mollie-api-ruby 3.1.5 → 4.0.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +0 -3
- data/CHANGELOG.md +6 -0
- data/README.md +63 -119
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docs/migration_v2_2_x.md +67 -0
- data/docs/migration_v3_x.md +227 -0
- data/examples/chargebacks/get.rb +4 -0
- data/examples/chargebacks/list.rb +1 -0
- data/{website-docs → examples}/connect/authorize.rb +3 -2
- data/{website-docs → examples}/connect/tokens.rb +1 -1
- data/examples/customers/create-payment.rb +6 -0
- data/examples/customers/create.rb +5 -0
- data/examples/customers/delete.rb +1 -0
- data/examples/customers/get.rb +1 -0
- data/examples/customers/list-payments.rb +1 -0
- data/examples/customers/list.rb +1 -0
- data/examples/customers/update.rb +4 -0
- data/examples/invoices/get.rb +1 -0
- data/examples/invoices/list.rb +1 -0
- data/examples/mandates/create.rb +9 -0
- data/examples/mandates/delete.rb +1 -0
- data/examples/mandates/get.rb +1 -0
- data/examples/mandates/list.rb +1 -0
- data/examples/methods/get.rb +4 -0
- data/examples/methods/list.rb +4 -0
- data/examples/organisations/get-current.rb +1 -0
- data/examples/organisations/get.rb +1 -0
- data/examples/payments/create.rb +9 -0
- data/examples/payments/delete.rb +1 -0
- data/examples/payments/get-customer.rb +2 -0
- data/examples/payments/get-mandate.rb +2 -0
- data/examples/payments/get-settlement.rb +2 -0
- data/examples/payments/get-subscription.rb +2 -0
- data/examples/payments/get.rb +1 -0
- data/examples/payments/list.rb +1 -0
- data/examples/payments/webhook.rb +12 -0
- data/examples/permissions/get.rb +1 -0
- data/examples/permissions/list.rb +1 -0
- data/examples/profiles/create.rb +8 -0
- data/examples/profiles/delete.rb +1 -0
- data/examples/profiles/get.rb +1 -0
- data/examples/profiles/list-chargebacks.rb +2 -0
- data/examples/profiles/list-methods.rb +2 -0
- data/examples/profiles/list-payments.rb +2 -0
- data/examples/profiles/list-refunds.rb +2 -0
- data/examples/profiles/list.rb +1 -0
- data/examples/profiles/update.rb +5 -0
- data/examples/refunds/create.rb +5 -0
- data/examples/refunds/delete.rb +4 -0
- data/examples/refunds/get-payment.rb +2 -0
- data/examples/refunds/get.rb +4 -0
- data/examples/refunds/list.rb +1 -0
- data/examples/settlements/get.rb +1 -0
- data/examples/settlements/list-chargebacks.rb +1 -0
- data/examples/settlements/list-payments.rb +1 -0
- data/examples/settlements/list-refunds.rb +1 -0
- data/examples/settlements/list.rb +1 -0
- data/examples/settlements/next.rb +1 -0
- data/examples/settlements/open.rb +1 -0
- data/examples/subscriptions/create.rb +8 -0
- data/examples/subscriptions/delete.rb +4 -0
- data/examples/subscriptions/get.rb +4 -0
- data/examples/subscriptions/list.rb +1 -0
- data/examples/subscriptions/update.rb +5 -0
- data/lib/cacert.pem +168 -48
- data/lib/mollie.rb +1 -3
- data/lib/mollie/amount.rb +20 -0
- data/lib/mollie/base.rb +9 -8
- data/lib/mollie/chargeback.rb +25 -15
- data/lib/mollie/client.rb +33 -13
- data/lib/mollie/customer.rb +9 -14
- data/lib/mollie/customer/mandate.rb +17 -5
- data/lib/mollie/customer/subscription.rb +14 -15
- data/lib/mollie/exception.rb +15 -3
- data/lib/mollie/invoice.rb +30 -26
- data/lib/mollie/list.rb +27 -18
- data/lib/mollie/method.rb +17 -25
- data/lib/mollie/organization.rb +5 -11
- data/lib/mollie/payment.rb +89 -61
- data/lib/mollie/permission.rb +0 -1
- data/lib/mollie/profile.rb +18 -13
- data/lib/mollie/refund.rb +27 -7
- data/lib/mollie/settlement.rb +50 -9
- data/lib/mollie/util.rb +11 -0
- data/lib/mollie/version.rb +1 -1
- data/mollie-api-ruby.gemspec +0 -7
- data/test/mollie/amount_test.rb +30 -0
- data/test/mollie/base_test.rb +44 -44
- data/test/mollie/chargeback_test.rb +78 -17
- data/test/mollie/client_test.rb +29 -12
- data/test/mollie/customer/mandate_test.rb +85 -9
- data/test/mollie/customer/payment_test.rb +2 -2
- data/test/mollie/customer/subscription_test.rb +71 -20
- data/test/mollie/customer_test.rb +17 -89
- data/test/mollie/invoice_test.rb +40 -24
- data/test/mollie/list_test.rb +62 -18
- data/test/mollie/method_test.rb +2 -8
- data/test/mollie/organization_test.rb +28 -23
- data/test/mollie/payment/chargeback_test.rb +2 -3
- data/test/mollie/payment/refund_test.rb +2 -3
- data/test/mollie/payment_test.rb +272 -86
- data/test/mollie/permission_test.rb +0 -2
- data/test/mollie/profile_test.rb +129 -35
- data/test/mollie/refund_test.rb +90 -10
- data/test/mollie/settlement/chargeback_test.rb +2 -4
- data/test/mollie/settlement/payment_test.rb +2 -2
- data/test/mollie/settlement/refund_test.rb +2 -3
- data/test/mollie/settlement_test.rb +199 -98
- data/test/mollie/util_test.rb +31 -0
- metadata +96 -239
- data/examples/apis/api_docs.rb +0 -37
- data/examples/apis/chargebacks.rb +0 -17
- data/examples/apis/connect.rb +0 -58
- data/examples/apis/customers.rb +0 -116
- data/examples/apis/invoices.rb +0 -38
- data/examples/apis/issuers.rb +0 -35
- data/examples/apis/mandates.rb +0 -83
- data/examples/apis/methods.rb +0 -50
- data/examples/apis/organizations.rb +0 -16
- data/examples/apis/payments.rb +0 -174
- data/examples/apis/permissions.rb +0 -32
- data/examples/apis/profiles.rb +0 -126
- data/examples/apis/refunds.rb +0 -17
- data/examples/apis/settlements.rb +0 -84
- data/examples/apis/subscriptions.rb +0 -165
- data/examples/config.ru +0 -57
- data/examples/public/images/collapse.gif +0 -0
- data/examples/public/images/expand.gif +0 -0
- data/examples/public/images/explorer_icons.png +0 -0
- data/examples/public/images/favicon-16x16.png +0 -0
- data/examples/public/images/favicon-32x32.png +0 -0
- data/examples/public/images/favicon.ico +0 -0
- data/examples/public/images/logo_small.png +0 -0
- data/examples/public/images/pet_store_api.png +0 -0
- data/examples/public/images/throbber.gif +0 -0
- data/examples/public/images/wordnik_api.png +0 -0
- data/examples/public/index.html +0 -101
- data/examples/public/javascripts/lib/backbone-min.js +0 -1
- data/examples/public/javascripts/lib/es5-shim.js +0 -1
- data/examples/public/javascripts/lib/handlebars-4.0.5.js +0 -3
- data/examples/public/javascripts/lib/highlight.9.1.0.pack.js +0 -1
- data/examples/public/javascripts/lib/highlight.9.1.0.pack_extended.js +0 -1
- data/examples/public/javascripts/lib/jquery-1.8.0.min.js +0 -3
- data/examples/public/javascripts/lib/jquery.ba-bbq.min.js +0 -1
- data/examples/public/javascripts/lib/jquery.slideto.min.js +0 -1
- data/examples/public/javascripts/lib/jquery.wiggle.min.js +0 -1
- data/examples/public/javascripts/lib/js-yaml.min.js +0 -2
- data/examples/public/javascripts/lib/jsoneditor.min.js +0 -5
- data/examples/public/javascripts/lib/lodash.min.js +0 -2
- data/examples/public/javascripts/lib/marked.js +0 -1
- data/examples/public/javascripts/lib/object-assign-pollyfill.js +0 -1
- data/examples/public/javascripts/lib/sanitize-html.min.js +0 -4
- data/examples/public/javascripts/lib/swagger-oauth.js +0 -1
- data/examples/public/javascripts/swagger-ui.js +0 -25378
- data/examples/public/javascripts/swagger-ui.min.js +0 -15
- data/examples/public/javascripts/swagger_docs.js +0 -14
- data/examples/public/o2c.html +0 -20
- data/examples/public/stylesheets/reset.css +0 -1
- data/examples/public/stylesheets/screen.css +0 -1545
- data/examples/public/stylesheets/swagger_docs.css +0 -4
- data/examples/public/stylesheets/typography.css +0 -0
- data/lib/mollie/issuer.rb +0 -5
- data/lib/mollie/profile/api_key.rb +0 -19
- data/lib/mollie/relation.rb +0 -36
- data/test/mollie/issuer_test.rb +0 -19
- data/test/mollie/profile/apikey_test.rb +0 -31
- data/website-docs/chargebacks/list-all.rb +0 -12
- data/website-docs/customers/create-payment.rb +0 -13
- data/website-docs/customers/create.rb +0 -12
- data/website-docs/customers/delete.rb +0 -10
- data/website-docs/customers/get.rb +0 -10
- data/website-docs/customers/list-payments.rb +0 -10
- data/website-docs/customers/list.rb +0 -12
- data/website-docs/customers/update.rb +0 -11
- data/website-docs/invoices/get.rb +0 -10
- data/website-docs/invoices/list.rb +0 -12
- data/website-docs/issuers/get.rb +0 -10
- data/website-docs/issuers/list.rb +0 -12
- data/website-docs/mandates/create.rb +0 -16
- data/website-docs/mandates/delete.rb +0 -10
- data/website-docs/mandates/get.rb +0 -10
- data/website-docs/mandates/list.rb +0 -12
- data/website-docs/methods/get.rb +0 -10
- data/website-docs/methods/list.rb +0 -12
- data/website-docs/organisations/get.rb +0 -10
- data/website-docs/payments/create-refund.rb +0 -14
- data/website-docs/payments/create.rb +0 -16
- data/website-docs/payments/delete-refund.rb +0 -13
- data/website-docs/payments/delete.rb +0 -12
- data/website-docs/payments/get-chargeback.rb +0 -11
- data/website-docs/payments/get-refund.rb +0 -11
- data/website-docs/payments/get.rb +0 -10
- data/website-docs/payments/list-chargeback.rb +0 -13
- data/website-docs/payments/list-refunds.rb +0 -13
- data/website-docs/payments/list.rb +0 -12
- data/website-docs/payments/payment-webhook.rb +0 -21
- data/website-docs/permissions/get.rb +0 -10
- data/website-docs/permissions/list.rb +0 -12
- data/website-docs/profiles/create.rb +0 -15
- data/website-docs/profiles/delete.rb +0 -10
- data/website-docs/profiles/get-key.rb +0 -11
- data/website-docs/profiles/get.rb +0 -10
- data/website-docs/profiles/list-keys.rb +0 -13
- data/website-docs/profiles/list.rb +0 -12
- data/website-docs/profiles/reset-key.rb +0 -13
- data/website-docs/profiles/update.rb +0 -12
- data/website-docs/refunds/list.rb +0 -12
- data/website-docs/settlements/get.rb +0 -10
- data/website-docs/settlements/list-chargebacks.rb +0 -13
- data/website-docs/settlements/list-payments.rb +0 -13
- data/website-docs/settlements/list-refunds.rb +0 -13
- data/website-docs/settlements/list.rb +0 -12
- data/website-docs/settlements/next.rb +0 -9
- data/website-docs/settlements/open.rb +0 -9
- data/website-docs/subscriptions/create.rb +0 -14
- data/website-docs/subscriptions/delete.rb +0 -10
- data/website-docs/subscriptions/get.rb +0 -10
- data/website-docs/subscriptions/list.rb +0 -12
data/test/mollie/client_test.rb
CHANGED
@@ -17,7 +17,7 @@ module Mollie
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_perform_http_call_defaults
|
20
|
-
stub_request(:any, "https://api.mollie.
|
20
|
+
stub_request(:any, "https://api.mollie.com/v2/my-method")
|
21
21
|
.with(:headers => { 'Accept' => 'application/json',
|
22
22
|
'Content-type' => 'application/json',
|
23
23
|
'Authorization' => 'Bearer test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM',
|
@@ -27,7 +27,7 @@ module Mollie
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_perform_http_call_key_override
|
30
|
-
stub_request(:any, "https://localhost/
|
30
|
+
stub_request(:any, "https://localhost/v2/my-method")
|
31
31
|
.with(:headers => { 'Accept' => 'application/json',
|
32
32
|
'Content-type' => 'application/json',
|
33
33
|
'Authorization' => 'Bearer my_key',
|
@@ -38,7 +38,7 @@ module Mollie
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_perform_http_call_with_api_key_block
|
41
|
-
stub_request(:any, "https://api.mollie.
|
41
|
+
stub_request(:any, "https://api.mollie.com/v2/my-method")
|
42
42
|
.with(:headers => { 'Accept' => 'application/json',
|
43
43
|
'Content-type' => 'application/json',
|
44
44
|
'Authorization' => 'Bearer my_key',
|
@@ -54,7 +54,7 @@ module Mollie
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_get_request_convert_to_camel_case
|
57
|
-
stub_request(:get, "https://api.mollie.
|
57
|
+
stub_request(:get, "https://api.mollie.com/v2/my-method?myParam=ok")
|
58
58
|
.to_return(:status => 200, :body => "{}", :headers => {})
|
59
59
|
client.perform_http_call("GET", "my-method", nil, {}, { my_param: "ok" })
|
60
60
|
end
|
@@ -81,7 +81,7 @@ module Mollie
|
|
81
81
|
]
|
82
82
|
}
|
83
83
|
|
84
|
-
stub_request(:get, "https://api.mollie.
|
84
|
+
stub_request(:get, "https://api.mollie.com/v2/my-method")
|
85
85
|
.to_return(:status => 200, :body => response_body, :headers => {})
|
86
86
|
response = client.perform_http_call("GET", "my-method", nil, {})
|
87
87
|
|
@@ -91,7 +91,7 @@ module Mollie
|
|
91
91
|
def test_post_requests_convert_to_camel_case
|
92
92
|
expected_body = %{{"redirectUrl":"my-url"}}
|
93
93
|
|
94
|
-
stub_request(:post, "https://api.mollie.
|
94
|
+
stub_request(:post, "https://api.mollie.com/v2/my-method")
|
95
95
|
.with(body: expected_body)
|
96
96
|
.to_return(:status => 200, :body => "{}", :headers => {})
|
97
97
|
|
@@ -99,7 +99,7 @@ module Mollie
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_delete_requests_with_no_content_responses
|
102
|
-
stub_request(:delete, "https://api.mollie.
|
102
|
+
stub_request(:delete, "https://api.mollie.com/v2/my-method/1")
|
103
103
|
.to_return(:status => 204, :body => "", :headers => {})
|
104
104
|
|
105
105
|
client.perform_http_call("DELETE", "my-method", "1")
|
@@ -107,16 +107,33 @@ module Mollie
|
|
107
107
|
|
108
108
|
def test_error_response
|
109
109
|
response = <<-JSON
|
110
|
-
|
110
|
+
{
|
111
|
+
"status": 401,
|
112
|
+
"title": "Unauthorized Request",
|
113
|
+
"detail": "Missing authentication, or failed to authenticate",
|
114
|
+
"field": "test-field",
|
115
|
+
"_links": {
|
116
|
+
"documentation": {
|
117
|
+
"href": "https://www.mollie.com/en/docs/authentication",
|
118
|
+
"type": "text/html"
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
111
122
|
JSON
|
112
|
-
stub_request(:post, "https://api.mollie.nl/v1/my-method")
|
113
|
-
.to_return(:status => 500, :body => response, :headers => {})
|
114
123
|
|
115
|
-
|
124
|
+
json = JSON.parse(response)
|
125
|
+
stub_request(:post, "https://api.mollie.com/v2/my-method")
|
126
|
+
.to_return(:status => 401, :body => response, :headers => {})
|
127
|
+
|
128
|
+
e = assert_raise Mollie::RequestError.new(JSON.parse(response)) do
|
116
129
|
client.perform_http_call("POST", "my-method", nil, {})
|
117
130
|
end
|
118
131
|
|
119
|
-
assert_equal
|
132
|
+
assert_equal(json['status'], e.status)
|
133
|
+
assert_equal(json['title'], e.title)
|
134
|
+
assert_equal(json['detail'], e.detail)
|
135
|
+
assert_equal(json['field'], e.field)
|
136
|
+
assert_equal(json['_links'], e.links)
|
120
137
|
end
|
121
138
|
end
|
122
139
|
end
|
@@ -5,38 +5,114 @@ module Mollie
|
|
5
5
|
class MandateTest < Test::Unit::TestCase
|
6
6
|
def test_setting_attributes
|
7
7
|
attributes = {
|
8
|
-
id: "
|
8
|
+
id: "mdt_h3gAaD5zP",
|
9
9
|
status: "valid",
|
10
10
|
method: "creditcard",
|
11
|
-
customer_id: "cst_R6JLAuqEgm",
|
12
11
|
details: {
|
13
12
|
card_holder: "John Doe",
|
14
13
|
card_expiry_date: "2016-03-31"
|
15
14
|
},
|
16
|
-
|
15
|
+
mandate_reference: "YOUR-COMPANY-MD1380",
|
16
|
+
signature_date: "2018-05-07",
|
17
|
+
created_at: "2016-04-13T11:32:38.0Z",
|
18
|
+
_links: {
|
19
|
+
"self" => {
|
20
|
+
"href" => "https://api.mollie.com/v2/customers/cst_4qqhO89gsT/mandates/mdt_h3gAaD5zP",
|
21
|
+
"type" => "application/hal+json"
|
22
|
+
},
|
23
|
+
"customer" => {
|
24
|
+
"href" => "https://api.mollie.com/v2/customers/cst_4qqhO89gsT",
|
25
|
+
"type" => "application/hal+json"
|
26
|
+
},
|
27
|
+
"documentation" => {
|
28
|
+
"href" => "https://docs.mollie.com/reference/v2/mandates-api/get-mandate",
|
29
|
+
"type" => "text/html"
|
30
|
+
}
|
31
|
+
}
|
17
32
|
}
|
18
33
|
|
19
34
|
mandate = Mandate.new(attributes)
|
20
35
|
|
21
|
-
assert_equal '
|
36
|
+
assert_equal 'mdt_h3gAaD5zP', mandate.id
|
22
37
|
assert_equal 'valid', mandate.status
|
23
38
|
assert_equal 'creditcard', mandate.method
|
24
|
-
assert_equal '
|
25
|
-
assert_equal
|
39
|
+
assert_equal 'YOUR-COMPANY-MD1380', mandate.mandate_reference
|
40
|
+
assert_equal '2018-05-07', mandate.signature_date
|
41
|
+
assert_equal Time.parse('2016-04-13T11:32:38.0Z'), mandate.created_at
|
26
42
|
|
27
43
|
assert_equal 'John Doe', mandate.details.card_holder
|
28
44
|
assert_equal '2016-03-31', mandate.details.card_expiry_date
|
29
45
|
assert_equal nil, mandate.details.non_existing
|
30
46
|
end
|
31
47
|
|
32
|
-
def
|
48
|
+
def test_valid_invalid_pending
|
33
49
|
mandate = Mandate.new(status: Mandate::STATUS_VALID)
|
34
50
|
assert mandate.valid?
|
35
|
-
assert !mandate.invalid?
|
36
51
|
|
37
52
|
mandate = Mandate.new(status: Mandate::STATUS_INVALID)
|
38
|
-
assert !mandate.valid?
|
39
53
|
assert mandate.invalid?
|
54
|
+
|
55
|
+
mandate = Mandate.new(status: Mandate::STATUS_PENDING)
|
56
|
+
assert mandate.pending?
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_get_mandate
|
60
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cus-id/mandates/man-id")
|
61
|
+
.to_return(:status => 200, :body => %{{"id":"man-id", "method":"directdebit"}}, :headers => {})
|
62
|
+
|
63
|
+
mandate = Customer::Mandate.get("man-id", customer_id: "cus-id")
|
64
|
+
|
65
|
+
assert_equal "man-id", mandate.id
|
66
|
+
assert_equal "directdebit", mandate.method
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_create_mandate
|
70
|
+
stub_request(:post, "https://api.mollie.com/v2/customers/cus-id/mandates")
|
71
|
+
.with(body: %{{"method":"directdebit"}})
|
72
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "method":"directdebit"}}, :headers => {})
|
73
|
+
|
74
|
+
mandate = Customer::Mandate.create(
|
75
|
+
method: "directdebit",
|
76
|
+
customer_id: "cus-id"
|
77
|
+
)
|
78
|
+
|
79
|
+
assert_equal "my-id", mandate.id
|
80
|
+
assert_equal "directdebit", mandate.method
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_delete_mandate
|
84
|
+
stub_request(:delete, "https://api.mollie.com/v2/customers/cus-id/mandates/man-id")
|
85
|
+
.to_return(:status => 204, :headers => {})
|
86
|
+
|
87
|
+
mandate = Customer::Mandate.delete("man-id", customer_id: "cus-id")
|
88
|
+
assert_equal nil, mandate
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_get_customer
|
92
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cst_4qqhO89gsT/mandates/mdt_h3gAaD5zP")
|
93
|
+
.to_return(:status => 200, :body => %{
|
94
|
+
{
|
95
|
+
"resource": "mandate",
|
96
|
+
"id": "mdt_h3gAaD5zP",
|
97
|
+
"_links": {
|
98
|
+
"customer": {
|
99
|
+
"href": "https://api.mollie.com/v2/customers/cst_4qqhO89gsT",
|
100
|
+
"type": "application/hal+json"
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}, :headers => {})
|
105
|
+
|
106
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cst_4qqhO89gsT")
|
107
|
+
.to_return(:status => 200, :body => %{
|
108
|
+
{
|
109
|
+
"resource": "customer",
|
110
|
+
"id": "cst_4qqhO89gsT"
|
111
|
+
}
|
112
|
+
}, :headers => {})
|
113
|
+
|
114
|
+
mandate = Customer::Mandate.get("mdt_h3gAaD5zP", customer_id: 'cst_4qqhO89gsT')
|
115
|
+
assert_equal "cst_4qqhO89gsT", mandate.customer.id
|
40
116
|
end
|
41
117
|
end
|
42
118
|
end
|
@@ -10,8 +10,8 @@ module Mollie
|
|
10
10
|
|
11
11
|
|
12
12
|
def test_list_payments
|
13
|
-
stub_request(:get, "https://api.mollie.
|
14
|
-
.to_return(:status => 200, :body => %{{"
|
13
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cus-id/payments")
|
14
|
+
.to_return(:status => 200, :body => %{{"_embedded" : { "payments" : [{"id":"pay-id", "customer_id":"cus-id"}]}}}, :headers => {})
|
15
15
|
|
16
16
|
payments = Payment.all(customer_id: "cus-id")
|
17
17
|
|
@@ -5,20 +5,18 @@ module Mollie
|
|
5
5
|
class SubscriptionTest < Test::Unit::TestCase
|
6
6
|
def test_setting_attributes
|
7
7
|
attributes = {
|
8
|
-
id:
|
9
|
-
customer_id:
|
10
|
-
mode:
|
11
|
-
|
12
|
-
status:
|
13
|
-
amount:
|
14
|
-
times:
|
15
|
-
interval:
|
16
|
-
description:
|
17
|
-
method:
|
18
|
-
|
19
|
-
|
20
|
-
'webhook_url' => "https://example.org/payments/webhook"
|
21
|
-
}
|
8
|
+
id: "sub_rVKGtNd6s3",
|
9
|
+
customer_id: "cst_stTC2WHAuS",
|
10
|
+
mode: "live",
|
11
|
+
created_at: "2016-06-01T12:23:34.0Z",
|
12
|
+
status: "active",
|
13
|
+
amount: { "value" => "25.00", "currency" => "EUR" },
|
14
|
+
times: 4,
|
15
|
+
interval: "3 months",
|
16
|
+
description: "Quarterly payment",
|
17
|
+
method: "creditcard",
|
18
|
+
canceled_at: "2016-06-01T12:23:34.0Z",
|
19
|
+
webhook_url: "https://example.org/payments/webhook"
|
22
20
|
}
|
23
21
|
|
24
22
|
subscription = Subscription.new(attributes)
|
@@ -26,14 +24,15 @@ module Mollie
|
|
26
24
|
assert_equal "sub_rVKGtNd6s3", subscription.id
|
27
25
|
assert_equal "cst_stTC2WHAuS", subscription.customer_id
|
28
26
|
assert_equal "live", subscription.mode
|
29
|
-
assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.
|
27
|
+
assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.created_at
|
30
28
|
assert_equal "active", subscription.status
|
31
|
-
assert_equal BigDecimal.new(25
|
29
|
+
assert_equal BigDecimal.new("25.00"), subscription.amount.value
|
30
|
+
assert_equal "EUR", subscription.amount.currency
|
32
31
|
assert_equal 4, subscription.times
|
33
32
|
assert_equal "3 months", subscription.interval
|
34
33
|
assert_equal "Quarterly payment", subscription.description
|
35
34
|
assert_equal "creditcard", subscription.method
|
36
|
-
assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.
|
35
|
+
assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.canceled_at
|
37
36
|
assert_equal "https://example.org/payments/webhook", subscription.webhook_url
|
38
37
|
end
|
39
38
|
|
@@ -52,15 +51,67 @@ module Mollie
|
|
52
51
|
assert !Subscription.new(status: 'not-suspended').suspended?
|
53
52
|
end
|
54
53
|
|
55
|
-
def
|
56
|
-
assert Subscription.new(status: Subscription::
|
57
|
-
assert !Subscription.new(status: 'not-
|
54
|
+
def test_status_canceled
|
55
|
+
assert Subscription.new(status: Subscription::STATUS_CANCELED).canceled?
|
56
|
+
assert !Subscription.new(status: 'not-canceled').canceled?
|
58
57
|
end
|
59
58
|
|
60
59
|
def test_status_completed
|
61
60
|
assert Subscription.new(status: Subscription::STATUS_COMPLETED).completed?
|
62
61
|
assert !Subscription.new(status: 'not-completed').completed?
|
63
62
|
end
|
63
|
+
|
64
|
+
def test_get_subscription
|
65
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cus-id/subscriptions/sub-id")
|
66
|
+
.to_return(:status => 200, :body => %{{"id":"sub-id", "customer_id":"cus-id"}}, :headers => {})
|
67
|
+
|
68
|
+
subscription = Customer::Subscription.get("sub-id", customer_id: "cus-id")
|
69
|
+
|
70
|
+
assert_equal "sub-id", subscription.id
|
71
|
+
assert_equal "cus-id", subscription.customer_id
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_create_subscription
|
75
|
+
stub_request(:post, "https://api.mollie.com/v2/customers/cus-id/subscriptions")
|
76
|
+
.with(body: %{{"amount":{"value":1.95,"currency":"EUR"}}})
|
77
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "amount": { "value" : 1.95, "currency": "EUR"}}}, :headers => {})
|
78
|
+
|
79
|
+
subscription = Customer::Subscription.create(customer_id: 'cus-id', amount: { value: 1.95, currency: "EUR" })
|
80
|
+
|
81
|
+
assert_equal "my-id", subscription.id
|
82
|
+
assert_equal BigDecimal.new("1.95"), subscription.amount.value
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_delete_subscription
|
86
|
+
stub_request(:delete, "https://api.mollie.com/v2/customers/cus-id/subscriptions/sub-id")
|
87
|
+
.to_return(:status => 204, :headers => {})
|
88
|
+
|
89
|
+
subscription = Customer::Subscription.delete("sub-id", customer_id: "cus-id")
|
90
|
+
assert_equal nil, subscription
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_get_customer
|
94
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_rVKGtNd6s3")
|
95
|
+
.to_return(:status => 200, :body => %{
|
96
|
+
{
|
97
|
+
"resource": "subscription",
|
98
|
+
"id": "sub_rVKGtNd6s3",
|
99
|
+
"customer_id": "cst_8wmqcHMN4U"
|
100
|
+
}
|
101
|
+
}, :headers => {})
|
102
|
+
|
103
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U")
|
104
|
+
.to_return(:status => 200, :body => %{
|
105
|
+
{
|
106
|
+
"resource": "customer",
|
107
|
+
"id": "cst_8wmqcHMN4U"
|
108
|
+
}
|
109
|
+
}, :headers => {})
|
110
|
+
|
111
|
+
payment = Customer::Subscription.get("sub_rVKGtNd6s3", customer_id: "cst_8wmqcHMN4U")
|
112
|
+
customer = payment.customer
|
113
|
+
assert_equal "cst_8wmqcHMN4U", customer.id
|
114
|
+
end
|
64
115
|
end
|
65
116
|
end
|
66
117
|
end
|
@@ -4,14 +4,13 @@ module Mollie
|
|
4
4
|
class CustomerTest < Test::Unit::TestCase
|
5
5
|
def test_setting_attributes
|
6
6
|
attributes = {
|
7
|
-
id:
|
8
|
-
mode:
|
9
|
-
name:
|
10
|
-
email:
|
11
|
-
locale:
|
12
|
-
metadata:
|
13
|
-
|
14
|
-
created_datetime: '2016-04-06T13:23:21.0Z'
|
7
|
+
id: 'cst_vsKJpSsabw',
|
8
|
+
mode: 'test',
|
9
|
+
name: 'Customer A',
|
10
|
+
email: 'customer@example.org',
|
11
|
+
locale: 'nl_NL',
|
12
|
+
metadata: { my_field: 'value' },
|
13
|
+
created_at: '2016-04-06T13:23:21.0Z'
|
15
14
|
}
|
16
15
|
|
17
16
|
customer = Customer.new(attributes)
|
@@ -21,108 +20,37 @@ module Mollie
|
|
21
20
|
assert_equal 'Customer A', customer.name
|
22
21
|
assert_equal 'customer@example.org', customer.email
|
23
22
|
assert_equal 'nl_NL', customer.locale
|
24
|
-
assert_equal
|
25
|
-
assert_equal Time.parse('2016-04-06T13:23:21.0Z'), customer.created_datetime
|
23
|
+
assert_equal Time.parse('2016-04-06T13:23:21.0Z'), customer.created_at
|
26
24
|
|
27
25
|
assert_equal 'value', customer.metadata.my_field
|
28
26
|
assert_equal nil, customer.metadata.non_existing
|
29
27
|
end
|
30
28
|
|
31
29
|
def test_list_mandates
|
32
|
-
stub_request(:get, "https://api.mollie.
|
33
|
-
.to_return(:status => 200, :body => %{{"
|
30
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cus-id/mandates")
|
31
|
+
.to_return(:status => 200, :body => %{{"_embedded" : { "mandates" : [{"id":"man-id", "customer_id":"cus-id"}]}} }, :headers => {})
|
34
32
|
|
35
|
-
mandates = Customer.new(id: "cus-id").mandates
|
33
|
+
mandates = Customer.new(id: "cus-id").mandates
|
36
34
|
|
37
35
|
assert_equal "man-id", mandates.first.id
|
38
36
|
end
|
39
37
|
|
40
|
-
def test_create_mandate
|
41
|
-
stub_request(:post, "https://api.mollie.nl/v1/customers/cus-id/mandates")
|
42
|
-
.with(body: %{{"method":"directdebit"}})
|
43
|
-
.to_return(:status => 201, :body => %{{"id":"my-id", "method":"directdebit"}}, :headers => {})
|
44
|
-
|
45
|
-
mandate = Customer.new(id: "cus-id").mandates.create(method: "directdebit")
|
46
|
-
|
47
|
-
assert_equal "my-id", mandate.id
|
48
|
-
assert_equal "directdebit", mandate.method
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_delete_mandate
|
52
|
-
stub_request(:delete, "https://api.mollie.nl/v1/customers/cus-id/mandates/man-id")
|
53
|
-
.to_return(:status => 204, :headers => {})
|
54
|
-
|
55
|
-
mandate = Customer.new(id: "cus-id").mandates.delete("man-id")
|
56
|
-
assert_equal nil, mandate
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_get_mandate
|
60
|
-
stub_request(:get, "https://api.mollie.nl/v1/customers/cus-id/mandates/man-id")
|
61
|
-
.to_return(:status => 200, :body => %{{"id":"man-id", "customer_id":"cus-id"}}, :headers => {})
|
62
|
-
|
63
|
-
mandate = Customer.new(id: "cus-id").mandates.get("man-id")
|
64
|
-
|
65
|
-
assert_equal "man-id", mandate.id
|
66
|
-
assert_equal "cus-id", mandate.customer_id
|
67
|
-
end
|
68
|
-
|
69
38
|
def test_list_subscriptions
|
70
|
-
stub_request(:get, "https://api.mollie.
|
71
|
-
.to_return(:status => 200, :body => %{{"
|
39
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cus-id/subscriptions")
|
40
|
+
.to_return(:status => 200, :body => %{{"_embedded" : {"subscriptions" : [{"id":"sub-id", "customer_id":"cus-id"}]}} }, :headers => {})
|
72
41
|
|
73
|
-
subscriptions = Customer.new(id: "cus-id").subscriptions
|
42
|
+
subscriptions = Customer.new(id: "cus-id").subscriptions
|
74
43
|
|
75
44
|
assert_equal "sub-id", subscriptions.first.id
|
76
45
|
end
|
77
46
|
|
78
|
-
def test_create_subscription
|
79
|
-
stub_request(:post, "https://api.mollie.nl/v1/customers/cus-id/subscriptions")
|
80
|
-
.with(body: %{{"amount":1.95}})
|
81
|
-
.to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.95}}, :headers => {})
|
82
|
-
|
83
|
-
subscription = Customer.new(id: "cus-id").subscriptions.create(amount: 1.95)
|
84
|
-
|
85
|
-
assert_equal "my-id", subscription.id
|
86
|
-
assert_equal BigDecimal.new("1.95"), subscription.amount
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_delete_subscription
|
90
|
-
stub_request(:delete, "https://api.mollie.nl/v1/customers/cus-id/subscriptions/sub-id")
|
91
|
-
.to_return(:status => 204, :headers => {})
|
92
|
-
|
93
|
-
subscription = Customer.new(id: "cus-id").subscriptions.delete("sub-id")
|
94
|
-
assert_equal nil, subscription
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_get_subscription
|
98
|
-
stub_request(:get, "https://api.mollie.nl/v1/customers/cus-id/subscriptions/sub-id")
|
99
|
-
.to_return(:status => 200, :body => %{{"id":"sub-id", "customer_id":"cus-id"}}, :headers => {})
|
100
|
-
|
101
|
-
subscription = Customer.new(id: "cus-id").subscriptions.get("sub-id")
|
102
|
-
|
103
|
-
assert_equal "sub-id", subscription.id
|
104
|
-
assert_equal "cus-id", subscription.customer_id
|
105
|
-
end
|
106
|
-
|
107
47
|
def test_list_payments
|
108
|
-
stub_request(:get, "https://api.mollie.
|
109
|
-
.to_return(:status => 200, :body => %{{"
|
48
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cus-id/payments")
|
49
|
+
.to_return(:status => 200, :body => %{{"_embedded" : { "payments" : [{"id":"sub-id", "customer_id":"cus-id"}]}}}, :headers => {})
|
110
50
|
|
111
|
-
payments = Customer.new(id: "cus-id").payments
|
51
|
+
payments = Customer.new(id: "cus-id").payments
|
112
52
|
|
113
53
|
assert_equal "sub-id", payments.first.id
|
114
54
|
end
|
115
|
-
|
116
|
-
def test_create_payment
|
117
|
-
stub_request(:post, "https://api.mollie.nl/v1/customers/cus-id/payments")
|
118
|
-
.with(body: %{{"amount":1.95}})
|
119
|
-
.to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.95}}, :headers => {})
|
120
|
-
|
121
|
-
payment = Customer.new(id: "cus-id").payments.create(amount: 1.95)
|
122
|
-
|
123
|
-
assert_kind_of Mollie::Payment, payment
|
124
|
-
assert_equal "my-id", payment.id
|
125
|
-
assert_equal BigDecimal.new("1.95"), payment.amount
|
126
|
-
end
|
127
55
|
end
|
128
56
|
end
|