paddle_pay 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -2
  3. data/lib/paddle_pay.rb +23 -23
  4. data/lib/paddle_pay/configuration.rb +19 -6
  5. data/lib/paddle_pay/connection.rb +11 -11
  6. data/lib/paddle_pay/errors/paddle_pay_error.rb +4 -1
  7. data/lib/paddle_pay/models/alert/webhook.rb +2 -2
  8. data/lib/paddle_pay/models/product/coupon.rb +12 -12
  9. data/lib/paddle_pay/models/product/license.rb +2 -2
  10. data/lib/paddle_pay/models/product/pay_link.rb +2 -2
  11. data/lib/paddle_pay/models/product/payment.rb +4 -4
  12. data/lib/paddle_pay/models/product/product.rb +2 -2
  13. data/lib/paddle_pay/models/subscription/charge.rb +1 -1
  14. data/lib/paddle_pay/models/subscription/modifier.rb +6 -6
  15. data/lib/paddle_pay/models/subscription/payment.rb +7 -7
  16. data/lib/paddle_pay/models/subscription/plan.rb +4 -4
  17. data/lib/paddle_pay/models/subscription/user.rb +10 -10
  18. data/lib/paddle_pay/util.rb +6 -6
  19. data/lib/paddle_pay/version.rb +1 -1
  20. data/test/spec/paddle_pay/configuration_spec.rb +35 -7
  21. data/test/spec/paddle_pay/connection_spec.rb +38 -38
  22. data/test/spec/paddle_pay/models/alert/webhook_spec.rb +9 -13
  23. data/test/spec/paddle_pay/models/product/coupon_spec.rb +29 -33
  24. data/test/spec/paddle_pay/models/product/license_spec.rb +8 -8
  25. data/test/spec/paddle_pay/models/product/pay_link_spec.rb +8 -8
  26. data/test/spec/paddle_pay/models/product/payment_spec.rb +7 -7
  27. data/test/spec/paddle_pay/models/product/product_spec.rb +9 -13
  28. data/test/spec/paddle_pay/models/subscription/charge_spec.rb +8 -8
  29. data/test/spec/paddle_pay/models/subscription/modifier_spec.rb +17 -21
  30. data/test/spec/paddle_pay/models/subscription/payment_spec.rb +17 -21
  31. data/test/spec/paddle_pay/models/subscription/plan_spec.rb +14 -18
  32. data/test/spec/paddle_pay/models/subscription/user_spec.rb +20 -24
  33. data/test/spec/paddle_pay/models/transaction/checkout_spec.rb +10 -14
  34. data/test/spec/paddle_pay/models/transaction/order_spec.rb +10 -14
  35. data/test/spec/paddle_pay/models/transaction/product_spec.rb +9 -13
  36. data/test/spec/paddle_pay/models/transaction/subscription_spec.rb +9 -13
  37. data/test/spec/paddle_pay/models/transaction/user_spec.rb +9 -13
  38. data/test/spec/paddle_pay/util_spec.rb +19 -19
  39. data/test/spec/paddle_pay/version_spec.rb +2 -2
  40. data/test/test_helper.rb +10 -10
  41. metadata +35 -7
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  describe PaddlePay::Product::Payment do
6
6
  before do
7
- PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
8
- PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
7
+ PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
8
+ PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
9
9
  @payment = PaddlePay::Product::Payment
10
10
  path = PaddlePay::Util.convert_class_to_path(@payment.name) + "/#{name}"
11
11
  VCR.insert_cassette(path)
@@ -15,17 +15,17 @@ describe PaddlePay::Product::Payment do
15
15
  VCR.eject_cassette
16
16
  end
17
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
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
20
  assert_raises PaddlePay::PaddlePayError do
21
21
  @payment.refund(1234567)
22
22
  end
23
23
  end
24
24
 
25
- it 'should return success if the payment refund is valid' do
25
+ it "should return success if the payment refund is valid" do
26
26
  response = @payment.refund(10710436)
27
27
  assert_instance_of Hash, response
28
28
  refute_nil response[:refund_request_id]
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  describe PaddlePay::Product do
6
6
  before do
7
- PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
8
- PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
7
+ PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
8
+ PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
9
9
  @product = PaddlePay::Product
10
10
  path = PaddlePay::Util.convert_class_to_path(@product.name) + "/#{name}"
11
11
  VCR.insert_cassette(path)
@@ -15,27 +15,23 @@ describe PaddlePay::Product do
15
15
  VCR.eject_cassette
16
16
  end
17
17
 
18
- describe 'when products are requested' do
19
- it 'should list all products' do
18
+ describe "when products are requested" do
19
+ it "should list all products" do
20
20
  list = @product.list
21
21
  assert_instance_of Hash, list
22
22
  assert_instance_of Array, list[:products]
23
23
  refute_nil list[:products].first[:id] if list[:products].count > 0
24
24
  end
25
25
 
26
- it 'should raise an error if no vendor id is present' do
26
+ it "should raise an error if no vendor id is present" do
27
27
  PaddlePay.config.vendor_id = nil
28
- exception = assert_raises PaddlePay::PaddlePayError do
29
- @product.list
30
- end
28
+ exception = assert_raises(PaddlePay::PaddlePayError) { @product.list }
31
29
  assert_equal exception.code, 107 # You don't have permission to access this resource
32
30
  end
33
31
 
34
- it 'should raise an error if no vendor auth code is present' do
32
+ it "should raise an error if no vendor auth code is present" do
35
33
  PaddlePay.config.vendor_auth_code = nil
36
- exception = assert_raises PaddlePay::PaddlePayError do
37
- @product.list
38
- end
34
+ exception = assert_raises(PaddlePay::PaddlePayError) { @product.list }
39
35
  assert_equal exception.code, 107 # You don't have permission to access this resource
40
36
  end
41
37
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  describe PaddlePay::Subscription::Charge do
6
6
  before do
7
- PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
8
- PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
7
+ PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
8
+ PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
9
9
  @charge = PaddlePay::Subscription::Charge
10
10
  path = PaddlePay::Util.convert_class_to_path(@charge.name) + "/#{name}"
11
11
  VCR.insert_cassette(path)
@@ -15,15 +15,15 @@ describe PaddlePay::Subscription::Charge do
15
15
  VCR.eject_cassette
16
16
  end
17
17
 
18
- describe 'when a charge is created' do
19
- it 'should raise an error if the charge is invalid' do
18
+ describe "when a charge is created" do
19
+ it "should raise an error if the charge is invalid" do
20
20
  assert_raises PaddlePay::PaddlePayError do
21
- @charge.create(12345678, '0.00', 'Test')
21
+ @charge.create(12345678, "0.00", "Test")
22
22
  end
23
23
  end
24
24
 
25
- it 'should return invoice id if the charge is valid' do
26
- response = @charge.create(3484448, '0.00', 'Test')
25
+ it "should return invoice id if the charge is valid" do
26
+ response = @charge.create(3484448, "0.00", "Test")
27
27
  assert_instance_of Hash, response
28
28
  refute_nil response[:invoice_id]
29
29
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  describe PaddlePay::Subscription::Modifier do
6
6
  before do
7
- PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
8
- PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
7
+ PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
8
+ PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
9
9
  @modifier = PaddlePay::Subscription::Modifier
10
10
  path = PaddlePay::Util.convert_class_to_path(@modifier.name) + "/#{name}"
11
11
  VCR.insert_cassette(path)
@@ -15,54 +15,50 @@ describe PaddlePay::Subscription::Modifier do
15
15
  VCR.eject_cassette
16
16
  end
17
17
 
18
- describe 'when modifiers are requested' do
19
- it 'should list all modifiers' do
18
+ describe "when modifiers are requested" do
19
+ it "should list all modifiers" do
20
20
  list = @modifier.list
21
21
  assert_instance_of Array, list
22
22
  refute_nil list.first[:modifier_id] if list.count > 0
23
23
  end
24
24
 
25
- it 'should raise an error if no vendor id is present' do
25
+ it "should raise an error if no vendor id is present" do
26
26
  PaddlePay.config.vendor_id = nil
27
- exception = assert_raises PaddlePay::PaddlePayError do
28
- @modifier.list
29
- end
27
+ exception = assert_raises(PaddlePay::PaddlePayError) { @modifier.list }
30
28
  assert_equal exception.code, 107 # You don't have permission to access this resource
31
29
  end
32
30
 
33
- it 'should raise an error if no vendor auth code is present' do
31
+ it "should raise an error if no vendor auth code is present" do
34
32
  PaddlePay.config.vendor_auth_code = nil
35
- exception = assert_raises PaddlePay::PaddlePayError do
36
- @modifier.list
37
- end
33
+ exception = assert_raises(PaddlePay::PaddlePayError) { @modifier.list }
38
34
  assert_equal exception.code, 107 # You don't have permission to access this resource
39
35
  end
40
36
  end
41
37
 
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' }
38
+ describe "when the creation of a modifier is requested" do
39
+ it "should raise an error if the modifier is invalid" do
40
+ modifier = {subscription_id: 1234567, modifier_amount: "1.00", modifier_description: "Test"}
45
41
  assert_raises PaddlePay::PaddlePayError do
46
42
  @modifier.create(modifier)
47
43
  end
48
44
  end
49
45
 
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' }
46
+ it "should return a modifier id if the modifier is valid" do
47
+ modifier = {subscription_id: 3484448, modifier_amount: "1.00", modifier_description: "Test"}
52
48
  response = @modifier.create(modifier)
53
49
  assert_instance_of Hash, response
54
50
  refute_nil response[:modifier_id]
55
51
  end
56
52
  end
57
53
 
58
- describe 'when the deletion of a modifier is requested' do
59
- it 'should raise an error if the modifier deletion is invalid' do
54
+ describe "when the deletion of a modifier is requested" do
55
+ it "should raise an error if the modifier deletion is invalid" do
60
56
  assert_raises PaddlePay::PaddlePayError do
61
57
  @modifier.delete(1234567)
62
58
  end
63
59
  end
64
60
 
65
- it 'should return a product id if the modifier deletion is valid' do
61
+ it "should return a product id if the modifier deletion is valid" do
66
62
  response = @modifier.delete(143433)
67
63
  assert_nil response # no response when request is successful
68
64
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  describe PaddlePay::Subscription::Payment do
6
6
  before do
7
- PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
8
- PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
7
+ PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
8
+ PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
9
9
  @payment = PaddlePay::Subscription::Payment
10
10
  path = PaddlePay::Util.convert_class_to_path(@payment.name) + "/#{name}"
11
11
  VCR.insert_cassette(path)
@@ -15,51 +15,47 @@ describe PaddlePay::Subscription::Payment do
15
15
  VCR.eject_cassette
16
16
  end
17
17
 
18
- describe 'when payments are requested' do
19
- it 'should list all payments' do
18
+ describe "when payments are requested" do
19
+ it "should list all payments" do
20
20
  list = @payment.list
21
21
  assert_instance_of Array, list
22
22
  refute_nil list.first[:id] if list.count > 0
23
23
  end
24
24
 
25
- it 'should raise an error if no vendor id is present' do
25
+ it "should raise an error if no vendor id is present" do
26
26
  PaddlePay.config.vendor_id = nil
27
- exception = assert_raises PaddlePay::PaddlePayError do
28
- @payment.list
29
- end
27
+ exception = assert_raises(PaddlePay::PaddlePayError) { @payment.list }
30
28
  assert_equal exception.code, 107 # You don't have permission to access this resource
31
29
  end
32
30
 
33
- it 'should raise an error if no vendor auth code is present' do
31
+ it "should raise an error if no vendor auth code is present" do
34
32
  PaddlePay.config.vendor_auth_code = nil
35
- exception = assert_raises PaddlePay::PaddlePayError do
36
- @payment.list
37
- end
33
+ exception = assert_raises(PaddlePay::PaddlePayError) { @payment.list }
38
34
  assert_equal exception.code, 107 # You don't have permission to access this resource
39
35
  end
40
36
  end
41
37
 
42
- describe 'when the reschedule of a payment is requested' do
43
- it 'should raise an error if the payment reschedule is invalid' do
38
+ describe "when the reschedule of a payment is requested" do
39
+ it "should raise an error if the payment reschedule is invalid" do
44
40
  assert_raises PaddlePay::PaddlePayError do
45
- @payment.reschedule(10710436, 'wrong date')
41
+ @payment.reschedule(10710436, "wrong date")
46
42
  end
47
43
  end
48
44
 
49
- it 'should return success if the payment reschedule is valid' do
50
- response = @payment.reschedule(10710436, '2020-12-31')
45
+ it "should return success if the payment reschedule is valid" do
46
+ response = @payment.reschedule(10710436, "2020-12-31")
51
47
  assert_nil response # no response when request is successful
52
48
  end
53
49
  end
54
50
 
55
- describe 'when the refund of a payment is requested' do
56
- it 'should raise an error if the payment refund is invalid' do
51
+ describe "when the refund of a payment is requested" do
52
+ it "should raise an error if the payment refund is invalid" do
57
53
  assert_raises PaddlePay::PaddlePayError do
58
54
  @payment.refund(1234567)
59
55
  end
60
56
  end
61
57
 
62
- it 'should return success if the payment refund is valid' do
58
+ it "should return success if the payment refund is valid" do
63
59
  response = @payment.refund(10710436)
64
60
  assert_instance_of Hash, response
65
61
  refute_nil response[:refund_request_id]
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  describe PaddlePay::Subscription::Plan do
6
6
  before do
7
- PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
8
- PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
7
+ PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
8
+ PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
9
9
  @plan = PaddlePay::Subscription::Plan
10
10
  path = PaddlePay::Util.convert_class_to_path(@plan.name) + "/#{name}"
11
11
  VCR.insert_cassette(path)
@@ -15,40 +15,36 @@ describe PaddlePay::Subscription::Plan do
15
15
  VCR.eject_cassette
16
16
  end
17
17
 
18
- describe 'when plans are requested' do
19
- it 'should list all plans' do
18
+ describe "when plans are requested" do
19
+ it "should list all plans" do
20
20
  list = @plan.list
21
21
  assert_instance_of Array, list
22
22
  refute_nil list.first[:id] if list.count > 0
23
23
  end
24
24
 
25
- it 'should raise an error if no vendor id is present' do
25
+ it "should raise an error if no vendor id is present" do
26
26
  PaddlePay.config.vendor_id = nil
27
- exception = assert_raises PaddlePay::PaddlePayError do
28
- @plan.list
29
- end
27
+ exception = assert_raises(PaddlePay::PaddlePayError) { @plan.list }
30
28
  assert_equal exception.code, 107 # You don't have permission to access this resource
31
29
  end
32
30
 
33
- it 'should raise an error if no vendor auth code is present' do
31
+ it "should raise an error if no vendor auth code is present" do
34
32
  PaddlePay.config.vendor_auth_code = nil
35
- exception = assert_raises PaddlePay::PaddlePayError do
36
- @plan.list
37
- end
33
+ exception = assert_raises(PaddlePay::PaddlePayError) { @plan.list }
38
34
  assert_equal exception.code, 107 # You don't have permission to access this resource
39
35
  end
40
36
  end
41
37
 
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' }
38
+ describe "when the creation of a plan is requested" do
39
+ it "should raise an error if the plan is invalid" do
40
+ plan = {plan_name: "Test", plan_trial_days: 30, plan_length: 1, plan_type: "month"}
45
41
  assert_raises PaddlePay::PaddlePayError do
46
42
  @plan.create(plan)
47
43
  end
48
44
  end
49
45
 
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' }
46
+ it "should return a product id if the plan is valid" do
47
+ plan = {plan_name: "Test", plan_trial_days: 30, plan_length: 1, plan_type: "month", main_currency_code: "USD", recurring_price_usd: "5.00"}
52
48
  response = @plan.create(plan)
53
49
  assert_instance_of Hash, response
54
50
  refute_nil response[:product_id]
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  describe PaddlePay::Subscription::User do
6
6
  before do
7
- PaddlePay.config.vendor_id = ENV['PADDLE_VENDOR_ID']
8
- PaddlePay.config.vendor_auth_code = ENV['PADDLE_VENDOR_AUTH_CODE']
7
+ PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
8
+ PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
9
9
  @user = PaddlePay::Subscription::User
10
10
  path = PaddlePay::Util.convert_class_to_path(@user.name) + "/#{name}"
11
11
  puts path
@@ -16,70 +16,66 @@ describe PaddlePay::Subscription::User do
16
16
  VCR.eject_cassette
17
17
  end
18
18
 
19
- describe 'when users are requested' do
20
- it 'should list all users' do
19
+ describe "when users are requested" do
20
+ it "should list all users" do
21
21
  list = @user.list
22
22
  assert_instance_of Array, list
23
23
  refute_nil list.first[:user_id] if list.count > 0
24
24
  end
25
25
 
26
- it 'should raise an error if no vendor id is present' do
26
+ it "should raise an error if no vendor id is present" do
27
27
  PaddlePay.config.vendor_id = nil
28
- exception = assert_raises PaddlePay::PaddlePayError do
29
- @user.list
30
- end
28
+ exception = assert_raises(PaddlePay::PaddlePayError) { @user.list }
31
29
  assert_equal exception.code, 107 # You don't have permission to access this resource
32
30
  end
33
31
 
34
- it 'should raise an error if no vendor auth code is present' do
32
+ it "should raise an error if no vendor auth code is present" do
35
33
  PaddlePay.config.vendor_auth_code = nil
36
- exception = assert_raises PaddlePay::PaddlePayError do
37
- @user.list
38
- end
34
+ exception = assert_raises(PaddlePay::PaddlePayError) { @user.list }
39
35
  assert_equal exception.code, 107 # You don't have permission to access this resource
40
36
  end
41
37
  end
42
38
 
43
- describe 'when an update preview is requested' do
44
- it 'should raise an error if the subscription update preview is invalid' do
39
+ describe "when an update preview is requested" do
40
+ it "should raise an error if the subscription update preview is invalid" do
45
41
  subscription = {}
46
42
  assert_raises PaddlePay::PaddlePayError do
47
43
  @user.preview_update(3479984, subscription)
48
44
  end
49
45
  end
50
46
 
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 }
47
+ it "should return a subscription id if the subscription update preview is valid" do
48
+ subscription = {recurring_price: "10.00", currency: "USD", quantity: 1}
53
49
  response = @user.preview_update(3479984, subscription)
54
50
  assert_instance_of Hash, response
55
51
  refute_nil response[:subscription_id]
56
52
  end
57
53
  end
58
54
 
59
- describe 'when an update is requested' do
60
- it 'should raise an error if the subscription update is invalid' do
55
+ describe "when an update is requested" do
56
+ it "should raise an error if the subscription update is invalid" do
61
57
  subscription = {}
62
58
  assert_raises PaddlePay::PaddlePayError do
63
59
  @user.update(3479984, subscription)
64
60
  end
65
61
  end
66
62
 
67
- it 'should return a subscription id if the subscription update is valid' do
68
- subscription = { recurring_price: '10.00', currency: 'USD', quantity: 1 }
63
+ it "should return a subscription id if the subscription update is valid" do
64
+ subscription = {recurring_price: "10.00", currency: "USD", quantity: 1}
69
65
  response = @user.update(3479984, subscription)
70
66
  assert_instance_of Hash, response
71
67
  refute_nil response[:subscription_id]
72
68
  end
73
69
  end
74
70
 
75
- describe 'when a cancelation is requested' do
76
- it 'should raise an error if the cancelation is invalid' do
71
+ describe "when a cancelation is requested" do
72
+ it "should raise an error if the cancelation is invalid" do
77
73
  assert_raises PaddlePay::PaddlePayError do
78
74
  @user.cancel(1000000, {})
79
75
  end
80
76
  end
81
77
 
82
- it 'should return success if the cancelation is valid' do
78
+ it "should return success if the cancelation is valid" do
83
79
  response = @user.cancel(3479984)
84
80
  assert_nil response # no response when request is successful
85
81
  end