Skip to content

Commit 1f0b1d2

Browse files
authored
Merge pull request #183 from MathijsK93/payment-embedded-refunds
2 parents 4cd4e40 + ed1916e commit 1f0b1d2

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

lib/mollie/payment.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,13 @@ def refund!(options = {})
197197
end
198198

199199
def refunds(options = {})
200-
Payment::Refund.all(options.merge(payment_id: id))
200+
resources = (attributes['_embedded']['refunds'] if attributes['_embedded'])
201+
202+
if resources.nil?
203+
Payment::Refund.all(options.merge(payment_id: id))
204+
else
205+
List.new({ '_embedded' => { 'refunds' => resources } }, Payment::Refund)
206+
end
201207
end
202208

203209
def chargebacks(options = {})
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"resource": "payment",
3+
"id": "tr_WDqYK6vllg",
4+
"mode": "test",
5+
"createdAt": "2018-03-20T13:13:37+00:00",
6+
"amount": {
7+
"value": "10.00",
8+
"currency": "EUR"
9+
},
10+
"description": "Order #12345",
11+
"method": null,
12+
"metadata": {
13+
"order_id": "12345"
14+
},
15+
"status": "open",
16+
"isCancelable": false,
17+
"locale": "nl_NL",
18+
"restrictPaymentMethodsToCountry": "NL",
19+
"expiresAt": "2018-03-20T13:28:37+00:00",
20+
"details": null,
21+
"profileId": "pfl_QkEhN94Ba",
22+
"sequenceType": "oneoff",
23+
"redirectUrl": "https://webshop.example.org/order/12345/",
24+
"webhookUrl": "https://webshop.example.org/payments/webhook/",
25+
"_embedded": {
26+
"refunds": [
27+
{
28+
"resource": "refund",
29+
"id": "re_vD3Jm32wQt",
30+
"amount": {
31+
"value": "329.99",
32+
"currency": "EUR"
33+
},
34+
"status": "pending",
35+
"createdAt": "2019-01-15T15:41:21+00:00",
36+
"description": "Required quantity not in stock, refunding one photo book.",
37+
"orderId": "ord_kEn1PlbGa",
38+
"paymentId": "tr_WDqYK6vllg",
39+
"settlementAmount": {
40+
"value": "-329.99",
41+
"currency": "EUR"
42+
},
43+
"_links": {
44+
"self": {
45+
"href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_vD3Jm32wQt",
46+
"type": "application/hal+json"
47+
},
48+
"payment": {
49+
"href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
50+
"type": "application/hal+json"
51+
},
52+
"order": {
53+
"href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa",
54+
"type": "application/hal+json"
55+
}
56+
}
57+
}
58+
]
59+
},
60+
"_links": {
61+
"self": {
62+
"href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
63+
"type": "application/hal+json"
64+
},
65+
"checkout": {
66+
"href": "https://www.mollie.com/payscreen/select-method/WDqYK6vllg",
67+
"type": "text/html"
68+
},
69+
"documentation": {
70+
"href": "https://docs.mollie.com/reference/v2/payments-api/get-payment",
71+
"type": "text/html"
72+
}
73+
}
74+
}

test/mollie/payment_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module Mollie
44
class PaymentTest < Test::Unit::TestCase
5+
GET_PAYMENT_WITH_EMBEDDED_RESOURCES = read_fixture('payments/get_embedded_resources.json')
6+
57
def test_setting_attributes
68
attributes = {
79
resource: 'payment',
@@ -233,6 +235,16 @@ def test_restrict_payment_methods_to_country
233235
assert_equal 'NL', payment.restrict_payment_methods_to_country
234236
end
235237

238+
def test_embedded_refunds
239+
stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg')
240+
.to_return(status: 200, body: GET_PAYMENT_WITH_EMBEDDED_RESOURCES, headers: {})
241+
242+
payment = Payment.get('tr_WDqYK6vllg')
243+
244+
assert_equal 're_vD3Jm32wQt', payment.refunds.first.id
245+
assert_equal 1, payment.refunds.size
246+
end
247+
236248
def test_list_refunds
237249
stub_request(:get, 'https://api.mollie.com/v2/payments/pay-id/refunds')
238250
.to_return(status: 200, body: %({"_embedded" : {"refunds" : [{"id":"ref-id", "payment_id":"pay-id"}]}}), headers: {})

0 commit comments

Comments
 (0)