mollie-api-ruby 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +92 -0
- data/.travis.yml +3 -1
- data/CHANGELOG.md +1 -1
- data/Gemfile +1 -1
- data/Rakefile +1 -2
- data/bin/console +4 -4
- data/docs/migration_v2_2_x.md +1 -1
- data/docs/migration_v3_x.md +2 -2
- data/examples/chargebacks/get.rb +2 -2
- data/examples/customers/create-payment.rb +4 -4
- data/examples/customers/create.rb +3 -3
- data/examples/customers/delete.rb +1 -1
- data/examples/customers/get.rb +1 -1
- data/examples/customers/list-payments.rb +1 -1
- data/examples/customers/update.rb +2 -2
- data/examples/invoices/get.rb +1 -1
- data/examples/mandates/create.rb +7 -7
- data/examples/mandates/delete.rb +1 -1
- data/examples/mandates/get.rb +1 -1
- data/examples/mandates/list.rb +1 -1
- data/examples/methods/get.rb +2 -2
- data/examples/organisations/get.rb +1 -1
- data/examples/payments/delete.rb +1 -1
- data/examples/payments/get-customer.rb +1 -1
- data/examples/payments/get-mandate.rb +1 -1
- data/examples/payments/get-settlement.rb +1 -1
- data/examples/payments/get-subscription.rb +1 -1
- data/examples/payments/get.rb +1 -1
- data/examples/payments/webhook.rb +1 -1
- data/examples/permissions/get.rb +1 -1
- data/examples/profiles/create.rb +6 -6
- data/examples/profiles/delete.rb +1 -1
- data/examples/profiles/get.rb +1 -1
- data/examples/profiles/list-chargebacks.rb +1 -1
- data/examples/profiles/list-methods.rb +1 -1
- data/examples/profiles/list-payments.rb +1 -1
- data/examples/profiles/list-refunds.rb +1 -1
- data/examples/profiles/update.rb +3 -3
- data/examples/refunds/create.rb +3 -3
- data/examples/refunds/delete.rb +2 -2
- data/examples/refunds/get.rb +2 -2
- data/examples/settlements/get.rb +1 -1
- data/examples/settlements/list-chargebacks.rb +1 -1
- data/examples/settlements/list-payments.rb +1 -1
- data/examples/settlements/list-refunds.rb +1 -1
- data/examples/subscriptions/create.rb +5 -5
- data/examples/subscriptions/delete.rb +2 -2
- data/examples/subscriptions/get.rb +2 -2
- data/examples/subscriptions/list.rb +1 -1
- data/examples/subscriptions/update.rb +1 -1
- data/lib/cacert.pem +2 -26
- data/lib/mollie.rb +0 -1
- data/lib/mollie/amount.rb +1 -1
- data/lib/mollie/base.rb +8 -8
- data/lib/mollie/chargeback.rb +12 -6
- data/lib/mollie/client.rb +17 -17
- data/lib/mollie/customer/mandate.rb +10 -6
- data/lib/mollie/customer/subscription.rb +15 -7
- data/lib/mollie/exception.rb +1 -1
- data/lib/mollie/invoice.rb +14 -6
- data/lib/mollie/list.rb +9 -13
- data/lib/mollie/method.rb +15 -15
- data/lib/mollie/organization.rb +1 -1
- data/lib/mollie/payment.rb +36 -16
- data/lib/mollie/permission.rb +18 -17
- data/lib/mollie/profile.rb +11 -7
- data/lib/mollie/refund.rb +12 -8
- data/lib/mollie/settlement.rb +17 -9
- data/lib/mollie/util.rb +8 -8
- data/lib/mollie/version.rb +1 -1
- data/mollie-api-ruby.gemspec +5 -4
- data/test/helper.rb +1 -1
- data/test/mollie/amount_test.rb +1 -1
- data/test/mollie/base_test.rb +72 -72
- data/test/mollie/chargeback_test.rb +36 -37
- data/test/mollie/client_test.rb +49 -49
- data/test/mollie/customer/mandate_test.rb +40 -40
- data/test/mollie/customer/payment_test.rb +5 -6
- data/test/mollie/customer/subscription_test.rb +45 -45
- data/test/mollie/customer_test.rb +12 -12
- data/test/mollie/invoice_test.rb +29 -29
- data/test/mollie/list_test.rb +23 -23
- data/test/mollie/method_test.rb +8 -8
- data/test/mollie/organization_test.rb +9 -9
- data/test/mollie/payment/chargeback_test.rb +4 -4
- data/test/mollie/payment/refund_test.rb +4 -4
- data/test/mollie/payment_test.rb +111 -111
- data/test/mollie/profile_test.rb +41 -42
- data/test/mollie/refund_test.rb +39 -39
- data/test/mollie/settlement/chargeback_test.rb +4 -4
- data/test/mollie/settlement/payment_test.rb +5 -5
- data/test/mollie/settlement/refund_test.rb +4 -4
- data/test/mollie/settlement_test.rb +53 -53
- data/test/mollie/util_test.rb +9 -11
- data/test/run-test.rb +4 -4
- metadata +46 -30
@@ -4,64 +4,64 @@ module Mollie
|
|
4
4
|
class ChargebackTest < Test::Unit::TestCase
|
5
5
|
def test_setting_attributes
|
6
6
|
attributes = {
|
7
|
-
id:
|
8
|
-
amount: {
|
9
|
-
created_at:
|
10
|
-
reversed_at:
|
11
|
-
payment_id:
|
12
|
-
settlement_amount: {
|
7
|
+
id: 're_4qqhO89gsT',
|
8
|
+
amount: { 'value' => '5.95', 'currency' => 'EUR' },
|
9
|
+
created_at: '2016-10-08T07:59:53.0Z',
|
10
|
+
reversed_at: '2016-10-08T07:59:53.0Z',
|
11
|
+
payment_id: 'tr_WDqYK6vllg',
|
12
|
+
settlement_amount: { 'value' => '-5.95', 'currency' => 'EUR' }
|
13
13
|
}
|
14
14
|
|
15
15
|
chargeback = Chargeback.new(attributes)
|
16
16
|
|
17
|
-
assert_equal
|
18
|
-
assert_equal BigDecimal
|
19
|
-
assert_equal
|
20
|
-
assert_equal Time.parse(
|
21
|
-
assert_equal Time.parse(
|
22
|
-
assert_equal
|
23
|
-
assert_equal BigDecimal
|
24
|
-
assert_equal
|
17
|
+
assert_equal 're_4qqhO89gsT', chargeback.id
|
18
|
+
assert_equal BigDecimal('5.95'), chargeback.amount.value
|
19
|
+
assert_equal 'EUR', chargeback.amount.currency
|
20
|
+
assert_equal Time.parse('2016-10-08T07:59:53.0Z'), chargeback.created_at
|
21
|
+
assert_equal Time.parse('2016-10-08T07:59:53.0Z'), chargeback.reversed_at
|
22
|
+
assert_equal 'tr_WDqYK6vllg', chargeback.payment_id
|
23
|
+
assert_equal BigDecimal('-5.95'), chargeback.settlement_amount.value
|
24
|
+
assert_equal 'EUR', chargeback.settlement_amount.currency
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_reversed?
|
28
|
-
assert Chargeback.new(reversed_at:
|
28
|
+
assert Chargeback.new(reversed_at: '2016-10-08T07:59:53.0Z').reversed?
|
29
29
|
assert !Chargeback.new(reversed_at: nil).reversed?
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_get_chargeback
|
33
|
-
stub_request(:get,
|
34
|
-
.to_return(:
|
33
|
+
stub_request(:get, 'https://api.mollie.com/v2/payments/pay-id/chargebacks/chb-id')
|
34
|
+
.to_return(status: 200, body: %({"id":"chb-id"}), headers: {})
|
35
35
|
|
36
|
-
chargeback = Payment::Chargeback.get(
|
37
|
-
assert_equal
|
36
|
+
chargeback = Payment::Chargeback.get('chb-id', payment_id: 'pay-id')
|
37
|
+
assert_equal 'chb-id', chargeback.id
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_get_payment
|
41
|
-
stub_request(:get,
|
42
|
-
.to_return(:
|
41
|
+
stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/chargebacks/chb_n9z0tp')
|
42
|
+
.to_return(status: 200, body: %(
|
43
43
|
{
|
44
44
|
"resource": "chargeback",
|
45
45
|
"id": "chb_n9z0tp",
|
46
46
|
"paymentId": "tr_WDqYK6vllg"
|
47
47
|
}
|
48
|
-
|
48
|
+
), headers: {})
|
49
49
|
|
50
|
-
stub_request(:get,
|
51
|
-
.to_return(:
|
50
|
+
stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg')
|
51
|
+
.to_return(status: 200, body: %(
|
52
52
|
{
|
53
53
|
"resource": "payment",
|
54
54
|
"id": "tr_WDqYK6vllg"
|
55
55
|
}
|
56
|
-
|
56
|
+
), headers: {})
|
57
57
|
|
58
|
-
chargeback = Payment::Chargeback.get(
|
59
|
-
assert_equal
|
58
|
+
chargeback = Payment::Chargeback.get('chb_n9z0tp', payment_id: 'tr_WDqYK6vllg')
|
59
|
+
assert_equal 'tr_WDqYK6vllg', chargeback.payment.id
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_get_settlement
|
63
|
-
stub_request(:get,
|
64
|
-
.to_return(:
|
63
|
+
stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/chargebacks/chb_n9z0tp')
|
64
|
+
.to_return(status: 200, body: %(
|
65
65
|
{
|
66
66
|
"resource": "chargeback",
|
67
67
|
"id": "chb_n9z0tp",
|
@@ -73,24 +73,23 @@ module Mollie
|
|
73
73
|
}
|
74
74
|
}
|
75
75
|
}
|
76
|
-
|
76
|
+
), headers: {})
|
77
77
|
|
78
|
-
stub_request(:get,
|
79
|
-
.to_return(:
|
78
|
+
stub_request(:get, 'https://api.mollie.com/v2/settlements/stl_jDk30akdN')
|
79
|
+
.to_return(status: 200, body: %(
|
80
80
|
{
|
81
81
|
"resource": "settlement",
|
82
82
|
"id": "stl_jDk30akdN"
|
83
83
|
}
|
84
|
-
|
84
|
+
), headers: {})
|
85
85
|
|
86
|
-
chargeback = Payment::Chargeback.get(
|
87
|
-
assert_equal
|
86
|
+
chargeback = Payment::Chargeback.get('chb_n9z0tp', payment_id: 'tr_WDqYK6vllg')
|
87
|
+
assert_equal 'stl_jDk30akdN', chargeback.settlement.id
|
88
88
|
end
|
89
89
|
|
90
90
|
def test_nil_settlement
|
91
|
-
chargeback = Payment::Chargeback.new(id:
|
91
|
+
chargeback = Payment::Chargeback.new(id: 'chb_n9z0tp')
|
92
92
|
assert_nil chargeback.settlement
|
93
93
|
end
|
94
|
-
|
95
94
|
end
|
96
95
|
end
|
data/test/mollie/client_test.rb
CHANGED
@@ -3,60 +3,60 @@ require 'helper'
|
|
3
3
|
module Mollie
|
4
4
|
class ClientTest < Test::Unit::TestCase
|
5
5
|
def client
|
6
|
-
Mollie::Client.new(
|
6
|
+
Mollie::Client.new('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM')
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_initialize
|
10
|
-
assert_equal
|
10
|
+
assert_equal 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM', client.api_key
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_setting_the_api_endpoint
|
14
14
|
client = self.client
|
15
|
-
client.api_endpoint =
|
16
|
-
assert_equal
|
15
|
+
client.api_endpoint = 'http://my.endpoint/'
|
16
|
+
assert_equal 'http://my.endpoint', client.api_endpoint
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_perform_http_call_defaults
|
20
|
-
stub_request(:any,
|
21
|
-
.with(:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
.to_return(:
|
26
|
-
client.perform_http_call(
|
20
|
+
stub_request(:any, 'https://api.mollie.com/v2/my-method')
|
21
|
+
.with(headers: { 'Accept' => 'application/json',
|
22
|
+
'Content-type' => 'application/json',
|
23
|
+
'Authorization' => 'Bearer test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM',
|
24
|
+
'User-Agent' => /^Mollie\/#{Mollie::VERSION} Ruby\/#{RUBY_VERSION} OpenSSL\/.*$/ })
|
25
|
+
.to_return(status: 200, body: '{}', headers: {})
|
26
|
+
client.perform_http_call('GET', 'my-method', nil, {})
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_perform_http_call_key_override
|
30
|
-
stub_request(:any,
|
31
|
-
.with(:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
.to_return(:
|
36
|
-
client.perform_http_call(
|
37
|
-
client.perform_http_call(
|
30
|
+
stub_request(:any, 'https://localhost/v2/my-method')
|
31
|
+
.with(headers: { 'Accept' => 'application/json',
|
32
|
+
'Content-type' => 'application/json',
|
33
|
+
'Authorization' => 'Bearer my_key',
|
34
|
+
'User-Agent' => /^Mollie\/#{Mollie::VERSION} Ruby\/#{RUBY_VERSION} OpenSSL\/.*$/ })
|
35
|
+
.to_return(status: 200, body: '{}', headers: {})
|
36
|
+
client.perform_http_call('GET', 'my-method', nil, { api_key: 'my_key', api_endpoint: 'https://localhost' })
|
37
|
+
client.perform_http_call('GET', 'my-method', nil, {}, { api_key: 'my_key', api_endpoint: 'https://localhost' })
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_perform_http_call_with_api_key_block
|
41
|
-
stub_request(:any,
|
42
|
-
.with(:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
.to_return(:
|
47
|
-
|
48
|
-
Mollie::Client.instance.api_key =
|
49
|
-
Mollie::Client.with_api_key(
|
50
|
-
assert_equal
|
51
|
-
Mollie::Client.instance.perform_http_call(
|
41
|
+
stub_request(:any, 'https://api.mollie.com/v2/my-method')
|
42
|
+
.with(headers: { 'Accept' => 'application/json',
|
43
|
+
'Content-type' => 'application/json',
|
44
|
+
'Authorization' => 'Bearer my_key',
|
45
|
+
'User-Agent' => /^Mollie\/#{Mollie::VERSION} Ruby\/#{RUBY_VERSION} OpenSSL\/.*$/ })
|
46
|
+
.to_return(status: 200, body: '{}', headers: {})
|
47
|
+
|
48
|
+
Mollie::Client.instance.api_key = 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM'
|
49
|
+
Mollie::Client.with_api_key('my_key') do
|
50
|
+
assert_equal 'my_key', Mollie::Client.instance.api_key
|
51
|
+
Mollie::Client.instance.perform_http_call('GET', 'my-method', nil, {})
|
52
52
|
end
|
53
|
-
assert_equal
|
53
|
+
assert_equal 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM', Mollie::Client.instance.api_key
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_get_request_convert_to_camel_case
|
57
|
-
stub_request(:get,
|
58
|
-
.to_return(:
|
59
|
-
client.perform_http_call(
|
57
|
+
stub_request(:get, 'https://api.mollie.com/v2/my-method?myParam=ok')
|
58
|
+
.to_return(status: 200, body: '{}', headers: {})
|
59
|
+
client.perform_http_call('GET', 'my-method', nil, {}, { my_param: 'ok' })
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_get_response_convert_to_snake_case
|
@@ -75,34 +75,34 @@ module Mollie
|
|
75
75
|
|
76
76
|
expected_response = {
|
77
77
|
'some_camel_cased' =>
|
78
|
-
{ 'also_nested' =>
|
78
|
+
{ 'also_nested' => 'camelCaseValue' },
|
79
79
|
'even_lists' => [
|
80
|
-
{ 'with_camel_case' =>
|
80
|
+
{ 'with_camel_case' => 'camelCaseValue' }
|
81
81
|
]
|
82
82
|
}
|
83
83
|
|
84
|
-
stub_request(:get,
|
85
|
-
.to_return(:
|
86
|
-
response = client.perform_http_call(
|
84
|
+
stub_request(:get, 'https://api.mollie.com/v2/my-method')
|
85
|
+
.to_return(status: 200, body: response_body, headers: {})
|
86
|
+
response = client.perform_http_call('GET', 'my-method', nil, {})
|
87
87
|
|
88
88
|
assert_equal expected_response, response
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_post_requests_convert_to_camel_case
|
92
|
-
expected_body = %{
|
92
|
+
expected_body = %({"redirectUrl":"my-url"})
|
93
93
|
|
94
|
-
stub_request(:post,
|
94
|
+
stub_request(:post, 'https://api.mollie.com/v2/my-method')
|
95
95
|
.with(body: expected_body)
|
96
|
-
.to_return(:
|
96
|
+
.to_return(status: 200, body: '{}', headers: {})
|
97
97
|
|
98
|
-
client.perform_http_call(
|
98
|
+
client.perform_http_call('POST', 'my-method', nil, redirect_url: 'my-url')
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_delete_requests_with_no_content_responses
|
102
|
-
stub_request(:delete,
|
103
|
-
.to_return(:
|
102
|
+
stub_request(:delete, 'https://api.mollie.com/v2/my-method/1')
|
103
|
+
.to_return(status: 204, body: '', headers: {})
|
104
104
|
|
105
|
-
client.perform_http_call(
|
105
|
+
client.perform_http_call('DELETE', 'my-method', '1')
|
106
106
|
end
|
107
107
|
|
108
108
|
def test_error_response
|
@@ -122,11 +122,11 @@ module Mollie
|
|
122
122
|
JSON
|
123
123
|
|
124
124
|
json = JSON.parse(response)
|
125
|
-
stub_request(:post,
|
126
|
-
.to_return(:
|
125
|
+
stub_request(:post, 'https://api.mollie.com/v2/my-method')
|
126
|
+
.to_return(status: 401, body: response, headers: {})
|
127
127
|
|
128
128
|
e = assert_raise Mollie::RequestError.new(JSON.parse(response)) do
|
129
|
-
client.perform_http_call(
|
129
|
+
client.perform_http_call('POST', 'my-method', nil, {})
|
130
130
|
end
|
131
131
|
|
132
132
|
assert_equal(json['status'], e.status)
|
@@ -5,28 +5,28 @@ module Mollie
|
|
5
5
|
class MandateTest < Test::Unit::TestCase
|
6
6
|
def test_setting_attributes
|
7
7
|
attributes = {
|
8
|
-
id:
|
9
|
-
status:
|
10
|
-
method:
|
8
|
+
id: 'mdt_h3gAaD5zP',
|
9
|
+
status: 'valid',
|
10
|
+
method: 'creditcard',
|
11
11
|
details: {
|
12
|
-
card_holder:
|
13
|
-
card_expiry_date:
|
12
|
+
card_holder: 'John Doe',
|
13
|
+
card_expiry_date: '2016-03-31'
|
14
14
|
},
|
15
|
-
mandate_reference:
|
16
|
-
signature_date:
|
17
|
-
created_at:
|
15
|
+
mandate_reference: 'YOUR-COMPANY-MD1380',
|
16
|
+
signature_date: '2018-05-07',
|
17
|
+
created_at: '2016-04-13T11:32:38.0Z',
|
18
18
|
_links: {
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
'self' => {
|
20
|
+
'href' => 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT/mandates/mdt_h3gAaD5zP',
|
21
|
+
'type' => 'application/hal+json'
|
22
22
|
},
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
'customer' => {
|
24
|
+
'href' => 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT',
|
25
|
+
'type' => 'application/hal+json'
|
26
26
|
},
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
'documentation' => {
|
28
|
+
'href' => 'https://docs.mollie.com/reference/v2/mandates-api/get-mandate',
|
29
|
+
'type' => 'text/html'
|
30
30
|
}
|
31
31
|
}
|
32
32
|
}
|
@@ -57,40 +57,40 @@ module Mollie
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_get_mandate
|
60
|
-
stub_request(:get,
|
61
|
-
.to_return(:
|
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
62
|
|
63
|
-
mandate = Customer::Mandate.get(
|
63
|
+
mandate = Customer::Mandate.get('man-id', customer_id: 'cus-id')
|
64
64
|
|
65
|
-
assert_equal
|
66
|
-
assert_equal
|
65
|
+
assert_equal 'man-id', mandate.id
|
66
|
+
assert_equal 'directdebit', mandate.method
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_create_mandate
|
70
|
-
stub_request(:post,
|
71
|
-
.with(body: %{
|
72
|
-
.to_return(:
|
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
73
|
|
74
74
|
mandate = Customer::Mandate.create(
|
75
|
-
method:
|
76
|
-
customer_id:
|
75
|
+
method: 'directdebit',
|
76
|
+
customer_id: 'cus-id'
|
77
77
|
)
|
78
78
|
|
79
|
-
assert_equal
|
80
|
-
assert_equal
|
79
|
+
assert_equal 'my-id', mandate.id
|
80
|
+
assert_equal 'directdebit', mandate.method
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_delete_mandate
|
84
|
-
stub_request(:delete,
|
85
|
-
.to_return(:
|
84
|
+
stub_request(:delete, 'https://api.mollie.com/v2/customers/cus-id/mandates/man-id')
|
85
|
+
.to_return(status: 204, headers: {})
|
86
86
|
|
87
|
-
mandate = Customer::Mandate.delete(
|
87
|
+
mandate = Customer::Mandate.delete('man-id', customer_id: 'cus-id')
|
88
88
|
assert_equal nil, mandate
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_get_customer
|
92
|
-
stub_request(:get,
|
93
|
-
.to_return(:
|
92
|
+
stub_request(:get, 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT/mandates/mdt_h3gAaD5zP')
|
93
|
+
.to_return(status: 200, body: %(
|
94
94
|
{
|
95
95
|
"resource": "mandate",
|
96
96
|
"id": "mdt_h3gAaD5zP",
|
@@ -101,18 +101,18 @@ module Mollie
|
|
101
101
|
}
|
102
102
|
}
|
103
103
|
}
|
104
|
-
|
104
|
+
), headers: {})
|
105
105
|
|
106
|
-
stub_request(:get,
|
107
|
-
.to_return(:
|
106
|
+
stub_request(:get, 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT')
|
107
|
+
.to_return(status: 200, body: %(
|
108
108
|
{
|
109
109
|
"resource": "customer",
|
110
110
|
"id": "cst_4qqhO89gsT"
|
111
111
|
}
|
112
|
-
|
112
|
+
), headers: {})
|
113
113
|
|
114
|
-
mandate = Customer::Mandate.get(
|
115
|
-
assert_equal
|
114
|
+
mandate = Customer::Mandate.get('mdt_h3gAaD5zP', customer_id: 'cst_4qqhO89gsT')
|
115
|
+
assert_equal 'cst_4qqhO89gsT', mandate.customer.id
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
@@ -8,15 +8,14 @@ module Mollie
|
|
8
8
|
assert_kind_of Mollie::Payment, payment
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
11
|
def test_list_payments
|
13
|
-
stub_request(:get,
|
14
|
-
.to_return(:
|
12
|
+
stub_request(:get, 'https://api.mollie.com/v2/customers/cus-id/payments')
|
13
|
+
.to_return(status: 200, body: %({"_embedded" : { "payments" : [{"id":"pay-id", "customer_id":"cus-id"}]}}), headers: {})
|
15
14
|
|
16
|
-
payments = Payment.all(customer_id:
|
15
|
+
payments = Payment.all(customer_id: 'cus-id')
|
17
16
|
|
18
|
-
assert_equal
|
19
|
-
assert_equal
|
17
|
+
assert_equal 'pay-id', payments.first.id
|
18
|
+
assert_equal 'cus-id', payments.first.customer_id
|
20
19
|
end
|
21
20
|
end
|
22
21
|
end
|
@@ -5,35 +5,35 @@ 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
|
-
created_at:
|
12
|
-
status:
|
13
|
-
amount: {
|
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
14
|
times: 4,
|
15
|
-
interval:
|
16
|
-
description:
|
17
|
-
method:
|
18
|
-
canceled_at:
|
19
|
-
webhook_url:
|
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'
|
20
20
|
}
|
21
21
|
|
22
22
|
subscription = Subscription.new(attributes)
|
23
23
|
|
24
|
-
assert_equal
|
25
|
-
assert_equal
|
26
|
-
assert_equal
|
27
|
-
assert_equal Time.parse(
|
28
|
-
assert_equal
|
29
|
-
assert_equal BigDecimal
|
30
|
-
assert_equal
|
24
|
+
assert_equal 'sub_rVKGtNd6s3', subscription.id
|
25
|
+
assert_equal 'cst_stTC2WHAuS', subscription.customer_id
|
26
|
+
assert_equal 'live', subscription.mode
|
27
|
+
assert_equal Time.parse('2016-06-01T12:23:34.0Z'), subscription.created_at
|
28
|
+
assert_equal 'active', subscription.status
|
29
|
+
assert_equal BigDecimal('25.00'), subscription.amount.value
|
30
|
+
assert_equal 'EUR', subscription.amount.currency
|
31
31
|
assert_equal 4, subscription.times
|
32
|
-
assert_equal
|
33
|
-
assert_equal
|
34
|
-
assert_equal
|
35
|
-
assert_equal Time.parse(
|
36
|
-
assert_equal
|
32
|
+
assert_equal '3 months', subscription.interval
|
33
|
+
assert_equal 'Quarterly payment', subscription.description
|
34
|
+
assert_equal 'creditcard', subscription.method
|
35
|
+
assert_equal Time.parse('2016-06-01T12:23:34.0Z'), subscription.canceled_at
|
36
|
+
assert_equal 'https://example.org/payments/webhook', subscription.webhook_url
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_status_active
|
@@ -62,55 +62,55 @@ module Mollie
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_get_subscription
|
65
|
-
stub_request(:get,
|
66
|
-
.to_return(:
|
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
67
|
|
68
|
-
subscription = Customer::Subscription.get(
|
68
|
+
subscription = Customer::Subscription.get('sub-id', customer_id: 'cus-id')
|
69
69
|
|
70
|
-
assert_equal
|
71
|
-
assert_equal
|
70
|
+
assert_equal 'sub-id', subscription.id
|
71
|
+
assert_equal 'cus-id', subscription.customer_id
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_create_subscription
|
75
|
-
stub_request(:post,
|
76
|
-
.with(body: %{
|
77
|
-
.to_return(:
|
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
78
|
|
79
|
-
subscription = Customer::Subscription.create(customer_id: 'cus-id', amount: { value: 1.95, currency:
|
79
|
+
subscription = Customer::Subscription.create(customer_id: 'cus-id', amount: { value: 1.95, currency: 'EUR' })
|
80
80
|
|
81
|
-
assert_equal
|
82
|
-
assert_equal BigDecimal
|
81
|
+
assert_equal 'my-id', subscription.id
|
82
|
+
assert_equal BigDecimal('1.95'), subscription.amount.value
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_delete_subscription
|
86
|
-
stub_request(:delete,
|
87
|
-
.to_return(:
|
86
|
+
stub_request(:delete, 'https://api.mollie.com/v2/customers/cus-id/subscriptions/sub-id')
|
87
|
+
.to_return(status: 204, headers: {})
|
88
88
|
|
89
|
-
subscription = Customer::Subscription.delete(
|
89
|
+
subscription = Customer::Subscription.delete('sub-id', customer_id: 'cus-id')
|
90
90
|
assert_equal nil, subscription
|
91
91
|
end
|
92
92
|
|
93
93
|
def test_get_customer
|
94
|
-
stub_request(:get,
|
95
|
-
.to_return(:
|
94
|
+
stub_request(:get, 'https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_rVKGtNd6s3')
|
95
|
+
.to_return(status: 200, body: %(
|
96
96
|
{
|
97
97
|
"resource": "subscription",
|
98
98
|
"id": "sub_rVKGtNd6s3",
|
99
99
|
"customer_id": "cst_8wmqcHMN4U"
|
100
100
|
}
|
101
|
-
|
101
|
+
), headers: {})
|
102
102
|
|
103
|
-
stub_request(:get,
|
104
|
-
.to_return(:
|
103
|
+
stub_request(:get, 'https://api.mollie.com/v2/customers/cst_8wmqcHMN4U')
|
104
|
+
.to_return(status: 200, body: %(
|
105
105
|
{
|
106
106
|
"resource": "customer",
|
107
107
|
"id": "cst_8wmqcHMN4U"
|
108
108
|
}
|
109
|
-
|
109
|
+
), headers: {})
|
110
110
|
|
111
|
-
payment = Customer::Subscription.get(
|
111
|
+
payment = Customer::Subscription.get('sub_rVKGtNd6s3', customer_id: 'cst_8wmqcHMN4U')
|
112
112
|
customer = payment.customer
|
113
|
-
assert_equal
|
113
|
+
assert_equal 'cst_8wmqcHMN4U', customer.id
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|