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.
- checksums.yaml +4 -4
- data/README.md +21 -2
- data/lib/paddle_pay.rb +23 -23
- data/lib/paddle_pay/configuration.rb +19 -6
- data/lib/paddle_pay/connection.rb +11 -11
- data/lib/paddle_pay/errors/paddle_pay_error.rb +4 -1
- data/lib/paddle_pay/models/alert/webhook.rb +2 -2
- data/lib/paddle_pay/models/product/coupon.rb +12 -12
- data/lib/paddle_pay/models/product/license.rb +2 -2
- data/lib/paddle_pay/models/product/pay_link.rb +2 -2
- data/lib/paddle_pay/models/product/payment.rb +4 -4
- data/lib/paddle_pay/models/product/product.rb +2 -2
- data/lib/paddle_pay/models/subscription/charge.rb +1 -1
- data/lib/paddle_pay/models/subscription/modifier.rb +6 -6
- data/lib/paddle_pay/models/subscription/payment.rb +7 -7
- data/lib/paddle_pay/models/subscription/plan.rb +4 -4
- data/lib/paddle_pay/models/subscription/user.rb +10 -10
- data/lib/paddle_pay/util.rb +6 -6
- data/lib/paddle_pay/version.rb +1 -1
- data/test/spec/paddle_pay/configuration_spec.rb +35 -7
- data/test/spec/paddle_pay/connection_spec.rb +38 -38
- data/test/spec/paddle_pay/models/alert/webhook_spec.rb +9 -13
- data/test/spec/paddle_pay/models/product/coupon_spec.rb +29 -33
- data/test/spec/paddle_pay/models/product/license_spec.rb +8 -8
- data/test/spec/paddle_pay/models/product/pay_link_spec.rb +8 -8
- data/test/spec/paddle_pay/models/product/payment_spec.rb +7 -7
- data/test/spec/paddle_pay/models/product/product_spec.rb +9 -13
- data/test/spec/paddle_pay/models/subscription/charge_spec.rb +8 -8
- data/test/spec/paddle_pay/models/subscription/modifier_spec.rb +17 -21
- data/test/spec/paddle_pay/models/subscription/payment_spec.rb +17 -21
- data/test/spec/paddle_pay/models/subscription/plan_spec.rb +14 -18
- data/test/spec/paddle_pay/models/subscription/user_spec.rb +20 -24
- data/test/spec/paddle_pay/models/transaction/checkout_spec.rb +10 -14
- data/test/spec/paddle_pay/models/transaction/order_spec.rb +10 -14
- data/test/spec/paddle_pay/models/transaction/product_spec.rb +9 -13
- data/test/spec/paddle_pay/models/transaction/subscription_spec.rb +9 -13
- data/test/spec/paddle_pay/models/transaction/user_spec.rb +9 -13
- data/test/spec/paddle_pay/util_spec.rb +19 -19
- data/test/spec/paddle_pay/version_spec.rb +2 -2
- data/test/test_helper.rb +10 -10
- metadata +35 -7
data/lib/paddle_pay/version.rb
CHANGED
@@ -1,24 +1,52 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
describe PaddlePay::Configuration do
|
6
6
|
before do
|
7
|
-
PaddlePay.config.vendor_id = ENV[
|
8
|
-
PaddlePay.config.vendor_auth_code = ENV[
|
7
|
+
PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
12
|
-
it
|
11
|
+
describe "when loading default configuration" do
|
12
|
+
it "should have a base url" do
|
13
13
|
assert !PaddlePay.config.vendors_url.nil?
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it "should have a vendor id" do
|
17
17
|
assert !PaddlePay.config.vendor_id.nil?
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "should have a vendor auth code" do
|
21
21
|
assert !PaddlePay.config.vendor_auth_code.nil?
|
22
22
|
end
|
23
|
+
|
24
|
+
it "should use the production url if no environment is set" do
|
25
|
+
assert_equal PaddlePay.config.vendors_url, "https://vendors.paddle.com/api"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "when loading production configuration" do
|
30
|
+
before do
|
31
|
+
PaddlePay.config.environment = :production
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should use the production url" do
|
35
|
+
assert_equal PaddlePay.config.vendors_url, "https://vendors.paddle.com/api"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "when loading development configuration" do
|
40
|
+
before do
|
41
|
+
PaddlePay.config.environment = :development
|
42
|
+
end
|
43
|
+
|
44
|
+
after do
|
45
|
+
PaddlePay.config.environment = :production
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should use the sandbox url" do
|
49
|
+
assert_equal PaddlePay.config.vendors_url, "https://sandbox-vendors.paddle.com/api"
|
50
|
+
end
|
23
51
|
end
|
24
52
|
end
|
@@ -1,114 +1,114 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
describe PaddlePay::Connection do
|
6
6
|
before do
|
7
7
|
@connection = PaddlePay::Connection
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
11
|
-
it
|
10
|
+
describe "when a request is made" do
|
11
|
+
it "should return a json parsed response if request is successful" do
|
12
12
|
stub_request(:post, PaddlePay.config.vendors_url)
|
13
13
|
.to_return(body: '{"success":true,"response":[{"data": "abcd"}]}', status: 200)
|
14
|
-
response = @connection.request(
|
14
|
+
response = @connection.request("")
|
15
15
|
assert_instance_of Array, response
|
16
|
-
assert_equal response.first[:data],
|
16
|
+
assert_equal response.first[:data], "abcd"
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it "should raise a paddle pay error if request is not successful" do
|
20
20
|
stub_request(:post, PaddlePay.config.vendors_url)
|
21
21
|
.to_return(body: '{"success":false,"error":{"code":100,"message":"Error"}}', status: 200)
|
22
22
|
assert_raises PaddlePay::PaddlePayError do
|
23
|
-
@connection.request(
|
23
|
+
@connection.request("")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it "should raise a parse error if response is not in json format" do
|
28
28
|
stub_request(:post, PaddlePay.config.vendors_url)
|
29
|
-
.to_return(body:
|
29
|
+
.to_return(body: "abcd", status: 200)
|
30
30
|
assert_raises PaddlePay::ParseError do
|
31
|
-
@connection.request(
|
31
|
+
@connection.request("")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it "should raise a bad request error if status 400 is returned" do
|
36
36
|
stub_request(:post, PaddlePay.config.vendors_url)
|
37
|
-
.to_return(status: [400,
|
37
|
+
.to_return(status: [400, "Bad Request"])
|
38
38
|
assert_raises PaddlePay::BadRequestError do
|
39
|
-
@connection.request(
|
39
|
+
@connection.request("")
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it "should raise an unauthorized error if status 401 is returned" do
|
44
44
|
stub_request(:post, PaddlePay.config.vendors_url)
|
45
|
-
.to_return(status: [401,
|
45
|
+
.to_return(status: [401, "Unauthorized"])
|
46
46
|
assert_raises PaddlePay::UnauthorizedError do
|
47
|
-
@connection.request(
|
47
|
+
@connection.request("")
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it "should raise a forbidden error if status 403 is returned" do
|
52
52
|
stub_request(:post, PaddlePay.config.vendors_url)
|
53
|
-
.to_return(status: [403,
|
53
|
+
.to_return(status: [403, "Forbidden"])
|
54
54
|
assert_raises PaddlePay::ForbiddenError do
|
55
|
-
@connection.request(
|
55
|
+
@connection.request("")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it "should raise a resource not found error if status 404 is returned" do
|
60
60
|
stub_request(:post, PaddlePay.config.vendors_url)
|
61
|
-
.to_return(status: [404,
|
61
|
+
.to_return(status: [404, "Not Found"])
|
62
62
|
assert_raises PaddlePay::ResourceNotFoundError do
|
63
|
-
@connection.request(
|
63
|
+
@connection.request("")
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it "should raise a proxy authentication error if status 407 is returned" do
|
68
68
|
stub_request(:post, PaddlePay.config.vendors_url)
|
69
|
-
.to_return(status: [407,
|
69
|
+
.to_return(status: [407, "Proxy Authentication Required"])
|
70
70
|
assert_raises PaddlePay::ProxyAuthError do
|
71
|
-
@connection.request(
|
71
|
+
@connection.request("")
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
it
|
75
|
+
it "should raise a conflict error if status 409 is returned" do
|
76
76
|
stub_request(:post, PaddlePay.config.vendors_url)
|
77
|
-
.to_return(status: [409,
|
77
|
+
.to_return(status: [409, "Conflict"])
|
78
78
|
assert_raises PaddlePay::ConflictError do
|
79
|
-
@connection.request(
|
79
|
+
@connection.request("")
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it "should raise an unprocessable entity error if status 422 is returned" do
|
84
84
|
stub_request(:post, PaddlePay.config.vendors_url)
|
85
|
-
.to_return(status: [422,
|
85
|
+
.to_return(status: [422, "Unprocessable Entity"])
|
86
86
|
assert_raises PaddlePay::UnprocessableEntityError do
|
87
|
-
@connection.request(
|
87
|
+
@connection.request("")
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
it
|
91
|
+
it "should raise a connection error if connection failed" do
|
92
92
|
stub_request(:post, PaddlePay.config.vendors_url)
|
93
93
|
.to_timeout
|
94
94
|
assert_raises PaddlePay::ConnectionError do
|
95
|
-
@connection.request(
|
95
|
+
@connection.request("")
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
99
|
+
it "should raise an timeout error if request timed out" do
|
100
100
|
stub_request(:post, PaddlePay.config.vendors_url)
|
101
101
|
.to_raise(Net::ReadTimeout)
|
102
102
|
assert_raises PaddlePay::TimeoutError do
|
103
|
-
@connection.request(
|
103
|
+
@connection.request("")
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
it
|
107
|
+
it "should raise a server error if status 500 is returned" do
|
108
108
|
stub_request(:post, PaddlePay.config.vendors_url)
|
109
|
-
.to_return(status: [500,
|
109
|
+
.to_return(status: [500, "Internal Server Error"])
|
110
110
|
assert_raises PaddlePay::ServerError do
|
111
|
-
@connection.request(
|
111
|
+
@connection.request("")
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
describe PaddlePay::Alert::Webhook do
|
6
6
|
before do
|
7
|
-
PaddlePay.config.vendor_id = ENV[
|
8
|
-
PaddlePay.config.vendor_auth_code = ENV[
|
7
|
+
PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
|
9
9
|
@webhook = PaddlePay::Alert::Webhook
|
10
10
|
path = PaddlePay::Util.convert_class_to_path(@webhook.name) + "/#{name}"
|
11
11
|
VCR.insert_cassette(path)
|
@@ -15,26 +15,22 @@ describe PaddlePay::Alert::Webhook do
|
|
15
15
|
VCR.eject_cassette
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
it
|
18
|
+
describe "when webhooks are requested" do
|
19
|
+
it "should list all webhooks" do
|
20
20
|
response = @webhook.history
|
21
21
|
assert_instance_of Hash, response
|
22
22
|
refute_nil response[:data]
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "should raise an error if no vendor id is present" do
|
26
26
|
PaddlePay.config.vendor_id = nil
|
27
|
-
exception = assert_raises
|
28
|
-
@webhook.history
|
29
|
-
end
|
27
|
+
exception = assert_raises(PaddlePay::PaddlePayError) { @webhook.history }
|
30
28
|
assert_equal exception.code, 107 # You don't have permission to access this resource
|
31
29
|
end
|
32
30
|
|
33
|
-
it
|
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
|
36
|
-
@webhook.history
|
37
|
-
end
|
33
|
+
exception = assert_raises(PaddlePay::PaddlePayError) { @webhook.history }
|
38
34
|
assert_equal exception.code, 107 # You don't have permission to access this resource
|
39
35
|
end
|
40
36
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
describe PaddlePay::Product::Coupon do
|
6
6
|
before do
|
7
|
-
PaddlePay.config.vendor_id = ENV[
|
8
|
-
PaddlePay.config.vendor_auth_code = ENV[
|
7
|
+
PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
|
9
9
|
@coupon = PaddlePay::Product::Coupon
|
10
10
|
path = PaddlePay::Util.convert_class_to_path(@coupon.name) + "/#{name}"
|
11
11
|
VCR.insert_cassette(path)
|
@@ -15,83 +15,79 @@ describe PaddlePay::Product::Coupon do
|
|
15
15
|
VCR.eject_cassette
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
it
|
18
|
+
describe "when coupons are requested" do
|
19
|
+
it "should list all coupons" do
|
20
20
|
list = @coupon.list(594469)
|
21
21
|
assert_instance_of Array, list
|
22
22
|
refute_nil list.first[:coupon] if list.count > 0
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "should raise an error if no vendor id is present" do
|
26
26
|
PaddlePay.config.vendor_id = nil
|
27
|
-
exception = assert_raises
|
28
|
-
@coupon.list(594469)
|
29
|
-
end
|
27
|
+
exception = assert_raises(PaddlePay::PaddlePayError) { @coupon.list(594469) }
|
30
28
|
assert_equal exception.code, 107 # You don't have permission to access this resource
|
31
29
|
end
|
32
30
|
|
33
|
-
it
|
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
|
36
|
-
@coupon.list(594469)
|
37
|
-
end
|
33
|
+
exception = assert_raises(PaddlePay::PaddlePayError) { @coupon.list(594469) }
|
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
|
43
|
-
it
|
44
|
-
coupon = {
|
38
|
+
describe "when the creation of a coupon is requested" do
|
39
|
+
it "should raise an error if the coupon is invalid" do
|
40
|
+
coupon = {coupon_type: "checkout"}
|
45
41
|
assert_raises PaddlePay::PaddlePayError do
|
46
42
|
@coupon.create(coupon)
|
47
43
|
end
|
48
44
|
end
|
49
45
|
|
50
|
-
it
|
51
|
-
coupon = {
|
46
|
+
it "should return coupon codes if the coupon is valid" do
|
47
|
+
coupon = {coupon_type: "checkout", discount_type: "percentage", discount_amount: "100", allowed_uses: 10}
|
52
48
|
response = @coupon.create(coupon)
|
53
49
|
assert_instance_of Hash, response
|
54
50
|
refute_nil response[:coupon_codes]
|
55
51
|
end
|
56
52
|
end
|
57
53
|
|
58
|
-
describe
|
59
|
-
it
|
60
|
-
response = @coupon.update_code(
|
54
|
+
describe "when the update of a coupon is requested" do
|
55
|
+
it "should return updated == 0 if the coupon update is invalid" do
|
56
|
+
response = @coupon.update_code("NOVALIDCODE", {allowed_uses: 20})
|
61
57
|
assert_instance_of Hash, response
|
62
58
|
assert_equal response[:updated], 0
|
63
59
|
end
|
64
60
|
|
65
|
-
it
|
66
|
-
response = @coupon.update_code(
|
61
|
+
it "should return updated > 0 if the coupon update is valid" do
|
62
|
+
response = @coupon.update_code("7D0E7A68", {allowed_uses: 20})
|
67
63
|
assert_instance_of Hash, response
|
68
64
|
assert_equal response[:updated], 1
|
69
65
|
end
|
70
66
|
end
|
71
67
|
|
72
|
-
describe
|
73
|
-
it
|
74
|
-
response = @coupon.update_group(
|
68
|
+
describe "when the update of a coupon group is requested" do
|
69
|
+
it "should return updated == 0 if the coupon group update is invalid" do
|
70
|
+
response = @coupon.update_group("NOVALIDGROUP", {allowed_uses: 20})
|
75
71
|
assert_instance_of Hash, response
|
76
72
|
assert_equal response[:updated], 0
|
77
73
|
end
|
78
74
|
|
79
|
-
it
|
80
|
-
response = @coupon.update_group(
|
75
|
+
it "should return updated > 0 if the coupon group update is valid" do
|
76
|
+
response = @coupon.update_group("Testgroup", {allowed_uses: 30})
|
81
77
|
assert_instance_of Hash, response
|
82
78
|
assert_equal response[:updated], 1
|
83
79
|
end
|
84
80
|
end
|
85
81
|
|
86
|
-
describe
|
87
|
-
it
|
82
|
+
describe "when the deletion of a coupon is requested" do
|
83
|
+
it "should raise an error if the coupon deletion is invalid" do
|
88
84
|
assert_raises PaddlePay::PaddlePayError do
|
89
|
-
@coupon.delete(
|
85
|
+
@coupon.delete("NOVALIDCOUPON", 594470)
|
90
86
|
end
|
91
87
|
end
|
92
88
|
|
93
|
-
it
|
94
|
-
response = @coupon.delete(
|
89
|
+
it "should return success if the coupon deletion is valid" do
|
90
|
+
response = @coupon.delete("9F9F78DA", 594470)
|
95
91
|
assert_nil response # no response when request is successful
|
96
92
|
end
|
97
93
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
describe PaddlePay::Product::License do
|
6
6
|
before do
|
7
|
-
PaddlePay.config.vendor_id = ENV[
|
8
|
-
PaddlePay.config.vendor_auth_code = ENV[
|
7
|
+
PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
|
9
9
|
@license = PaddlePay::Product::License
|
10
10
|
path = PaddlePay::Util.convert_class_to_path(@license.name) + "/#{name}"
|
11
11
|
VCR.insert_cassette(path)
|
@@ -15,16 +15,16 @@ describe PaddlePay::Product::License do
|
|
15
15
|
VCR.eject_cassette
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
it
|
20
|
-
license = {
|
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
21
|
assert_raises PaddlePay::PaddlePayError do
|
22
22
|
@license.generate(license)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
27
|
-
license = {
|
26
|
+
it "should return a license code if license generation request is valid" do
|
27
|
+
license = {product_id: "594512", allowed_uses: 10}
|
28
28
|
response = @license.generate(license)
|
29
29
|
assert_instance_of Hash, response
|
30
30
|
refute_nil response[:license_code]
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
describe PaddlePay::Product::PayLink do
|
6
6
|
before do
|
7
|
-
PaddlePay.config.vendor_id = ENV[
|
8
|
-
PaddlePay.config.vendor_auth_code = ENV[
|
7
|
+
PaddlePay.config.vendor_id = ENV["PADDLE_VENDOR_ID"]
|
8
|
+
PaddlePay.config.vendor_auth_code = ENV["PADDLE_VENDOR_AUTH_CODE"]
|
9
9
|
@pay_link = PaddlePay::Product::PayLink
|
10
10
|
path = PaddlePay::Util.convert_class_to_path(@pay_link.name) + "/#{name}"
|
11
11
|
VCR.insert_cassette(path)
|
@@ -15,16 +15,16 @@ describe PaddlePay::Product::PayLink do
|
|
15
15
|
VCR.eject_cassette
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
it
|
20
|
-
pay_link = {
|
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
21
|
assert_raises PaddlePay::PaddlePayError do
|
22
22
|
@pay_link.generate(pay_link)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
27
|
-
pay_link = {
|
26
|
+
it "should return an url if pay link generation request is valid" do
|
27
|
+
pay_link = {product_id: "594512"}
|
28
28
|
response = @pay_link.generate(pay_link)
|
29
29
|
assert_instance_of Hash, response
|
30
30
|
refute_nil response[:url]
|