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.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +207 -0
  4. data/lib/paddle_pay.rb +40 -0
  5. data/lib/paddle_pay/configuration.rb +17 -0
  6. data/lib/paddle_pay/connection.rb +69 -0
  7. data/lib/paddle_pay/errors/paddle_pay_error.rb +54 -0
  8. data/lib/paddle_pay/models/alert/webhook.rb +14 -0
  9. data/lib/paddle_pay/models/product/coupon.rb +36 -0
  10. data/lib/paddle_pay/models/product/license.rb +14 -0
  11. data/lib/paddle_pay/models/product/pay_link.rb +14 -0
  12. data/lib/paddle_pay/models/product/payment.rb +15 -0
  13. data/lib/paddle_pay/models/product/product.rb +12 -0
  14. data/lib/paddle_pay/models/subscription/charge.rb +14 -0
  15. data/lib/paddle_pay/models/subscription/modifier.rb +24 -0
  16. data/lib/paddle_pay/models/subscription/payment.rb +25 -0
  17. data/lib/paddle_pay/models/subscription/plan.rb +19 -0
  18. data/lib/paddle_pay/models/subscription/user.rb +31 -0
  19. data/lib/paddle_pay/models/transaction/checkout.rb +13 -0
  20. data/lib/paddle_pay/models/transaction/order.rb +13 -0
  21. data/lib/paddle_pay/models/transaction/product.rb +13 -0
  22. data/lib/paddle_pay/models/transaction/subscription.rb +13 -0
  23. data/lib/paddle_pay/models/transaction/user.rb +13 -0
  24. data/lib/paddle_pay/util.rb +36 -0
  25. data/lib/paddle_pay/version.rb +5 -0
  26. data/test/spec/paddle_pay/configuration_spec.rb +24 -0
  27. data/test/spec/paddle_pay/connection_spec.rb +115 -0
  28. data/test/spec/paddle_pay/models/alert/webhook_spec.rb +41 -0
  29. data/test/spec/paddle_pay/models/product/coupon_spec.rb +98 -0
  30. data/test/spec/paddle_pay/models/product/license_spec.rb +33 -0
  31. data/test/spec/paddle_pay/models/product/pay_link_spec.rb +33 -0
  32. data/test/spec/paddle_pay/models/product/payment_spec.rb +31 -0
  33. data/test/spec/paddle_pay/models/product/product_spec.rb +42 -0
  34. data/test/spec/paddle_pay/models/subscription/charge_spec.rb +31 -0
  35. data/test/spec/paddle_pay/models/subscription/modifier_spec.rb +70 -0
  36. data/test/spec/paddle_pay/models/subscription/payment_spec.rb +68 -0
  37. data/test/spec/paddle_pay/models/subscription/plan_spec.rb +57 -0
  38. data/test/spec/paddle_pay/models/subscription/user_spec.rb +87 -0
  39. data/test/spec/paddle_pay/models/transaction/checkout_spec.rb +41 -0
  40. data/test/spec/paddle_pay/models/transaction/order_spec.rb +41 -0
  41. data/test/spec/paddle_pay/models/transaction/product_spec.rb +41 -0
  42. data/test/spec/paddle_pay/models/transaction/subscription_spec.rb +41 -0
  43. data/test/spec/paddle_pay/models/transaction/user_spec.rb +41 -0
  44. data/test/spec/paddle_pay/util_spec.rb +41 -0
  45. data/test/spec/paddle_pay/version_spec.rb +9 -0
  46. data/test/test_helper.rb +18 -0
  47. data/test/vcr_cassettes/paddle_pay/alert/webhook/test_0001_should_list_all_webhooks.yml +61 -0
  48. data/test/vcr_cassettes/paddle_pay/alert/webhook/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  49. data/test/vcr_cassettes/paddle_pay/alert/webhook/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  50. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_list_all_coupons.yml +60 -0
  51. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_raise_an_error_if_the_coupon_deletion_is_invalid.yml +61 -0
  52. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_raise_an_error_if_the_coupon_is_invalid.yml +61 -0
  53. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_return_updated_0_if_the_coupon_group_update_is_invalid.yml +62 -0
  54. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0001_should_return_updated_0_if_the_coupon_update_is_invalid.yml +62 -0
  55. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  56. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_return_coupon_codes_if_the_coupon_is_valid.yml +60 -0
  57. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_return_success_if_the_coupon_deletion_is_valid.yml +62 -0
  58. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_return_updated_0_if_the_coupon_group_update_is_valid.yml +62 -0
  59. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0002_should_return_updated_0_if_the_coupon_update_is_valid.yml +62 -0
  60. data/test/vcr_cassettes/paddle_pay/product/coupon/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  61. data/test/vcr_cassettes/paddle_pay/product/license/test_0001_should_raise_an_error_if_license_generation_request_is_invalid.yml +61 -0
  62. data/test/vcr_cassettes/paddle_pay/product/license/test_0002_should_return_a_license_code_if_license_generation_request_is_valid.yml +61 -0
  63. 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
  64. 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
  65. data/test/vcr_cassettes/paddle_pay/product/payment/test_0001_should_raise_an_error_if_the_payment_refund_is_invalid.yml +61 -0
  66. data/test/vcr_cassettes/paddle_pay/product/payment/test_0002_should_return_success_if_the_payment_refund_is_valid.yml +60 -0
  67. data/test/vcr_cassettes/paddle_pay/product/test_0001_should_list_all_products.yml +60 -0
  68. data/test/vcr_cassettes/paddle_pay/product/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  69. data/test/vcr_cassettes/paddle_pay/product/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  70. data/test/vcr_cassettes/paddle_pay/subscription/charge/test_0001_should_raise_an_error_if_the_charge_is_invalid.yml +61 -0
  71. data/test/vcr_cassettes/paddle_pay/subscription/charge/test_0002_should_return_invoice_id_if_the_charge_is_valid.yml +61 -0
  72. data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0001_should_list_all_modifiers.yml +62 -0
  73. data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0001_should_raise_an_error_if_the_modifier_deletion_is_invalid.yml +61 -0
  74. data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0001_should_raise_an_error_if_the_modifier_is_invalid.yml +61 -0
  75. data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  76. data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0002_should_return_a_modifier_id_if_the_modifier_is_valid.yml +60 -0
  77. data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0002_should_return_a_product_id_if_the_modifier_deletion_is_valid.yml +60 -0
  78. data/test/vcr_cassettes/paddle_pay/subscription/modifier/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  79. data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0001_should_list_all_payments.yml +60 -0
  80. data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0001_should_raise_an_error_if_the_payment_refund_is_invalid.yml +61 -0
  81. data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0001_should_raise_an_error_if_the_payment_reschedule_is_invalid.yml +313 -0
  82. data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  83. data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0002_should_return_success_if_the_payment_refund_is_valid.yml +60 -0
  84. data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0002_should_return_success_if_the_payment_reschedule_is_valid.yml +62 -0
  85. data/test/vcr_cassettes/paddle_pay/subscription/payment/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  86. data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0001_should_list_all_plans.yml +60 -0
  87. data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0001_should_raise_an_error_if_the_plan_is_invalid.yml +61 -0
  88. data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0002_should_be_successful_if_the_plan_is_valid.yml +62 -0
  89. data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  90. data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0002_should_return_a_product_id_if_the_plan_is_valid.yml +62 -0
  91. data/test/vcr_cassettes/paddle_pay/subscription/plan/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  92. data/test/vcr_cassettes/paddle_pay/subscription/user/test_0001_should_list_all_users.yml +61 -0
  93. data/test/vcr_cassettes/paddle_pay/subscription/user/test_0001_should_raise_an_error_if_the_cancelation_is_invalid.yml +61 -0
  94. data/test/vcr_cassettes/paddle_pay/subscription/user/test_0001_should_raise_an_error_if_the_subscription_update_is_invalid.yml +61 -0
  95. data/test/vcr_cassettes/paddle_pay/subscription/user/test_0001_should_raise_an_error_if_the_subscription_update_preview_is_invalid.yml +61 -0
  96. data/test/vcr_cassettes/paddle_pay/subscription/user/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  97. data/test/vcr_cassettes/paddle_pay/subscription/user/test_0002_should_return_a_subscription_id_if_the_subscription_update_is_valid.yml +60 -0
  98. 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
  99. data/test/vcr_cassettes/paddle_pay/subscription/user/test_0002_should_return_success_if_the_cancelation_is_valid.yml +62 -0
  100. data/test/vcr_cassettes/paddle_pay/subscription/user/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  101. data/test/vcr_cassettes/paddle_pay/transaction/checkout/test_0001_should_list_all_checkouts.yml +61 -0
  102. data/test/vcr_cassettes/paddle_pay/transaction/checkout/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  103. data/test/vcr_cassettes/paddle_pay/transaction/checkout/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  104. data/test/vcr_cassettes/paddle_pay/transaction/order/test_0001_should_list_all_orders.yml +61 -0
  105. data/test/vcr_cassettes/paddle_pay/transaction/order/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  106. data/test/vcr_cassettes/paddle_pay/transaction/order/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  107. data/test/vcr_cassettes/paddle_pay/transaction/product/test_0001_should_list_all_products.yml +62 -0
  108. data/test/vcr_cassettes/paddle_pay/transaction/product/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  109. data/test/vcr_cassettes/paddle_pay/transaction/product/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  110. data/test/vcr_cassettes/paddle_pay/transaction/subscription/test_0001_should_list_all_subscriptions.yml +61 -0
  111. data/test/vcr_cassettes/paddle_pay/transaction/subscription/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  112. data/test/vcr_cassettes/paddle_pay/transaction/subscription/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  113. data/test/vcr_cassettes/paddle_pay/transaction/user/test_0001_should_list_all_users.yml +62 -0
  114. data/test/vcr_cassettes/paddle_pay/transaction/user/test_0002_should_raise_an_error_if_no_vendor_id_is_present.yml +61 -0
  115. data/test/vcr_cassettes/paddle_pay/transaction/user/test_0003_should_raise_an_error_if_no_vendor_auth_code_is_present.yml +61 -0
  116. metadata +358 -0
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ describe PaddlePay::Subscription::User 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
+ @user = PaddlePay::Subscription::User
10
+ path = PaddlePay::Util.convert_class_to_path(@user.name) + "/#{name}"
11
+ puts path
12
+ VCR.insert_cassette(path)
13
+ end
14
+
15
+ after do
16
+ VCR.eject_cassette
17
+ end
18
+
19
+ describe 'when users are requested' do
20
+ it 'should list all users' do
21
+ list = @user.list
22
+ assert_instance_of Array, list
23
+ refute_nil list.first[:user_id] if list.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
+ @user.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
+ @user.list
38
+ end
39
+ assert_equal exception.code, 107 # You don't have permission to access this resource
40
+ end
41
+ end
42
+
43
+ describe 'when an update preview is requested' do
44
+ it 'should raise an error if the subscription update preview is invalid' do
45
+ subscription = {}
46
+ assert_raises PaddlePay::PaddlePayError do
47
+ @user.preview_update(3479984, subscription)
48
+ end
49
+ end
50
+
51
+ it 'should return a subscription id if the subscription update preview is valid' do
52
+ subscription = { recurring_price: '10.00', currency: 'USD', quantity: 1 }
53
+ response = @user.preview_update(3479984, subscription)
54
+ assert_instance_of Hash, response
55
+ refute_nil response[:subscription_id]
56
+ end
57
+ end
58
+
59
+ describe 'when an update is requested' do
60
+ it 'should raise an error if the subscription update is invalid' do
61
+ subscription = {}
62
+ assert_raises PaddlePay::PaddlePayError do
63
+ @user.update(3479984, subscription)
64
+ end
65
+ end
66
+
67
+ it 'should return a subscription id if the subscription update is valid' do
68
+ subscription = { recurring_price: '10.00', currency: 'USD', quantity: 1 }
69
+ response = @user.update(3479984, subscription)
70
+ assert_instance_of Hash, response
71
+ refute_nil response[:subscription_id]
72
+ end
73
+ end
74
+
75
+ describe 'when a cancelation is requested' do
76
+ it 'should raise an error if the cancelation is invalid' do
77
+ assert_raises PaddlePay::PaddlePayError do
78
+ @user.cancel(1000000, {})
79
+ end
80
+ end
81
+
82
+ it 'should return success if the cancelation is valid' do
83
+ response = @user.cancel(3479984)
84
+ assert_nil response # no response when request is successful
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ describe PaddlePay::Transaction::Checkout 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
+ @checkout = PaddlePay::Transaction::Checkout
10
+ path = PaddlePay::Util.convert_class_to_path(@checkout.name) + "/#{name}"
11
+ VCR.insert_cassette(path)
12
+ end
13
+
14
+ after do
15
+ VCR.eject_cassette
16
+ end
17
+
18
+ describe 'when checkouts are requested' do
19
+ it 'should list all checkouts' do
20
+ list = @checkout.list('57064784-chrec5910826421-58f0e94797')
21
+ assert_instance_of Array, list
22
+ refute_nil list.first[:checkout_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
+ @checkout.list('57064784-chrec5910826421-58f0e94797')
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
+ @checkout.list('57064784-chrec5910826421-58f0e94797')
37
+ end
38
+ assert_equal exception.code, 107 # You don't have permission to access this resource
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ describe PaddlePay::Transaction::Order 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
+ @order = PaddlePay::Transaction::Order
10
+ path = PaddlePay::Util.convert_class_to_path(@order.name) + "/#{name}"
11
+ VCR.insert_cassette(path)
12
+ end
13
+
14
+ after do
15
+ VCR.eject_cassette
16
+ end
17
+
18
+ describe 'when orders are requested' do
19
+ it 'should list all orders' do
20
+ list = @order.list('14854225-10710435')
21
+ assert_instance_of Array, list
22
+ refute_nil list.first[:order_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
+ @order.list('14854225-10710435')
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
+ @order.list('14854225-10710435')
37
+ end
38
+ assert_equal exception.code, 107 # You don't have permission to access this resource
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ describe PaddlePay::Transaction::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::Transaction::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(594_469)
21
+ assert_instance_of Array, list
22
+ refute_nil list.first[:product_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
+ @product.list(594_469)
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
+ @product.list(594_469)
37
+ end
38
+ assert_equal exception.code, 107 # You don't have permission to access this resource
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ describe PaddlePay::Transaction::Subscription 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
+ @subscription = PaddlePay::Transaction::Subscription
10
+ path = PaddlePay::Util.convert_class_to_path(@subscription.name) + "/#{name}"
11
+ VCR.insert_cassette(path)
12
+ end
13
+
14
+ after do
15
+ VCR.eject_cassette
16
+ end
17
+
18
+ describe 'when subscriptions are requested' do
19
+ it 'should list all subscriptions' do
20
+ list = @subscription.list(3_484_448)
21
+ assert_instance_of Array, list
22
+ refute_nil list.first[:subscription] 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
+ @subscription.list(3_484_448)
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
+ @subscription.list(3_484_448)
37
+ end
38
+ assert_equal exception.code, 107 # You don't have permission to access this resource
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ describe PaddlePay::Transaction::User 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
+ @user = PaddlePay::Transaction::User
10
+ path = PaddlePay::Util.convert_class_to_path(@user.name) + "/#{name}"
11
+ VCR.insert_cassette(path)
12
+ end
13
+
14
+ after do
15
+ VCR.eject_cassette
16
+ end
17
+
18
+ describe 'when users are requested' do
19
+ it 'should list all users' do
20
+ list = @user.list(17_368_056)
21
+ assert_instance_of Array, list
22
+ refute_nil list.first[:user] 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
+ @user.list(17_368_056)
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
+ @user.list(17_368_056)
37
+ end
38
+ assert_equal exception.code, 107 # You don't have permission to access this resource
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ describe PaddlePay::Util do
6
+ describe 'when convert hash keys' do
7
+ it 'should not convert strings' do
8
+ assert_equal PaddlePay::Util.convert_hash_keys('string'), 'string'
9
+ end
10
+
11
+ it 'should convert hash keys to snake case' do
12
+ assert_equal PaddlePay::Util.convert_hash_keys({ "testKey": 'test' }), { test_key: 'test' }
13
+ end
14
+
15
+ it 'should convert multiple hash keys to snake case' do
16
+ assert_equal PaddlePay::Util.convert_hash_keys({ "testKey": 'test', "secondKey": 'test' }), { test_key: 'test', second_key: 'test' }
17
+ end
18
+
19
+ it 'should convert hash keys in arrays to snake case' do
20
+ assert_equal PaddlePay::Util.convert_hash_keys([{ "testKey": 'test' }]), [{ test_key: 'test' }]
21
+ end
22
+
23
+ it 'should convert abbreviations to lowercase keys' do
24
+ assert_equal PaddlePay::Util.convert_hash_keys({ "USD": 'test' }), { usd: 'test' }
25
+ end
26
+
27
+ it 'should convert multidimensional hashes' do
28
+ assert_equal PaddlePay::Util.convert_hash_keys({ "testKey": { "multiKey": 'test' } }), { test_key: { multi_key: 'test' } }
29
+ end
30
+ end
31
+
32
+ describe 'when convert simple class names' do
33
+ it 'should convert class names to snake case' do
34
+ assert_equal PaddlePay::Util.convert_class_to_path('PaddlePay'), 'paddle_pay'
35
+ end
36
+
37
+ it 'should convert modules to path' do
38
+ assert_equal PaddlePay::Util.convert_class_to_path('PaddlePay::Util'), 'paddle_pay/util'
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ describe PaddlePay do
6
+ it 'should has a version number' do
7
+ assert !PaddlePay::VERSION.nil?
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dotenv/load'
4
+ require 'minitest/autorun'
5
+ require 'minitest/spec'
6
+ require 'minitest/reporters'
7
+ require 'webmock/minitest'
8
+ require 'vcr'
9
+ require 'paddle_pay'
10
+
11
+ Minitest::Reporters.use!
12
+
13
+ VCR.configure do |config|
14
+ config.cassette_library_dir = 'test/vcr_cassettes'
15
+ config.hook_into :webmock
16
+ config.filter_sensitive_data('<VENDOR_ID>') { ENV['PADDLE_VENDOR_ID'] }
17
+ config.filter_sensitive_data('<VENDOR_AUTH_CODE>') { ENV['PADDLE_VENDOR_AUTH_CODE'] }
18
+ end
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://vendors.paddle.com/api/2.0/alert/webhooks
6
+ body:
7
+ encoding: UTF-8
8
+ string: vendor_auth_code=<VENDOR_AUTH_CODE>&vendor_id=<VENDOR_ID>
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v1.0.1
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Sat, 23 May 2020 11:00:40 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Set-Cookie:
32
+ - __cfduid=ddceecf8417b1b4dba6068f986fcad7071590231640; expires=Mon, 22-Jun-20
33
+ 11:00:40 GMT; path=/; domain=.paddle.com; HttpOnly; SameSite=Lax
34
+ - paddle_session_vendor=eyJpdiI6IjZLNzJnNFl4eDhuWlYwb2JnWXZuWWRhOVpTeTArMHpyUzkyNjJUM1JZaFk9IiwidmFsdWUiOiJmTEU3bk9tTndNZ3dYNVB3XC9IVGIyZFhZdmxkZTBcL0NmeXRGUk14dnBcL0lpaXpFUE9reTJ0WXRHRW1OSnNETWlwVnJrbnFFalRwc083WHkwQmp3dHdWdz09IiwibWFjIjoiNTFlOTBjMjNjZmI1NWY3ODIyZjcwN2Y2MTgwYWYwNDg5NGYwOTc1ZjM1YjExYTk5MGI5MWI3NTU0MjFkMzA0OSJ9;
35
+ expires=Sat, 23-May-2020 13:00:40 GMT; Max-Age=7200; path=/; domain=vendors.paddle.com;
36
+ secure; HttpOnly;SameSite=none;Secure
37
+ X-Powered-By:
38
+ - PHP/7.2.31
39
+ Cache-Control:
40
+ - no-cache
41
+ X-Frame-Options:
42
+ - sameorigin
43
+ P3p:
44
+ - CP="CAO CUR ADMa DEVa TAIa OUR DELa STP ONL NAV STA PUR"
45
+ Cf-Cache-Status:
46
+ - DYNAMIC
47
+ Expect-Ct:
48
+ - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
49
+ Server:
50
+ - cloudflare
51
+ Cf-Ray:
52
+ - 597e4649ba630c25-AMS
53
+ Cf-Request-Id:
54
+ - 02e2ca421200000c25a81eb200000001
55
+ body:
56
+ encoding: ASCII-8BIT
57
+ string: '{"success":true,"response":{"current_page":1,"total_pages":1,"alerts_per_page":10,"total_alerts":0,"query_head":"2020-05-23
58
+ 11:00:40","data":[]}}'
59
+ http_version: null
60
+ recorded_at: Sat, 23 May 2020 11:00:40 GMT
61
+ recorded_with: VCR 5.1.0
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://vendors.paddle.com/api/2.0/alert/webhooks
6
+ body:
7
+ encoding: UTF-8
8
+ string: vendor_auth_code=<VENDOR_AUTH_CODE>&vendor_id
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v1.0.1
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Sat, 23 May 2020 11:00:40 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Set-Cookie:
32
+ - __cfduid=d9b910d0a0e1aea11d66f4b263df6fd6e1590231640; expires=Mon, 22-Jun-20
33
+ 11:00:40 GMT; path=/; domain=.paddle.com; HttpOnly; SameSite=Lax
34
+ - paddle_session_vendor=eyJpdiI6InVIRHc0bFppdTlUOG1IWEphZ2JCY29FR1U1U3BkNHBUUUNkU2ZKYmozMzQ9IiwidmFsdWUiOiJ6UEdmS0NieWFqT3VrZnF1V1pkT3lMQU9UT2t4bG1zTlhzNjBINjRmc2lhYmpDYUZrdUtnTlVvSWp4UjY4SHc5RmN1NFZHR0FJVnZcL0ZXVGFtWlF4SEE9PSIsIm1hYyI6IjUzOGI1ZWMzY2QyMWZiZTMzYTQyYmVjMWNjYjUyZDcxOWE4OTQ4MWU4NDQ2MTc2ZTVjNmJhZTlmOTdkNjgxYjIifQ%3D%3D;
35
+ expires=Sat, 23-May-2020 13:00:40 GMT; Max-Age=7200; path=/; domain=vendors.paddle.com;
36
+ secure; HttpOnly;SameSite=none;Secure
37
+ X-Powered-By:
38
+ - PHP/7.2.31
39
+ Cache-Control:
40
+ - no-cache
41
+ X-Frame-Options:
42
+ - sameorigin
43
+ P3p:
44
+ - CP="CAO CUR ADMa DEVa TAIa OUR DELa STP ONL NAV STA PUR"
45
+ Cf-Cache-Status:
46
+ - DYNAMIC
47
+ Expect-Ct:
48
+ - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
49
+ Server:
50
+ - cloudflare
51
+ Cf-Ray:
52
+ - 597e46474888fa60-AMS
53
+ Cf-Request-Id:
54
+ - 02e2ca408d0000fa607eaa2200000001
55
+ body:
56
+ encoding: ASCII-8BIT
57
+ string: '{"success":false,"error":{"code":107,"message":"You don''t have permission
58
+ to access this resource"}}'
59
+ http_version: null
60
+ recorded_at: Sat, 23 May 2020 11:00:40 GMT
61
+ recorded_with: VCR 5.1.0