mollie-api-ruby 4.13.0 → 4.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +1 -1
  3. data/CHANGELOG.md +13 -1
  4. data/README.md +4 -4
  5. data/examples/balances/get-primary.rb +1 -0
  6. data/examples/balances/get-report.rb +2 -0
  7. data/examples/balances/get.rb +1 -0
  8. data/examples/balances/list-transactions.rb +2 -0
  9. data/examples/balances/list.rb +1 -0
  10. data/examples/connect/authorize.rb +1 -1
  11. data/examples/connect/tokens.rb +1 -1
  12. data/examples/payment-links/create.rb +5 -0
  13. data/examples/payment-links/delete.rb +1 -0
  14. data/examples/payment-links/get.rb +1 -0
  15. data/examples/payment-links/list-payments.rb +2 -0
  16. data/examples/payment-links/list.rb +1 -0
  17. data/examples/payment-links/update.rb +5 -0
  18. data/lib/mollie/balance/report.rb +25 -0
  19. data/lib/mollie/balance/transaction.rb +41 -0
  20. data/lib/mollie/balance.rb +53 -0
  21. data/lib/mollie/base.rb +2 -0
  22. data/lib/mollie/list.rb +1 -1
  23. data/lib/mollie/method.rb +12 -0
  24. data/lib/mollie/payment_link.rb +70 -0
  25. data/lib/mollie/version.rb +1 -1
  26. data/lib/mollie.rb +4 -0
  27. data/mollie-api-ruby.gemspec +8 -1
  28. data/test/fixtures/balances/get.json +38 -0
  29. data/test/fixtures/balances/list.json +34 -0
  30. data/test/fixtures/balances/list_transactions.json +65 -0
  31. data/test/fixtures/balances/report.json +149 -0
  32. data/test/fixtures/payment_links/create.json +7 -0
  33. data/test/fixtures/payment_links/get.json +32 -0
  34. data/test/fixtures/payment_links/list-payments.json +31 -0
  35. data/test/fixtures/payment_links/list.json +31 -0
  36. data/test/fixtures/payment_links/update.json +4 -0
  37. data/test/mollie/balance/transaction_test.rb +36 -0
  38. data/test/mollie/balance_test.rb +108 -0
  39. data/test/mollie/payment_link_test.rb +100 -0
  40. metadata +79 -6
  41. data/.travis.yml +0 -15
@@ -0,0 +1,149 @@
1
+ {
2
+ "resource": "balance-report",
3
+ "balanceId": "bal_gVMhHKqSSRYJyPsuoPNFH",
4
+ "timeZone": "Europe/Amsterdam",
5
+ "from": "2024-01-01",
6
+ "until": "2024-01-31",
7
+ "grouping": "transaction-categories",
8
+ "totals": {
9
+ "open": {
10
+ "available": {
11
+ "amount": {
12
+ "currency": "EUR",
13
+ "value": "0.00"
14
+ }
15
+ },
16
+ "pending": {
17
+ "amount": {
18
+ "currency": "EUR",
19
+ "value": "0.00"
20
+ }
21
+ }
22
+ },
23
+ "payments": {
24
+ "immediatelyAvailable": {
25
+ "amount": {
26
+ "currency": "EUR",
27
+ "value": "0.00"
28
+ }
29
+ },
30
+ "pending": {
31
+ "amount": {
32
+ "currency": "EUR",
33
+ "value": "4.98"
34
+ },
35
+ "subtotals": [
36
+ {
37
+ "transactionType": "payment",
38
+ "count": 1,
39
+ "amount": {
40
+ "currency": "EUR",
41
+ "value": "4.98"
42
+ },
43
+ "subtotals": [
44
+ {
45
+ "method": "ideal",
46
+ "count": 1,
47
+ "amount": {
48
+ "currency": "EUR",
49
+ "value": "4.98"
50
+ }
51
+ }
52
+ ]
53
+ }
54
+ ]
55
+ },
56
+ "movedToAvailable": {
57
+ "amount": {
58
+ "currency": "EUR",
59
+ "value": "0.00"
60
+ }
61
+ }
62
+ },
63
+ "refunds": {},
64
+ "capital": {},
65
+ "chargebacks": {},
66
+ "transfers": {},
67
+ "fee-prepayments": {
68
+ "immediatelyAvailable": {
69
+ "amount": {
70
+ "currency": "EUR",
71
+ "value": "0.00"
72
+ }
73
+ },
74
+ "movedToAvailable": {
75
+ "amount": {
76
+ "currency": "EUR",
77
+ "value": "-0.36"
78
+ },
79
+ "subtotals": [
80
+ {
81
+ "prepaymentPartType": "fee",
82
+ "count": 1,
83
+ "amount": {
84
+ "currency": "EUR",
85
+ "value": "-0.29"
86
+ },
87
+ "subtotals": [
88
+ {
89
+ "feeType": "payment-fee",
90
+ "method": "ideal",
91
+ "count": 1,
92
+ "amount": {
93
+ "currency": "EUR",
94
+ "value": "-0.29"
95
+ }
96
+ }
97
+ ]
98
+ },
99
+ {
100
+ "prepaymentPartType": "fee-vat",
101
+ "amount": {
102
+ "currency": "EUR",
103
+ "value": "-0.0609"
104
+ }
105
+ },
106
+ {
107
+ "prepaymentPartType": "fee-rounding-compensation",
108
+ "amount": {
109
+ "currency": "EUR",
110
+ "value": "-0.0091"
111
+ }
112
+ }
113
+ ]
114
+ },
115
+ "pending": {
116
+ "amount": {
117
+ "currency": "EUR",
118
+ "value": "-0.36"
119
+ },
120
+ "subtotals": []
121
+ }
122
+ },
123
+ "corrections": {},
124
+ "close": {
125
+ "available": {
126
+ "amount": {
127
+ "currency": "EUR",
128
+ "value": "0.00"
129
+ }
130
+ },
131
+ "pending": {
132
+ "amount": {
133
+ "currency": "EUR",
134
+ "value": "4.32"
135
+ }
136
+ }
137
+ }
138
+ },
139
+ "_links": {
140
+ "self": {
141
+ "href": "...",
142
+ "type": "application/hal+json"
143
+ },
144
+ "documentation": {
145
+ "href": "...",
146
+ "type": "text/html"
147
+ }
148
+ }
149
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "description": "Bicycle tires",
3
+ "amount": {
4
+ "currency": "EUR",
5
+ "value": "24.95"
6
+ }
7
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "resource": "payment-link",
3
+ "id": "pl_4Y0eZitmBnQ6IDoMqZQKh",
4
+ "mode": "test",
5
+ "description": "Bicycle tires",
6
+ "archived": false,
7
+ "profile_id": "pfl_QkEhN94Ba",
8
+ "amount": {
9
+ "currency": "EUR",
10
+ "value": "24.95"
11
+ },
12
+ "webhook_url": "https://webshop.example.org/payment-links/webhook",
13
+ "redirect_url": "https://webshop.example.org/thanks",
14
+ "created_at": "2024-09-24T12:16:44+00:00",
15
+ "paid_at": null,
16
+ "updated_at": null,
17
+ "expires_at": null,
18
+ "_links": {
19
+ "self": {
20
+ "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh",
21
+ "type": "application/hal+json"
22
+ },
23
+ "paymentLink": {
24
+ "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh",
25
+ "type": "text/html"
26
+ },
27
+ "documentation": {
28
+ "href": "https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link",
29
+ "type": "text/html"
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "count": 3,
3
+ "_embedded": {
4
+ "payments": [
5
+ {
6
+ "resource": "payment",
7
+ "id": "tr_one"
8
+ },
9
+ {
10
+ "resource": "payment",
11
+ "id": "tr_two"
12
+ },
13
+ {
14
+ "resource": "payment",
15
+ "id": "tr_three"
16
+ }
17
+ ]
18
+ },
19
+ "_links": {
20
+ "self": {
21
+ "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments?limit=50",
22
+ "type": "application/hal+json"
23
+ },
24
+ "previous": null,
25
+ "next": null,
26
+ "documentation": {
27
+ "href": "https://docs.mollie.com/reference/get-payment-link-payments",
28
+ "type": "text/html"
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "count": 3,
3
+ "_embedded": {
4
+ "payment_links": [
5
+ {
6
+ "resource": "payment-link",
7
+ "id": "pl_one"
8
+ },
9
+ {
10
+ "resource": "payment-link",
11
+ "id": "pl_two"
12
+ },
13
+ {
14
+ "resource": "payment-link",
15
+ "id": "pl_three"
16
+ }
17
+ ]
18
+ },
19
+ "_links": {
20
+ "self": {
21
+ "href": "https://api.mollie.com/v2/payment-links?limit=50",
22
+ "type": "application/hal+json"
23
+ },
24
+ "previous": null,
25
+ "next": null,
26
+ "documentation": {
27
+ "href": "https://docs.mollie.com/reference/v2/payment-links-api/list-payment-links",
28
+ "type": "text/html"
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "description": "Car tires",
3
+ "archived": true
4
+ }
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class Balance
5
+ class TransactionTest < Test::Unit::TestCase
6
+ def test_setting_attributes
7
+ attributes = {
8
+ id: "baltr_QM24QwzUWR4ev4Xfgyt29A",
9
+ type: "refund",
10
+ result_amount: { "value" => "-10.25", "currency" => "EUR" },
11
+ initial_amount: { "value" => "-10.00", "currency" => "EUR" },
12
+ deductions: { "value" => "0.25", "currency" => "EUR" },
13
+ context: {
14
+ "paymentId" => "tr_7UhSN1zuXS",
15
+ "refundId" => "re_4qqhO89gsT"
16
+ },
17
+ created_at: "2021-01-10T12:06:28+00:00"
18
+ }
19
+
20
+ balance = Balance::Transaction.new(attributes)
21
+
22
+ assert_equal "baltr_QM24QwzUWR4ev4Xfgyt29A", balance.id
23
+ assert_equal "refund", balance.type
24
+ assert_equal BigDecimal("-10.25"), balance.result_amount.value
25
+ assert_equal "EUR", balance.result_amount.currency
26
+ assert_equal BigDecimal("-10.00"), balance.initial_amount.value
27
+ assert_equal "EUR", balance.initial_amount.currency
28
+ assert_equal BigDecimal("0.25"), balance.deductions.value
29
+ assert_equal "EUR", balance.deductions.currency
30
+ assert_equal "tr_7UhSN1zuXS", balance.context.paymentId
31
+ assert_equal "re_4qqhO89gsT", balance.context.refundId
32
+ assert_equal Time.parse("2021-01-10T12:06:28+00:00"), balance.created_at
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,108 @@
1
+ require "helper"
2
+
3
+ module Mollie
4
+ class BalanceTest < Test::Unit::TestCase
5
+ GET_BALANCE = read_fixture('balances/get.json')
6
+ GET_BALANCE_REPORT = read_fixture('balances/report.json')
7
+ LIST_BALANCES = read_fixture('balances/list.json')
8
+ LIST_BALANCE_TRANSACTIONS = read_fixture('balances/list_transactions.json')
9
+
10
+ def test_setting_attributes
11
+ attributes = {
12
+ id: "bal_gVMhHKqSSRYJyPsuoPNFH",
13
+ mode: "live",
14
+ currency: "EUR",
15
+ description: "Primary balance",
16
+ available_amount: { "value" => "0.00", "currency" => "EUR" },
17
+ pending_amount: { "value" => "0.00", "currency" => "EUR" },
18
+ transfer_frequency: "twice-a-month",
19
+ transfer_threshold: { "value" => "5.00", "currency" => "EUR" },
20
+ transfer_reference: "Mollie settlement",
21
+ transfer_destination: {
22
+ type: "bank-account",
23
+ beneficiary_name: "John Doe",
24
+ bank_account: "NL55INGB0000000000"
25
+ },
26
+ status: "active",
27
+ created_at: "2018-03-20T09:13:37+00:00",
28
+ }
29
+
30
+ balance = Mollie::Balance.new(attributes)
31
+
32
+ assert_equal "bal_gVMhHKqSSRYJyPsuoPNFH", balance.id
33
+ assert_equal "live", balance.mode
34
+ assert_equal "EUR", balance.currency
35
+ assert_equal "Primary balance", balance.description
36
+ assert_equal BigDecimal("0.00"), balance.available_amount.value
37
+ assert_equal "EUR", balance.available_amount.currency
38
+ assert_equal BigDecimal("0.00"), balance.pending_amount.value
39
+ assert_equal "EUR", balance.pending_amount.currency
40
+ assert_equal "twice-a-month", balance.transfer_frequency
41
+ assert_equal BigDecimal("5.00"), balance.transfer_threshold.value
42
+ assert_equal "EUR", balance.transfer_threshold.currency
43
+ assert_equal "Mollie settlement", balance.transfer_reference
44
+ assert_equal "bank-account", balance.transfer_destination.type
45
+ assert_equal "John Doe", balance.transfer_destination.beneficiary_name
46
+ assert_equal "NL55INGB0000000000", balance.transfer_destination.bank_account
47
+ assert_equal "active", balance.status
48
+ assert_equal Time.parse('2018-03-20T09:13:37+00:00'), balance.created_at
49
+ end
50
+
51
+ def test_get_balance
52
+ stub_request(:get, "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH")
53
+ .to_return(status: 200, body: GET_BALANCE, headers: {})
54
+
55
+ balance = Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH")
56
+ assert_equal "bal_gVMhHKqSSRYJyPsuoPNFH", balance.id
57
+ end
58
+
59
+ def test_list_balances
60
+ stub_request(:get, 'https://api.mollie.com/v2/balances')
61
+ .to_return(status: 200, body: LIST_BALANCES, headers: {})
62
+
63
+ balances = Balance.all
64
+ assert_equal 3, balances.size
65
+ assert_equal 'bal_one', balances[0].id
66
+ assert_equal 'bal_two', balances[1].id
67
+ assert_equal 'bal_three', balances[2].id
68
+ end
69
+
70
+ def test_primary
71
+ stub_request(:get, "https://api.mollie.com/v2/balances/primary")
72
+ .to_return(status: 200, body: GET_BALANCE, headers: {})
73
+
74
+ balance = Balance.primary
75
+ assert_equal "bal_gVMhHKqSSRYJyPsuoPNFH", balance.id
76
+ end
77
+
78
+ def test_report
79
+ stub_request(:get, "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH")
80
+ .to_return(status: 200, body: GET_BALANCE, headers: {})
81
+
82
+ stub_request(:get, 'https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/report')
83
+ .to_return(status: 200, body: GET_BALANCE_REPORT, headers: {})
84
+
85
+ report = Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH").report
86
+
87
+ assert_equal Date.parse("2024-01-01"), report.from
88
+ assert_equal Date.parse("2024-01-31"), report.until
89
+ assert_equal "transaction-categories", report.grouping
90
+ assert_equal "4.98", report.totals.dig("payments", "pending", "amount", "value")
91
+ assert_equal "-0.36", report.totals.dig("fee_prepayments", "moved_to_available", "amount", "value")
92
+ end
93
+
94
+ def test_list_transactions
95
+ stub_request(:get, "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH")
96
+ .to_return(status: 200, body: GET_BALANCE, headers: {})
97
+
98
+ stub_request(:get, 'https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions')
99
+ .to_return(status: 200, body: LIST_BALANCE_TRANSACTIONS, headers: {})
100
+
101
+ transactions = Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH").transactions
102
+ assert_equal 2, transactions.size
103
+
104
+ assert_equal "baltr_QM24QwzUWR4ev4Xfgyt29A", transactions[0].id
105
+ assert_equal "baltr_WhmDwNYR87FPDbiwBhUXCh", transactions[1].id
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,100 @@
1
+ require "helper"
2
+
3
+ module Mollie
4
+ class PaymentLinkTest < Test::Unit::TestCase
5
+ CREATE_PAYMENT_LINK = read_fixture("payment_links/create.json")
6
+ GET_PAYMENT_LINK = read_fixture("payment_links/get.json")
7
+ UPDATE_PAYMENT_LINK = read_fixture("payment_links/update.json")
8
+ LIST_PAYMENT_LINKS = read_fixture("payment_links/list.json")
9
+ LIST_PAYMENT_LINK_PAYMENTS = read_fixture("payment_links/list-payments.json")
10
+
11
+ def test_archived?
12
+ assert PaymentLink.new(archived: true).archived?
13
+ assert_false PaymentLink.new(archived: false).archived?
14
+ end
15
+
16
+ def test_create_payment
17
+ minified_body = JSON.parse(CREATE_PAYMENT_LINK).to_json
18
+ stub_request(:post, "https://api.mollie.com/v2/payment-links")
19
+ .with(body: minified_body)
20
+ .to_return(status: 201, body: GET_PAYMENT_LINK, headers: {})
21
+
22
+ payment_link = PaymentLink.create(
23
+ description: "Bicycle tires",
24
+ amount: {currency: "EUR", value: "24.95"}
25
+ )
26
+
27
+ assert_kind_of PaymentLink, payment_link
28
+ assert_equal "pl_4Y0eZitmBnQ6IDoMqZQKh", payment_link.id
29
+ end
30
+
31
+ def test_get_payment_link
32
+ stub_request(:get, "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh")
33
+ .to_return(status: 200, body: GET_PAYMENT_LINK, headers: {})
34
+
35
+ payment_link = PaymentLink.get("pl_4Y0eZitmBnQ6IDoMqZQKh")
36
+
37
+ assert_equal "pl_4Y0eZitmBnQ6IDoMqZQKh", payment_link.id
38
+ assert_equal "test", payment_link.mode
39
+ assert_equal "Bicycle tires", payment_link.description
40
+ assert_false payment_link.archived
41
+ assert_equal "pfl_QkEhN94Ba", payment_link.profile_id
42
+ assert_equal 24.95, payment_link.amount.value
43
+ assert_equal "EUR", payment_link.amount.currency
44
+ assert_equal "https://webshop.example.org/payment-links/webhook", payment_link.webhook_url
45
+ assert_equal "https://webshop.example.org/thanks", payment_link.redirect_url
46
+ assert_equal Time.parse("2024-09-24T12:16:44+00:00"), payment_link.created_at
47
+ assert_equal "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", payment_link.payment_link
48
+ assert_nil payment_link.paid_at
49
+ assert_nil payment_link.updated_at
50
+ assert_nil payment_link.expires_at
51
+ end
52
+
53
+ def test_update_payment_link
54
+ minified_body = JSON.parse(UPDATE_PAYMENT_LINK).to_json
55
+ stub_request(:patch, 'https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh')
56
+ .with(body: minified_body)
57
+ .to_return(status: 200, body: GET_PAYMENT_LINK, headers: {})
58
+
59
+ payment_link = PaymentLink.update("pl_4Y0eZitmBnQ6IDoMqZQKh", JSON.parse(UPDATE_PAYMENT_LINK))
60
+
61
+ assert_kind_of PaymentLink, payment_link
62
+ assert_equal "pl_4Y0eZitmBnQ6IDoMqZQKh", payment_link.id
63
+ end
64
+
65
+ def test_delete_payment_link
66
+ stub_request(:delete, 'https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh')
67
+ .to_return(status: 204, body: GET_PAYMENT_LINK, headers: {})
68
+
69
+ payment_link = PaymentLink.delete("pl_4Y0eZitmBnQ6IDoMqZQKh")
70
+ assert_nil payment_link
71
+ end
72
+
73
+ def test_list_payment_links
74
+ stub_request(:get, "https://api.mollie.com/v2/payment-links")
75
+ .to_return(status: 200, body: LIST_PAYMENT_LINKS, headers: {})
76
+
77
+ payment_links = PaymentLink.all
78
+ assert_equal 3, payment_links.size
79
+ assert_equal "pl_one", payment_links[0].id
80
+ assert_equal "pl_two", payment_links[1].id
81
+ assert_equal "pl_three", payment_links[2].id
82
+ end
83
+
84
+ def test_list_payment_link_payments
85
+ stub_request(:get, "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh")
86
+ .to_return(status: 200, body: GET_PAYMENT_LINK, headers: {})
87
+
88
+ stub_request(:get, "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments")
89
+ .to_return(status: 200, body: LIST_PAYMENT_LINK_PAYMENTS, headers: {})
90
+
91
+ payment_link = PaymentLink.get("pl_4Y0eZitmBnQ6IDoMqZQKh")
92
+ payments = payment_link.payments
93
+
94
+ assert_equal 3, payments.size
95
+ assert_equal "tr_one", payments[0].id
96
+ assert_equal "tr_two", payments[1].id
97
+ assert_equal "tr_three", payments[2].id
98
+ end
99
+ end
100
+ end