paddle_pay 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Product
|
5
|
+
module License
|
6
|
+
class << self
|
7
|
+
def generate(attributes, options = {})
|
8
|
+
options.merge!({ body: attributes }) if attributes.is_a?(::Hash)
|
9
|
+
Connection.request('2.0/product/generate_license', options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Product
|
5
|
+
module PayLink
|
6
|
+
class << self
|
7
|
+
def generate(attributes, options = {})
|
8
|
+
options.merge!({ body: attributes }) if attributes.is_a?(::Hash)
|
9
|
+
Connection.request('2.0/product/generate_pay_link', options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Product
|
5
|
+
module Payment
|
6
|
+
class << self
|
7
|
+
def refund(order_id, attributes = {}, options = {})
|
8
|
+
attributes.merge!(order_id: order_id)
|
9
|
+
options.merge!({ body: attributes })
|
10
|
+
Connection.request('2.0/payment/refund', options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Product
|
5
|
+
class << self
|
6
|
+
def list(filters = {}, options = {})
|
7
|
+
options.merge!({ body: filters }) if filters.is_a?(::Hash)
|
8
|
+
Connection.request('2.0/product/get_products', options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Subscription
|
5
|
+
module Charge
|
6
|
+
class << self
|
7
|
+
def create(subscription_id, amount, charge_name, options = {})
|
8
|
+
options.merge!({ body: { amount: amount, charge_name: charge_name } })
|
9
|
+
Connection.request("2.0/subscription/#{subscription_id}/charge", options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Subscription
|
5
|
+
module Modifier
|
6
|
+
class << self
|
7
|
+
def list(filters = {}, options = {})
|
8
|
+
options.merge!({ body: filters }) if filters.is_a?(::Hash)
|
9
|
+
Connection.request('2.0/subscription/modifiers', options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(attributes, options = {})
|
13
|
+
options.merge!({ body: attributes }) if attributes.is_a?(::Hash)
|
14
|
+
Connection.request('2.0/subscription/modifiers/create', options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(modifier_id, options = {})
|
18
|
+
options.merge!({ body: { modifier_id: modifier_id } })
|
19
|
+
Connection.request('2.0/subscription/modifiers/delete', options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Subscription
|
5
|
+
module Payment
|
6
|
+
class << self
|
7
|
+
def list(filters = {}, options = {})
|
8
|
+
options.merge!({ body: filters }) if filters.is_a?(::Hash)
|
9
|
+
Connection.request('2.0/subscription/payments', options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def reschedule(payment_id, date, options = {})
|
13
|
+
options.merge!({ body: { payment_id: payment_id, date: date } })
|
14
|
+
Connection.request('2.0/subscription/payments_reschedule', options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def refund(order_id, attributes = {}, options = {})
|
18
|
+
attributes.merge!(order_id: order_id)
|
19
|
+
options.merge!({ body: attributes })
|
20
|
+
Connection.request('2.0/payment/refund', options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Subscription
|
5
|
+
module Plan
|
6
|
+
class << self
|
7
|
+
def list(filters = {}, options = {})
|
8
|
+
options.merge!({ body: filters }) if filters.is_a?(::Hash)
|
9
|
+
Connection.request('2.0/subscription/plans', options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(attributes, options = {})
|
13
|
+
options.merge!({ body: attributes }) if attributes.is_a?(::Hash)
|
14
|
+
Connection.request('2.0/subscription/plans_create', options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Subscription
|
5
|
+
module User
|
6
|
+
class << self
|
7
|
+
def list(filters = {}, options = {})
|
8
|
+
options.merge!({ body: filters }) if filters.is_a?(::Hash)
|
9
|
+
Connection.request('2.0/subscription/users', options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def cancel(subscription_id, options = {})
|
13
|
+
options.merge!({ body: { subscription_id: subscription_id } })
|
14
|
+
Connection.request('2.0/subscription/users_cancel', options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(subscription_id, attributes = {}, options = {})
|
18
|
+
attributes.merge!(subscription_id: subscription_id)
|
19
|
+
options.merge!({ body: attributes })
|
20
|
+
Connection.request('2.0/subscription/users_update', options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def preview_update(subscription_id, attributes = {}, options = {})
|
24
|
+
attributes.merge!(subscription_id: subscription_id)
|
25
|
+
options.merge!({ body: attributes })
|
26
|
+
Connection.request('2.0/subscription/preview_update', options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaddlePay
|
4
|
+
module Util
|
5
|
+
class << self
|
6
|
+
def convert_hash_keys(value)
|
7
|
+
case value
|
8
|
+
when Array
|
9
|
+
value.map { |v| convert_hash_keys(v) }
|
10
|
+
when Hash
|
11
|
+
Hash[value.map { |k, v| [underscore_key(k), convert_hash_keys(v)] }]
|
12
|
+
else
|
13
|
+
value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def convert_class_to_path(class_name)
|
18
|
+
class_name.split('::').map { |v| to_snake_case(v) }.join('/')
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def underscore_key(k)
|
24
|
+
to_snake_case(k.to_s).to_sym
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_snake_case(string)
|
28
|
+
string.gsub(/::/, '/')
|
29
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
30
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
31
|
+
.tr('-', '_')
|
32
|
+
.downcase
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Configuration 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
|
+
end
|
10
|
+
|
11
|
+
describe 'when loading configuration' do
|
12
|
+
it 'should have a base url' do
|
13
|
+
assert !PaddlePay.config.vendors_url.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should have a vendor id' do
|
17
|
+
assert !PaddlePay.config.vendor_id.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have a vendor auth code' do
|
21
|
+
assert !PaddlePay.config.vendor_auth_code.nil?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Connection do
|
6
|
+
before do
|
7
|
+
@connection = PaddlePay::Connection
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'when a request is made' do
|
11
|
+
it 'should return a json parsed response if request is successful' do
|
12
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
13
|
+
.to_return(body: '{"success":true,"response":[{"data": "abcd"}]}', status: 200)
|
14
|
+
response = @connection.request('')
|
15
|
+
assert_instance_of Array, response
|
16
|
+
assert_equal response.first[:data], 'abcd'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should raise a paddle pay error if request is not successful' do
|
20
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
21
|
+
.to_return(body: '{"success":false,"error":{"code":100,"message":"Error"}}', status: 200)
|
22
|
+
assert_raises PaddlePay::PaddlePayError do
|
23
|
+
@connection.request('')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should raise a parse error if response is not in json format' do
|
28
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
29
|
+
.to_return(body: 'abcd', status: 200)
|
30
|
+
assert_raises PaddlePay::ParseError do
|
31
|
+
@connection.request('')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should raise a bad request error if status 400 is returned' do
|
36
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
37
|
+
.to_return(status: [400, 'Bad Request'])
|
38
|
+
assert_raises PaddlePay::BadRequestError do
|
39
|
+
@connection.request('')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should raise an unauthorized error if status 401 is returned' do
|
44
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
45
|
+
.to_return(status: [401, 'Unauthorized'])
|
46
|
+
assert_raises PaddlePay::UnauthorizedError do
|
47
|
+
@connection.request('')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should raise a forbidden error if status 403 is returned' do
|
52
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
53
|
+
.to_return(status: [403, 'Forbidden'])
|
54
|
+
assert_raises PaddlePay::ForbiddenError do
|
55
|
+
@connection.request('')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should raise a resource not found error if status 404 is returned' do
|
60
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
61
|
+
.to_return(status: [404, 'Not Found'])
|
62
|
+
assert_raises PaddlePay::ResourceNotFoundError do
|
63
|
+
@connection.request('')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should raise a proxy authentication error if status 407 is returned' do
|
68
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
69
|
+
.to_return(status: [407, 'Proxy Authentication Required'])
|
70
|
+
assert_raises PaddlePay::ProxyAuthError do
|
71
|
+
@connection.request('')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should raise a conflict error if status 409 is returned' do
|
76
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
77
|
+
.to_return(status: [409, 'Conflict'])
|
78
|
+
assert_raises PaddlePay::ConflictError do
|
79
|
+
@connection.request('')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should raise an unprocessable entity error if status 422 is returned' do
|
84
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
85
|
+
.to_return(status: [422, 'Unprocessable Entity'])
|
86
|
+
assert_raises PaddlePay::UnprocessableEntityError do
|
87
|
+
@connection.request('')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should raise a connection error if connection failed' do
|
92
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
93
|
+
.to_timeout
|
94
|
+
assert_raises PaddlePay::ConnectionError do
|
95
|
+
@connection.request('')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should raise an timeout error if request timed out' do
|
100
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
101
|
+
.to_raise(Net::ReadTimeout)
|
102
|
+
assert_raises PaddlePay::TimeoutError do
|
103
|
+
@connection.request('')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should raise a server error if status 500 is returned' do
|
108
|
+
stub_request(:post, PaddlePay.config.vendors_url)
|
109
|
+
.to_return(status: [500, 'Internal Server Error'])
|
110
|
+
assert_raises PaddlePay::ServerError do
|
111
|
+
@connection.request('')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe PaddlePay::Alert::Webhook 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
|
+
@webhook = PaddlePay::Alert::Webhook
|
10
|
+
path = PaddlePay::Util.convert_class_to_path(@webhook.name) + "/#{name}"
|
11
|
+
VCR.insert_cassette(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
VCR.eject_cassette
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when webhooks are requested' do
|
19
|
+
it 'should list all webhooks' do
|
20
|
+
response = @webhook.history
|
21
|
+
assert_instance_of Hash, response
|
22
|
+
refute_nil response[:data]
|
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
|
+
@webhook.history
|
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
|
+
@webhook.history
|
37
|
+
end
|
38
|
+
assert_equal exception.code, 107 # You don't have permission to access this resource
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|