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/invoice_test.rb
CHANGED
@@ -4,50 +4,66 @@ module Mollie
|
|
4
4
|
class InvoiceTest < Test::Unit::TestCase
|
5
5
|
def test_setting_attributes
|
6
6
|
attributes = {
|
7
|
-
resource: "invoice",
|
8
7
|
id: "inv_xBEbP9rvAq",
|
9
8
|
reference: "2016.10000",
|
10
9
|
vat_number: "NL001234567B01",
|
11
10
|
status: "open",
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
gross: "54.45"
|
11
|
+
issued_at: "2016-08-31",
|
12
|
+
due_at: "2016-09-14",
|
13
|
+
net_amount: {
|
14
|
+
value: "45.00",
|
15
|
+
currency: "EUR"
|
18
16
|
},
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
vat_amount: {
|
18
|
+
value: "9.45",
|
19
|
+
currency: "EUR"
|
20
|
+
},
|
21
|
+
gross_amount: {
|
22
|
+
value: "54.45",
|
23
|
+
currency: "EUR"
|
24
|
+
},
|
25
|
+
lines: [
|
26
|
+
{
|
27
|
+
period: "2016-09",
|
28
|
+
description: "iDEAL transactiekosten",
|
29
|
+
count: 100,
|
30
|
+
vat_percentage: 21,
|
31
|
+
amount: {
|
32
|
+
value: "45.00",
|
33
|
+
currency: "EUR"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
],
|
37
|
+
_links: {
|
38
|
+
"pdf" => {
|
39
|
+
"href" => "https://www.mollie.com/beheer/facturen/2016.10000/52981a39788e5e0acaf71bbf570e941f/",
|
40
|
+
"type" => "application/pdf"
|
41
|
+
}
|
28
42
|
}
|
29
43
|
}
|
30
44
|
|
31
45
|
invoice = Invoice.new(attributes)
|
32
46
|
|
33
|
-
assert_equal "invoice", invoice.resource
|
34
47
|
assert_equal "inv_xBEbP9rvAq", invoice.id
|
35
48
|
assert_equal "2016.10000", invoice.reference
|
36
49
|
assert_equal "NL001234567B01", invoice.vat_number
|
37
50
|
assert_equal "open", invoice.status
|
38
|
-
assert_equal Time.parse("2016-08-31"), invoice.
|
39
|
-
assert_equal Time.parse("2016-09-14"), invoice.
|
40
|
-
assert_equal 45.0, invoice.
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
51
|
+
assert_equal Time.parse("2016-08-31"), invoice.issued_at
|
52
|
+
assert_equal Time.parse("2016-09-14"), invoice.due_at
|
53
|
+
assert_equal 45.0, invoice.net_amount.value
|
54
|
+
assert_equal 'EUR', invoice.net_amount.currency
|
55
|
+
assert_equal BigDecimal.new(9.45, 3), invoice.vat_amount.value
|
56
|
+
assert_equal 'EUR', invoice.vat_amount.currency
|
57
|
+
assert_equal 54.45, invoice.gross_amount.value
|
58
|
+
assert_equal 'EUR', invoice.gross_amount.currency
|
43
59
|
|
44
60
|
line = invoice.lines.first
|
45
61
|
assert_equal "2016-09", line.period
|
46
62
|
assert_equal "iDEAL transactiekosten", line.description
|
47
63
|
assert_equal 100, line.count
|
48
64
|
assert_equal 21, line.vat_percentage
|
49
|
-
assert_equal 45.0, line.amount
|
50
|
-
|
65
|
+
assert_equal 45.0, line.amount.value
|
66
|
+
assert_equal 'EUR', line.amount.currency
|
51
67
|
|
52
68
|
assert_equal "https://www.mollie.com/beheer/facturen/2016.10000/52981a39788e5e0acaf71bbf570e941f/", invoice.pdf
|
53
69
|
end
|
data/test/mollie/list_test.rb
CHANGED
@@ -4,37 +4,81 @@ module Mollie
|
|
4
4
|
class ListTest < Test::Unit::TestCase
|
5
5
|
def test_setting_attributes
|
6
6
|
attributes = {
|
7
|
-
'
|
8
|
-
'offset' => 0,
|
9
|
-
'count' => 10,
|
10
|
-
'data' => [
|
7
|
+
'_embedded' => { "payments" => [
|
11
8
|
{ 'id' => "tr_1" },
|
12
9
|
{ 'id' => "tr_2" },
|
13
|
-
],
|
14
|
-
'
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
] },
|
11
|
+
'count' => 2,
|
12
|
+
'_links' => {
|
13
|
+
"self" => {
|
14
|
+
"href" => "https://api.mollie.com/v2/payments?limit=5",
|
15
|
+
"type" => "application/hal+json"
|
16
|
+
},
|
17
|
+
"previous" => {
|
18
|
+
"href" => "https://api.mollie.com/v2/payments?from=tr_1&limit=1",
|
19
|
+
"type" => "application/hal+json"
|
20
|
+
},
|
21
|
+
"next" => {
|
22
|
+
"href" => "https://api.mollie.com/v2/payments?from=tr_2&limit=1",
|
23
|
+
"type" => "application/hal+json"
|
24
|
+
},
|
25
|
+
"documentation" => {
|
26
|
+
"href" => "https://docs.mollie.com/reference/payments/list",
|
27
|
+
"type" => "text/html"
|
28
|
+
}
|
19
29
|
}
|
20
30
|
}
|
21
31
|
|
22
32
|
list = Mollie::List.new(attributes, Payment)
|
23
33
|
|
24
|
-
assert_equal
|
25
|
-
assert_equal 0, list.offset
|
26
|
-
assert_equal 10, list.count
|
27
|
-
|
34
|
+
assert_equal 2, list.count
|
28
35
|
assert_kind_of Payment, list.to_a[0]
|
29
36
|
assert_equal "tr_1", list.to_a[0].id
|
30
37
|
|
31
38
|
assert_kind_of Payment, list.to_a[1]
|
32
39
|
assert_equal "tr_2", list.to_a[1].id
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_next_page
|
43
|
+
stub_request(:get, "https://api.mollie.com/v2/payments?from=tr_WDqYK6vllg&limit=10").
|
44
|
+
to_return(
|
45
|
+
status: 200,
|
46
|
+
body: %{{"_embedded":{"payments":[{"id":"tr_1"},{"id":"tr_2"}]},"count":2}},
|
47
|
+
headers: {}
|
48
|
+
)
|
49
|
+
|
50
|
+
attributes = {
|
51
|
+
'_links' => {
|
52
|
+
'next' => {
|
53
|
+
'href' => 'https://api.mollie.com/v2/payments?from=tr_WDqYK6vllg&limit=10',
|
54
|
+
'type' => 'application/hal+json'
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
list = Mollie::List.new(attributes, Payment)
|
60
|
+
assert_equal 2, list.next.count
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_previous_page
|
64
|
+
stub_request(:get, "https://api.mollie.com/v2/payments?from=tr_SDkzMggpvx&limit=10").
|
65
|
+
to_return(
|
66
|
+
status: 200,
|
67
|
+
body: %{{"_embedded":{"payments":[{"id":"tr_1"},{"id":"tr_2"}]},"count":2}},
|
68
|
+
headers: {}
|
69
|
+
)
|
70
|
+
|
71
|
+
attributes = {
|
72
|
+
'_links' => {
|
73
|
+
'previous' => {
|
74
|
+
'href' => 'https://api.mollie.com/v2/payments?from=tr_SDkzMggpvx&limit=10',
|
75
|
+
'type' => 'application/hal+json'
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
33
79
|
|
34
|
-
|
35
|
-
assert_equal
|
36
|
-
assert_equal "https://api.mollie.nl/v1/payments?count=10&offset=10", list.next_url
|
37
|
-
assert_equal "https://api.mollie.nl/v1/payments?count=10&offset=270", list.last_url
|
80
|
+
list = Mollie::List.new(attributes, Payment)
|
81
|
+
assert_equal 2, list.previous.count
|
38
82
|
end
|
39
83
|
end
|
40
84
|
end
|
data/test/mollie/method_test.rb
CHANGED
@@ -6,13 +6,9 @@ module Mollie
|
|
6
6
|
attributes = {
|
7
7
|
id: "creditcard",
|
8
8
|
description: "Credit card",
|
9
|
-
amount: {
|
10
|
-
'minimum' => "0.31",
|
11
|
-
'maximum' => "10000.00"
|
12
|
-
},
|
13
9
|
image: {
|
14
|
-
'
|
15
|
-
'
|
10
|
+
'size1x' => "https://www.mollie.com/images/payscreen/methods/creditcard.png",
|
11
|
+
'size2x' => "https://www.mollie.com/images/payscreen/methods/creditcard@2x.png"
|
16
12
|
}
|
17
13
|
}
|
18
14
|
|
@@ -20,8 +16,6 @@ module Mollie
|
|
20
16
|
|
21
17
|
assert_equal "creditcard", method.id
|
22
18
|
assert_equal "Credit card", method.description
|
23
|
-
assert_equal BigDecimal.new("0.31"), method.minimum_amount
|
24
|
-
assert_equal BigDecimal.new("10000.0"), method.maximum_amount
|
25
19
|
assert_equal "https://www.mollie.com/images/payscreen/methods/creditcard.png", method.normal_image
|
26
20
|
assert_equal "https://www.mollie.com/images/payscreen/methods/creditcard@2x.png", method.bigger_image
|
27
21
|
end
|
@@ -4,38 +4,43 @@ module Mollie
|
|
4
4
|
class OrganizationTest < Test::Unit::TestCase
|
5
5
|
def test_setting_attributes
|
6
6
|
attributes = {
|
7
|
-
id:
|
8
|
-
name:
|
9
|
-
email:
|
10
|
-
address:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
registration_number:
|
17
|
-
|
18
|
-
verified_datetime: '2007-06-29T09:41:00.0Z'
|
7
|
+
id: 'org_12345678',
|
8
|
+
name: 'Mollie B.V.',
|
9
|
+
email: 'info@mollie.com',
|
10
|
+
address: {
|
11
|
+
street_and_number: "Keizersgracht 313",
|
12
|
+
postal_code: "1016 EE",
|
13
|
+
city: "Amsterdam",
|
14
|
+
country: "NL"
|
15
|
+
},
|
16
|
+
registration_number: '30204462',
|
17
|
+
vat_number: 'NL815839091B01',
|
19
18
|
}
|
20
19
|
|
21
20
|
organization = Organization.new(attributes)
|
22
21
|
|
23
|
-
assert_equal '
|
22
|
+
assert_equal 'org_12345678', organization.id
|
24
23
|
assert_equal 'Mollie B.V.', organization.name
|
25
24
|
assert_equal 'info@mollie.com', organization.email
|
26
|
-
assert_equal 'Keizersgracht 313', organization.address
|
27
|
-
assert_equal '
|
28
|
-
assert_equal 'Amsterdam', organization.city
|
29
|
-
assert_equal '
|
30
|
-
assert_equal 'NL', organization.country_code
|
31
|
-
assert_equal 'bv', organization.registration_type
|
25
|
+
assert_equal 'Keizersgracht 313', organization.address.street_and_number
|
26
|
+
assert_equal '1016 EE', organization.address.postal_code
|
27
|
+
assert_equal 'Amsterdam', organization.address.city
|
28
|
+
assert_equal 'NL', organization.address.country
|
32
29
|
assert_equal '30204462', organization.registration_number
|
33
|
-
assert_equal
|
34
|
-
assert_equal Time.parse('2007-06-29T09:41:00.0Z'), organization.verified_datetime
|
30
|
+
assert_equal 'NL815839091B01', organization.vat_number
|
35
31
|
end
|
36
32
|
|
37
|
-
def
|
38
|
-
|
33
|
+
def test_current_organization
|
34
|
+
stub_request(:get, "https://api.mollie.com/v2/organizations/me")
|
35
|
+
.to_return(:status => 200, :body => %{
|
36
|
+
{
|
37
|
+
"resource": "organization",
|
38
|
+
"id": "org_12345678"
|
39
|
+
}
|
40
|
+
}, :headers => {})
|
41
|
+
|
42
|
+
organization = Organization.current
|
43
|
+
assert_equal "org_12345678", organization.id
|
39
44
|
end
|
40
45
|
end
|
41
46
|
end
|
@@ -9,13 +9,12 @@ module Mollie
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_list_chargebacks
|
12
|
-
stub_request(:get, "https://api.mollie.
|
13
|
-
.to_return(:status => 200, :body => %{{"
|
12
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/pay-id/chargebacks")
|
13
|
+
.to_return(:status => 200, :body => %{{"_embedded" : {"chargebacks" : [{"id":"re-id"}]}}}, :headers => {})
|
14
14
|
|
15
15
|
chargebacks = Mollie::Payment::Chargeback.all(payment_id: "pay-id")
|
16
16
|
|
17
17
|
assert_equal "re-id", chargebacks.first.id
|
18
|
-
assert_equal "pay-id", chargebacks.first.payment.id
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
@@ -9,13 +9,12 @@ module Mollie
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_list_refunds
|
12
|
-
stub_request(:get, "https://api.mollie.
|
13
|
-
.to_return(:status => 200, :body => %{{"
|
12
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/pay-id/refunds")
|
13
|
+
.to_return(:status => 200, :body => %{{"_embedded" : { "refunds" : [{"id":"re-id"}]}}}, :headers => {})
|
14
14
|
|
15
15
|
refunds = Mollie::Payment::Refund.all(payment_id: "pay-id")
|
16
16
|
|
17
17
|
assert_equal "re-id", refunds.first.id
|
18
|
-
assert_equal "pay-id", refunds.first.payment.id
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
data/test/mollie/payment_test.rb
CHANGED
@@ -4,56 +4,75 @@ module Mollie
|
|
4
4
|
class PaymentTest < Test::Unit::TestCase
|
5
5
|
def test_setting_attributes
|
6
6
|
attributes = {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
method: 'ideal',
|
15
|
-
country_code: 'NL',
|
16
|
-
metadata: {
|
17
|
-
order_id: '33'
|
7
|
+
resource: "payment",
|
8
|
+
id: "tr_7UhSN1zuXS",
|
9
|
+
mode: "test",
|
10
|
+
created_at: "2018-03-20T09:13:37+00:00",
|
11
|
+
amount: {
|
12
|
+
"value" => "10.00",
|
13
|
+
"currency" => "EUR"
|
18
14
|
},
|
19
|
-
|
15
|
+
description: "My first payment",
|
16
|
+
method: "ideal",
|
17
|
+
country_code: "NL",
|
18
|
+
metadata: {
|
19
|
+
order_id: "12345"
|
20
|
+
},
|
21
|
+
details: {
|
20
22
|
consumer_name: "Hr E G H K\u00fcppers en\/of MW M.J. K\u00fcppers-Veeneman",
|
21
|
-
consumer_account:
|
22
|
-
consumer_bic:
|
23
|
+
consumer_account: "NL53INGB0618365937",
|
24
|
+
consumer_bic: "INGBNL2A"
|
23
25
|
},
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
status: "paid",
|
27
|
+
paid_at: "2018-03-20T09:14:37+00:00",
|
28
|
+
is_cancelable: false,
|
29
|
+
expires_at: "2018-03-20T09:28:37+00:00",
|
30
|
+
locale: "nl_NL",
|
31
|
+
profile_id: "pfl_QkEhN94Ba",
|
32
|
+
sequence_type: "oneoff",
|
33
|
+
redirect_url: "https://webshop.example.org/order/12345",
|
34
|
+
webhook_url: "https://webshop.example.org/payments/webhook",
|
35
|
+
_links: {
|
36
|
+
"self" => {
|
37
|
+
"href" => "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS",
|
38
|
+
"type" => "application/json"
|
39
|
+
},
|
40
|
+
"checkout" => {
|
41
|
+
"href" => "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS",
|
42
|
+
"type" => "text/html"
|
43
|
+
},
|
44
|
+
"settlement" => {
|
45
|
+
"href" => "https://webshop.example.org/payment/tr_WDqYK6vllg/settlement",
|
46
|
+
},
|
47
|
+
"refunds" => {
|
48
|
+
"href" => "https://webshop.example.org/payment/tr_WDqYK6vllg/refunds",
|
49
|
+
"type" => "text/html"
|
50
|
+
}
|
32
51
|
}
|
33
52
|
}
|
34
53
|
|
35
54
|
payment = Payment.new(attributes)
|
36
55
|
|
37
|
-
assert_equal '
|
56
|
+
assert_equal 'tr_7UhSN1zuXS', payment.id
|
38
57
|
assert_equal 'test', payment.mode
|
39
|
-
assert_equal Time.parse('
|
58
|
+
assert_equal Time.parse('2018-03-20T09:13:37+00:00'), payment.created_at
|
40
59
|
assert_equal 'paid', payment.status
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
60
|
+
assert_equal true, payment.paid?
|
61
|
+
assert_equal Time.parse('2018-03-20T09:14:37+00:00'), payment.paid_at
|
62
|
+
assert_equal 10.00, payment.amount.value
|
63
|
+
assert_equal 'EUR', payment.amount.currency
|
64
|
+
assert_equal 'My first payment', payment.description
|
44
65
|
assert_equal 'ideal', payment.method
|
45
|
-
assert_equal '
|
66
|
+
assert_equal '12345', payment.metadata.order_id
|
46
67
|
assert_equal "Hr E G H K\u00fcppers en\/of MW M.J. K\u00fcppers-Veeneman", payment.details.consumer_name
|
47
68
|
assert_equal 'NL53INGB0618365937', payment.details.consumer_account
|
48
69
|
assert_equal 'INGBNL2A', payment.details.consumer_bic
|
49
|
-
assert_equal '
|
70
|
+
assert_equal 'nl_NL', payment.locale
|
50
71
|
assert_equal 'NL', payment.country_code
|
51
72
|
assert_equal 'pfl_QkEhN94Ba', payment.profile_id
|
52
73
|
assert_equal 'https://webshop.example.org/payments/webhook', payment.webhook_url
|
53
|
-
assert_equal 'https://webshop.example.org/order/
|
54
|
-
assert_equal 'https://
|
55
|
-
assert_equal 'https://webshop.example.org/payment/tr_WDqYK6vllg/settlement', payment.settlement
|
56
|
-
assert_equal 'https://webshop.example.org/payment/tr_WDqYK6vllg/refunds', payment.refunds_url
|
74
|
+
assert_equal 'https://webshop.example.org/order/12345', payment.redirect_url
|
75
|
+
assert_equal 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', payment.checkout_url
|
57
76
|
end
|
58
77
|
|
59
78
|
def test_status_open
|
@@ -61,9 +80,14 @@ module Mollie
|
|
61
80
|
assert !Payment.new(status: 'not-open').open?
|
62
81
|
end
|
63
82
|
|
64
|
-
def
|
65
|
-
assert Payment.new(status: Payment::
|
66
|
-
assert !Payment.new(status: 'not-
|
83
|
+
def test_status_canceled
|
84
|
+
assert Payment.new(status: Payment::STATUS_CANCELED).canceled?
|
85
|
+
assert !Payment.new(status: 'not-canceled').canceled?
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_status_pending
|
89
|
+
assert Payment.new(status: Payment::STATUS_PENDING).pending?
|
90
|
+
assert !Payment.new(status: 'not-pending').pending?
|
67
91
|
end
|
68
92
|
|
69
93
|
def test_status_expired
|
@@ -71,91 +95,253 @@ module Mollie
|
|
71
95
|
assert !Payment.new(status: 'not-expired').expired?
|
72
96
|
end
|
73
97
|
|
74
|
-
def
|
75
|
-
assert Payment.new(status: Payment::
|
76
|
-
assert !Payment.new(status: 'not-
|
98
|
+
def test_status_failed
|
99
|
+
assert Payment.new(status: Payment::STATUS_FAILED).failed?
|
100
|
+
assert !Payment.new(status: 'not-failed').failed?
|
77
101
|
end
|
78
102
|
|
79
|
-
def
|
80
|
-
assert Payment.new(status: Payment::
|
81
|
-
assert !Payment.new(status:
|
103
|
+
def test_status_paid
|
104
|
+
assert Payment.new(status: Payment::STATUS_PAID).paid?
|
105
|
+
assert !Payment.new(status: nil).paid?
|
82
106
|
end
|
83
107
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
108
|
+
def test_create_payment
|
109
|
+
stub_request(:post, "https://api.mollie.com/v2/payments")
|
110
|
+
.with(body: %{{"amount":{"value":1.95,"currency":"EUR"}}})
|
111
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "amount":{ "value" : 1.95, "currency" : "EUR"}}}, :headers => {})
|
112
|
+
|
113
|
+
payment = Payment.create(amount: { value: 1.95, currency: "EUR" })
|
114
|
+
|
115
|
+
assert_kind_of Mollie::Payment, payment
|
116
|
+
assert_equal "my-id", payment.id
|
117
|
+
assert_equal BigDecimal.new("1.95"), payment.amount.value
|
118
|
+
assert_equal 'EUR', payment.amount.currency
|
87
119
|
end
|
88
120
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
121
|
+
def test_create_payment_for_customer
|
122
|
+
stub_request(:post, "https://api.mollie.com/v2/payments")
|
123
|
+
.with(body: %{{"customerId":"cst_8wmqcHMN4U","amount":{"value":1.95,"currency":"EUR"}}})
|
124
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "amount":{ "value" : 1.95, "currency" : "EUR"}, "customerId":"cst_8wmqcHMN4U"}}, :headers => {})
|
125
|
+
|
126
|
+
payment = Payment.create(
|
127
|
+
customer_id: 'cst_8wmqcHMN4U',
|
128
|
+
amount: { value: 1.95, currency: "EUR" }
|
129
|
+
)
|
130
|
+
|
131
|
+
assert_kind_of Mollie::Payment, payment
|
132
|
+
assert_equal "cst_8wmqcHMN4U", payment.customer_id
|
92
133
|
end
|
93
134
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
135
|
+
def test_refund!
|
136
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
|
137
|
+
.to_return(:status => 200, :body => %{
|
138
|
+
{
|
139
|
+
"resource": "payment",
|
140
|
+
"id": "tr_WDqYK6vllg",
|
141
|
+
"amount": {
|
142
|
+
"value": "42.10",
|
143
|
+
"currency": "EUR"
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}, :headers => {})
|
147
|
+
|
148
|
+
stub_request(:post, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds")
|
149
|
+
.to_return(:status => 200, :body => %{
|
150
|
+
{
|
151
|
+
"resource": "refund",
|
152
|
+
"id": "re_4qqhO89gsT"
|
153
|
+
}
|
154
|
+
}, :headers => {})
|
155
|
+
|
156
|
+
payment = Payment.get("tr_WDqYK6vllg")
|
157
|
+
refund = payment.refund!
|
158
|
+
assert_equal "re_4qqhO89gsT", refund.id
|
97
159
|
end
|
98
160
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
161
|
+
def test_refund_with_custom_amount_and_description
|
162
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
|
163
|
+
.to_return(:status => 200, :body => %{
|
164
|
+
{
|
165
|
+
"resource": "payment",
|
166
|
+
"id": "tr_WDqYK6vllg",
|
167
|
+
"amount": {
|
168
|
+
"value": "42.10",
|
169
|
+
"currency": "EUR"
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}, :headers => {})
|
173
|
+
|
174
|
+
stub_request(:post, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds")
|
175
|
+
.with(body: %{{"amount":{"value":"9.95","currency":"EUR"},"description":"Test refund"}})
|
176
|
+
.to_return(:status => 200, :body => %{
|
177
|
+
{
|
178
|
+
"resource": "refund",
|
179
|
+
"id": "re_4qqhO89gsT"
|
180
|
+
}
|
181
|
+
}, :headers => {})
|
182
|
+
|
183
|
+
payment = Payment.get("tr_WDqYK6vllg")
|
184
|
+
refund = payment.refund!(
|
185
|
+
amount: { value: "9.95", currency: "EUR" },
|
186
|
+
description: 'Test refund'
|
187
|
+
)
|
188
|
+
|
189
|
+
assert_equal "re_4qqhO89gsT", refund.id
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_application_fee
|
193
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
|
194
|
+
.to_return(:status => 200, :body => %{
|
195
|
+
{
|
196
|
+
"application_fee": {
|
197
|
+
"amount": {
|
198
|
+
"value": "42.10",
|
199
|
+
"currency": "EUR"
|
200
|
+
},
|
201
|
+
"description": "Example application fee"
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}, :headers => {})
|
205
|
+
|
206
|
+
payment = Payment.get("tr_WDqYK6vllg")
|
207
|
+
assert_equal 42.10, payment.application_fee.amount.value
|
208
|
+
assert_equal "EUR", payment.application_fee.amount.currency
|
102
209
|
end
|
103
210
|
|
104
211
|
def test_list_refunds
|
105
|
-
stub_request(:get, "https://api.mollie.
|
106
|
-
.to_return(:status => 200, :body => %{{"
|
212
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/pay-id/refunds")
|
213
|
+
.to_return(:status => 200, :body => %{{"_embedded" : {"refunds" : [{"id":"ref-id", "payment_id":"pay-id"}]}}}, :headers => {})
|
107
214
|
|
108
|
-
refunds = Payment.new(id: "pay-id").refunds
|
215
|
+
refunds = Payment.new(id: "pay-id").refunds
|
109
216
|
|
110
217
|
assert_equal "ref-id", refunds.first.id
|
111
218
|
end
|
112
219
|
|
113
|
-
def
|
114
|
-
stub_request(:
|
115
|
-
.
|
116
|
-
|
220
|
+
def test_list_chargebacks
|
221
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/pay-id/chargebacks")
|
222
|
+
.to_return(:status => 200, :body => %{{"_embedded" : {"chargebacks" :[{"id":"chb-id", "payment_id":"pay-id"}]}}}, :headers => {})
|
223
|
+
|
224
|
+
chargebacks = Payment.new(id: "pay-id").chargebacks
|
225
|
+
assert_equal "chb-id", chargebacks.first.id
|
226
|
+
end
|
117
227
|
|
118
|
-
|
228
|
+
def test_get_settlement
|
229
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
|
230
|
+
.to_return(:status => 200, :body => %{
|
231
|
+
{
|
232
|
+
"resource": "payment",
|
233
|
+
"id": "tr_WDqYK6vllg",
|
234
|
+
"settlement_id": "stl_jDk30akdN"
|
235
|
+
}
|
236
|
+
}, :headers => {})
|
119
237
|
|
120
|
-
|
121
|
-
|
238
|
+
stub_request(:get, "https://api.mollie.com/v2/settlements/stl_jDk30akdN")
|
239
|
+
.to_return(:status => 200, :body => %{
|
240
|
+
{
|
241
|
+
"resource": "settlement",
|
242
|
+
"id": "stl_jDk30akdN"
|
243
|
+
}
|
244
|
+
}, :headers => {})
|
245
|
+
|
246
|
+
payment = Payment.get("tr_WDqYK6vllg")
|
247
|
+
settlement = payment.settlement
|
248
|
+
assert_equal "stl_jDk30akdN", settlement.id
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_nil_settlement
|
252
|
+
payment = Payment.new(id: "tr_WDqYK6vllg")
|
253
|
+
assert payment.settlement.nil?
|
122
254
|
end
|
123
255
|
|
124
|
-
def
|
125
|
-
stub_request(:
|
126
|
-
.to_return(:status =>
|
256
|
+
def test_get_mandate
|
257
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
|
258
|
+
.to_return(:status => 200, :body => %{
|
259
|
+
{
|
260
|
+
"resource": "payment",
|
261
|
+
"id": "tr_WDqYK6vllg",
|
262
|
+
"mandate_id": "mdt_h3gAaD5zP"
|
263
|
+
}
|
264
|
+
}, :headers => {})
|
265
|
+
|
266
|
+
stub_request(:get, "https://api.mollie.com/v2/mandates/mdt_h3gAaD5zP")
|
267
|
+
.to_return(:status => 200, :body => %{
|
268
|
+
{
|
269
|
+
"resource": "mandate",
|
270
|
+
"id": "mdt_h3gAaD5zP"
|
271
|
+
}
|
272
|
+
}, :headers => {})
|
273
|
+
|
274
|
+
payment = Payment.get("tr_WDqYK6vllg")
|
275
|
+
mandate = payment.mandate
|
276
|
+
assert_equal "mdt_h3gAaD5zP", mandate.id
|
277
|
+
end
|
127
278
|
|
128
|
-
|
129
|
-
|
279
|
+
def test_nil_mandate
|
280
|
+
payment = Payment.new(id: "tr_WDqYK6vllg")
|
281
|
+
assert payment.mandate.nil?
|
130
282
|
end
|
131
283
|
|
132
|
-
def
|
133
|
-
stub_request(:get, "https://api.mollie.
|
134
|
-
.to_return(:status => 200, :body => %{
|
284
|
+
def test_get_subscription
|
285
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
|
286
|
+
.to_return(:status => 200, :body => %{
|
287
|
+
{
|
288
|
+
"resource": "payment",
|
289
|
+
"id": "tr_WDqYK6vllg",
|
290
|
+
"subscription_id": "sub_rVKGtNd6s3",
|
291
|
+
"customer_id": "cst_8wmqcHMN4U"
|
292
|
+
}
|
293
|
+
}, :headers => {})
|
135
294
|
|
136
|
-
|
295
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_rVKGtNd6s3")
|
296
|
+
.to_return(:status => 200, :body => %{
|
297
|
+
{
|
298
|
+
"resource": "subscription",
|
299
|
+
"id": "sub_rVKGtNd6s3"
|
300
|
+
}
|
301
|
+
}, :headers => {})
|
137
302
|
|
138
|
-
|
139
|
-
|
303
|
+
payment = Payment.get("tr_WDqYK6vllg")
|
304
|
+
subscription = payment.subscription
|
305
|
+
assert_equal "sub_rVKGtNd6s3", subscription.id
|
140
306
|
end
|
141
307
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
308
|
+
def test_nil_subscription
|
309
|
+
payment = Payment.new(id: "tr_WDqYK6vllg")
|
310
|
+
assert payment.subscription.nil?
|
145
311
|
|
146
|
-
|
312
|
+
payment = Payment.new(id: "tr_WDqYK6vllg", customer_id: "cst_8wmqcHMN4U")
|
313
|
+
assert payment.subscription.nil?
|
147
314
|
|
148
|
-
|
315
|
+
payment = Payment.new(id: "tr_WDqYK6vllg", subscription_id: "sub_rVKGtNd6s3")
|
316
|
+
assert payment.subscription.nil?
|
149
317
|
end
|
150
318
|
|
151
|
-
def
|
152
|
-
stub_request(:get, "https://api.mollie.
|
153
|
-
.to_return(:status => 200, :body => %{
|
319
|
+
def test_get_customer
|
320
|
+
stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
|
321
|
+
.to_return(:status => 200, :body => %{
|
322
|
+
{
|
323
|
+
"resource": "payment",
|
324
|
+
"id": "tr_WDqYK6vllg",
|
325
|
+
"customer_id": "cst_8wmqcHMN4U"
|
326
|
+
}
|
327
|
+
}, :headers => {})
|
154
328
|
|
155
|
-
|
329
|
+
stub_request(:get, "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U")
|
330
|
+
.to_return(:status => 200, :body => %{
|
331
|
+
{
|
332
|
+
"resource": "customer",
|
333
|
+
"id": "cst_8wmqcHMN4U"
|
334
|
+
}
|
335
|
+
}, :headers => {})
|
336
|
+
|
337
|
+
payment = Payment.get("tr_WDqYK6vllg")
|
338
|
+
customer = payment.customer
|
339
|
+
assert_equal "cst_8wmqcHMN4U", customer.id
|
340
|
+
end
|
156
341
|
|
157
|
-
|
158
|
-
|
342
|
+
def test_nil_customer
|
343
|
+
payment = Payment.new(id: "tr_WDqYK6vllg")
|
344
|
+
assert payment.customer.nil?
|
159
345
|
end
|
160
346
|
end
|
161
347
|
end
|