paddle_pay 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +207 -0
- data/lib/paddle_pay.rb +40 -0
- data/lib/paddle_pay/configuration.rb +17 -0
- data/lib/paddle_pay/connection.rb +69 -0
- data/lib/paddle_pay/errors/paddle_pay_error.rb +54 -0
- data/lib/paddle_pay/models/alert/webhook.rb +14 -0
- data/lib/paddle_pay/models/product/coupon.rb +36 -0
- data/lib/paddle_pay/models/product/license.rb +14 -0
- data/lib/paddle_pay/models/product/pay_link.rb +14 -0
- data/lib/paddle_pay/models/product/payment.rb +15 -0
- data/lib/paddle_pay/models/product/product.rb +12 -0
- data/lib/paddle_pay/models/subscription/charge.rb +14 -0
- data/lib/paddle_pay/models/subscription/modifier.rb +24 -0
- data/lib/paddle_pay/models/subscription/payment.rb +25 -0
- data/lib/paddle_pay/models/subscription/plan.rb +19 -0
- data/lib/paddle_pay/models/subscription/user.rb +31 -0
- data/lib/paddle_pay/models/transaction/checkout.rb +13 -0
- data/lib/paddle_pay/models/transaction/order.rb +13 -0
- data/lib/paddle_pay/models/transaction/product.rb +13 -0
- data/lib/paddle_pay/models/transaction/subscription.rb +13 -0
- data/lib/paddle_pay/models/transaction/user.rb +13 -0
- data/lib/paddle_pay/util.rb +36 -0
- data/lib/paddle_pay/version.rb +5 -0
- data/test/spec/paddle_pay/configuration_spec.rb +24 -0
- data/test/spec/paddle_pay/connection_spec.rb +115 -0
- data/test/spec/paddle_pay/models/alert/webhook_spec.rb +41 -0
- data/test/spec/paddle_pay/models/product/coupon_spec.rb +98 -0
- data/test/spec/paddle_pay/models/product/license_spec.rb +33 -0
- data/test/spec/paddle_pay/models/product/pay_link_spec.rb +33 -0
- data/test/spec/paddle_pay/models/product/payment_spec.rb +31 -0
- data/test/spec/paddle_pay/models/product/product_spec.rb +42 -0
- data/test/spec/paddle_pay/models/subscription/charge_spec.rb +31 -0
- data/test/spec/paddle_pay/models/subscription/modifier_spec.rb +70 -0
- data/test/spec/paddle_pay/models/subscription/payment_spec.rb +68 -0
- data/test/spec/paddle_pay/models/subscription/plan_spec.rb +57 -0
- data/test/spec/paddle_pay/models/subscription/user_spec.rb +87 -0
- data/test/spec/paddle_pay/models/transaction/checkout_spec.rb +41 -0
- data/test/spec/paddle_pay/models/transaction/order_spec.rb +41 -0
- data/test/spec/paddle_pay/models/transaction/product_spec.rb +41 -0
- data/test/spec/paddle_pay/models/transaction/subscription_spec.rb +41 -0
- data/test/spec/paddle_pay/models/transaction/user_spec.rb +41 -0
- data/test/spec/paddle_pay/util_spec.rb +41 -0
- data/test/spec/paddle_pay/version_spec.rb +9 -0
- data/test/test_helper.rb +18 -0
- data/test/vcr_cassettes/paddle_pay/alert/webhook/test_0001_should_list_all_webhooks.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/alert/webhook/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/alert/webhook/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_list_all_coupons.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_raise_an_error_if_the_coupon_deletion_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_raise_an_error_if_the_coupon_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_return_updated_0_if_the_coupon_group_update_is_invalid.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_return_updated_0_if_the_coupon_update_is_invalid.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_return_coupon_codes_if_the_coupon_is_valid.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_return_success_if_the_coupon_deletion_is_valid.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_return_updated_0_if_the_coupon_group_update_is_valid.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_return_updated_0_if_the_coupon_update_is_valid.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/product/coupon/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/license/test_0001_should_raise_an_error_if_license_generation_request_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/license/test_0002_should_return_a_license_code_if_license_generation_request_is_valid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/pay_link/test_0001_should_raise_an_error_if_pay_link_generation_request_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/pay_link/test_0002_should_return_an_url_if_pay_link_generation_request_is_valid.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/product/payment/test_0001_should_raise_an_error_if_the_payment_refund_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/payment/test_0002_should_return_success_if_the_payment_refund_is_valid.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/product/test_0001_should_list_all_products.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/product/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/product/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/charge/test_0001_should_raise_an_error_if_the_charge_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/charge/test_0002_should_return_invoice_id_if_the_charge_is_valid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0001_should_list_all_modifiers.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0001_should_raise_an_error_if_the_modifier_deletion_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0001_should_raise_an_error_if_the_modifier_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0002_should_return_a_modifier_id_if_the_modifier_is_valid.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0002_should_return_a_product_id_if_the_modifier_deletion_is_valid.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0001_should_list_all_payments.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0001_should_raise_an_error_if_the_payment_refund_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0001_should_raise_an_error_if_the_payment_reschedule_is_invalid.yml +313 -0
- data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0002_should_return_success_if_the_payment_refund_is_valid.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0002_should_return_success_if_the_payment_reschedule_is_valid.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0001_should_list_all_plans.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0001_should_raise_an_error_if_the_plan_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0002_should_be_successful_if_the_plan_is_valid.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0002_should_return_a_product_id_if_the_plan_is_valid.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/user/test_0001_should_list_all_users.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/user/test_0001_should_raise_an_error_if_the_cancelation_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/user/test_0001_should_raise_an_error_if_the_subscription_update_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/user/test_0001_should_raise_an_error_if_the_subscription_update_preview_is_invalid.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/user/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/subscription/user/test_0002_should_return_a_subscription_id_if_the_subscription_update_is_valid.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/subscription/user/test_0002_should_return_a_subscription_id_if_the_subscription_update_preview_is_valid.yml +60 -0
- data/test/vcr_cassettes/paddle_pay/subscription/user/test_0002_should_return_success_if_the_cancelation_is_valid.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/subscription/user/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/checkout/test_0001_should_list_all_checkouts.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/checkout/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/checkout/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/order/test_0001_should_list_all_orders.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/order/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/order/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/product/test_0001_should_list_all_products.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/transaction/product/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/product/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/subscription/test_0001_should_list_all_subscriptions.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/subscription/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/subscription/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/user/test_0001_should_list_all_users.yml +62 -0
- data/test/vcr_cassettes/paddle_pay/transaction/user/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
- data/test/vcr_cassettes/paddle_pay/transaction/user/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
- metadata +358 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Product::Coupon do
|
6
|
+
before do
|
7
|
+
PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
|
9
|
+
@coupon = PaddlePay::Product::Coupon
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@coupon.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when coupons are requested' do
|
19
|
+
it 'should list all coupons' do
|
20
|
+
list = @coupon.list(594469)
|
21
|
+
assert_instance_of Array, list
|
22
|
+
refute_nil list.first[:coupon] if list.count > 0
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should raise an error if no vendor id is present' do
|
26
|
+
PaddlePay.config.vendor_id = nil
|
27
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
28
|
+
@coupon.list(594469)
|
29
|
+
end
|
30
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise an error if no vendor auth code is present' do
|
34
|
+
PaddlePay.config.vendor_auth_code = nil
|
35
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
36
|
+
@coupon.list(594469)
|
37
|
+
end
|
38
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'when the creation of a coupon is requested' do
|
43
|
+
it 'should raise an error if the coupon is invalid' do
|
44
|
+
coupon = { coupon_type: 'checkout' }
|
45
|
+
assert_raises PaddlePay::PaddlePayError do
|
46
|
+
@coupon.create(coupon)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should return coupon codes if the coupon is valid' do
|
51
|
+
coupon = { coupon_type: 'checkout', discount_type: 'percentage', discount_amount: '100', allowed_uses: 10 }
|
52
|
+
response = @coupon.create(coupon)
|
53
|
+
assert_instance_of Hash, response
|
54
|
+
refute_nil response[:coupon_codes]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'when the update of a coupon is requested' do
|
59
|
+
it 'should return updated == 0 if the coupon update is invalid' do
|
60
|
+
response = @coupon.update_code('NOVALIDCODE', { allowed_uses: 20 })
|
61
|
+
assert_instance_of Hash, response
|
62
|
+
assert_equal response[:updated], 0
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should return updated > 0 if the coupon update is valid' do
|
66
|
+
response = @coupon.update_code('7D0E7A68', { allowed_uses: 20 })
|
67
|
+
assert_instance_of Hash, response
|
68
|
+
assert_equal response[:updated], 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'when the update of a coupon group is requested' do
|
73
|
+
it 'should return updated == 0 if the coupon group update is invalid' do
|
74
|
+
response = @coupon.update_group('NOVALIDGROUP', { allowed_uses: 20 })
|
75
|
+
assert_instance_of Hash, response
|
76
|
+
assert_equal response[:updated], 0
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should return updated > 0 if the coupon group update is valid' do
|
80
|
+
response = @coupon.update_group('Testgroup', { allowed_uses: 30 })
|
81
|
+
assert_instance_of Hash, response
|
82
|
+
assert_equal response[:updated], 1
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'when the deletion of a coupon is requested' do
|
87
|
+
it 'should raise an error if the coupon deletion is invalid' do
|
88
|
+
assert_raises PaddlePay::PaddlePayError do
|
89
|
+
@coupon.delete('NOVALIDCOUPON', 594470)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should return success if the coupon deletion is valid' do
|
94
|
+
response = @coupon.delete('9F9F78DA', 594470)
|
95
|
+
assert_nil response # no response when request is successful
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Product::License do
|
6
|
+
before do
|
7
|
+
PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
|
9
|
+
@license = PaddlePay::Product::License
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@license.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when a license generation is requested' do
|
19
|
+
it 'should raise an error if license generation request is invalid' do
|
20
|
+
license = { product_id: '594512', allowed_uses: 10 }
|
21
|
+
assert_raises PaddlePay::PaddlePayError do
|
22
|
+
@license.generate(license)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should return a license code if license generation request is valid' do
|
27
|
+
license = { product_id: '594512', allowed_uses: 10 }
|
28
|
+
response = @license.generate(license)
|
29
|
+
assert_instance_of Hash, response
|
30
|
+
refute_nil response[:license_code]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Product::PayLink do
|
6
|
+
before do
|
7
|
+
PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
|
9
|
+
@pay_link = PaddlePay::Product::PayLink
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@pay_link.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when a pay link generation is requested' do
|
19
|
+
it 'should raise an error if pay link generation request is invalid' do
|
20
|
+
pay_link = { product_id: 'NOTVALID' }
|
21
|
+
assert_raises PaddlePay::PaddlePayError do
|
22
|
+
@pay_link.generate(pay_link)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should return an url if pay link generation request is valid' do
|
27
|
+
pay_link = { product_id: '594512' }
|
28
|
+
response = @pay_link.generate(pay_link)
|
29
|
+
assert_instance_of Hash, response
|
30
|
+
refute_nil response[:url]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Product::Payment do
|
6
|
+
before do
|
7
|
+
PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
|
9
|
+
@payment = PaddlePay::Product::Payment
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@payment.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when the refund of a payment is requested' do
|
19
|
+
it 'should raise an error if the payment refund is invalid' do
|
20
|
+
assert_raises PaddlePay::PaddlePayError do
|
21
|
+
@payment.refund(1234567)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return success if the payment refund is valid' do
|
26
|
+
response = @payment.refund(10710436)
|
27
|
+
assert_instance_of Hash, response
|
28
|
+
refute_nil response[:refund_request_id]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Product do
|
6
|
+
before do
|
7
|
+
PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
|
9
|
+
@product = PaddlePay::Product
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@product.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when products are requested' do
|
19
|
+
it 'should list all products' do
|
20
|
+
list = @product.list
|
21
|
+
assert_instance_of Hash, list
|
22
|
+
assert_instance_of Array, list[:products]
|
23
|
+
refute_nil list[:products].first[:id] if list[:products].count > 0
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise an error if no vendor id is present' do
|
27
|
+
PaddlePay.config.vendor_id = nil
|
28
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
29
|
+
@product.list
|
30
|
+
end
|
31
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should raise an error if no vendor auth code is present' do
|
35
|
+
PaddlePay.config.vendor_auth_code = nil
|
36
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
37
|
+
@product.list
|
38
|
+
end
|
39
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Subscription::Charge do
|
6
|
+
before do
|
7
|
+
PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
|
9
|
+
@charge = PaddlePay::Subscription::Charge
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@charge.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when a charge is created' do
|
19
|
+
it 'should raise an error if the charge is invalid' do
|
20
|
+
assert_raises PaddlePay::PaddlePayError do
|
21
|
+
@charge.create(12345678, '0.00', 'Test')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return invoice id if the charge is valid' do
|
26
|
+
response = @charge.create(3484448, '0.00', 'Test')
|
27
|
+
assert_instance_of Hash, response
|
28
|
+
refute_nil response[:invoice_id]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Subscription::Modifier do
|
6
|
+
before do
|
7
|
+
PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
|
9
|
+
@modifier = PaddlePay::Subscription::Modifier
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@modifier.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when modifiers are requested' do
|
19
|
+
it 'should list all modifiers' do
|
20
|
+
list = @modifier.list
|
21
|
+
assert_instance_of Array, list
|
22
|
+
refute_nil list.first[:modifier_id] if list.count > 0
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should raise an error if no vendor id is present' do
|
26
|
+
PaddlePay.config.vendor_id = nil
|
27
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
28
|
+
@modifier.list
|
29
|
+
end
|
30
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise an error if no vendor auth code is present' do
|
34
|
+
PaddlePay.config.vendor_auth_code = nil
|
35
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
36
|
+
@modifier.list
|
37
|
+
end
|
38
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'when the creation of a modifier is requested' do
|
43
|
+
it 'should raise an error if the modifier is invalid' do
|
44
|
+
modifier = { subscription_id: 1234567, modifier_amount: '1.00', modifier_description: 'Test' }
|
45
|
+
assert_raises PaddlePay::PaddlePayError do
|
46
|
+
@modifier.create(modifier)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should return a modifier id if the modifier is valid' do
|
51
|
+
modifier = { subscription_id: 3484448, modifier_amount: '1.00', modifier_description: 'Test' }
|
52
|
+
response = @modifier.create(modifier)
|
53
|
+
assert_instance_of Hash, response
|
54
|
+
refute_nil response[:modifier_id]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'when the deletion of a modifier is requested' do
|
59
|
+
it 'should raise an error if the modifier deletion is invalid' do
|
60
|
+
assert_raises PaddlePay::PaddlePayError do
|
61
|
+
@modifier.delete(1234567)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should return a product id if the modifier deletion is valid' do
|
66
|
+
response = @modifier.delete(143433)
|
67
|
+
assert_nil response # no response when request is successful
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Subscription::Payment do
|
6
|
+
before do
|
7
|
+
PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
|
9
|
+
@payment = PaddlePay::Subscription::Payment
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@payment.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when payments are requested' do
|
19
|
+
it 'should list all payments' do
|
20
|
+
list = @payment.list
|
21
|
+
assert_instance_of Array, list
|
22
|
+
refute_nil list.first[:id] if list.count > 0
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should raise an error if no vendor id is present' do
|
26
|
+
PaddlePay.config.vendor_id = nil
|
27
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
28
|
+
@payment.list
|
29
|
+
end
|
30
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise an error if no vendor auth code is present' do
|
34
|
+
PaddlePay.config.vendor_auth_code = nil
|
35
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
36
|
+
@payment.list
|
37
|
+
end
|
38
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'when the reschedule of a payment is requested' do
|
43
|
+
it 'should raise an error if the payment reschedule is invalid' do
|
44
|
+
assert_raises PaddlePay::PaddlePayError do
|
45
|
+
@payment.reschedule(10710436, 'wrong date')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return success if the payment reschedule is valid' do
|
50
|
+
response = @payment.reschedule(10710436, '2020-12-31')
|
51
|
+
assert_nil response # no response when request is successful
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'when the refund of a payment is requested' do
|
56
|
+
it 'should raise an error if the payment refund is invalid' do
|
57
|
+
assert_raises PaddlePay::PaddlePayError do
|
58
|
+
@payment.refund(1234567)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should return success if the payment refund is valid' do
|
63
|
+
response = @payment.refund(10710436)
|
64
|
+
assert_instance_of Hash, response
|
65
|
+
refute_nil response[:refund_request_id]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Subscription::Plan do
|
6
|
+
before do
|
7
|
+
PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
|
9
|
+
@plan = PaddlePay::Subscription::Plan
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@plan.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when plans are requested' do
|
19
|
+
it 'should list all plans' do
|
20
|
+
list = @plan.list
|
21
|
+
assert_instance_of Array, list
|
22
|
+
refute_nil list.first[:id] if list.count > 0
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should raise an error if no vendor id is present' do
|
26
|
+
PaddlePay.config.vendor_id = nil
|
27
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
28
|
+
@plan.list
|
29
|
+
end
|
30
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise an error if no vendor auth code is present' do
|
34
|
+
PaddlePay.config.vendor_auth_code = nil
|
35
|
+
exception = assert_raises PaddlePay::PaddlePayError do
|
36
|
+
@plan.list
|
37
|
+
end
|
38
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'when the creation of a plan is requested' do
|
43
|
+
it 'should raise an error if the plan is invalid' do
|
44
|
+
plan = { plan_name: 'Test', plan_trial_days: 30, plan_length: 1, plan_type: 'month' }
|
45
|
+
assert_raises PaddlePay::PaddlePayError do
|
46
|
+
@plan.create(plan)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should return a product id if the plan is valid' do
|
51
|
+
plan = { plan_name: 'Test', plan_trial_days: 30, plan_length: 1, plan_type: 'month', main_currency_code: 'USD', recurring_price_usd: '5.00' }
|
52
|
+
response = @plan.create(plan)
|
53
|
+
assert_instance_of Hash, response
|
54
|
+
refute_nil response[:product_id]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|