1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"encoding/json" |
5
|
|
|
"fmt" |
6
|
|
|
"net/http" |
7
|
|
|
"time" |
8
|
|
|
|
9
|
|
|
"github.com/google/go-querystring/query" |
10
|
|
|
) |
11
|
|
|
|
12
|
|
|
// Orders explain the items that customers need to pay for. |
13
|
|
|
type Orders struct { |
14
|
|
|
Resource string `json:"resource,omitempty"` |
15
|
|
|
ID string `json:"id,omitempty"` |
16
|
|
|
ProfileID string `json:"profileId,omitempty"` |
17
|
|
|
Method *PaymentMethod `json:"method,omitempty"` |
18
|
|
|
Mode *Mode `json:"mode,omitempty"` |
19
|
|
|
Amount *Amount `json:"amount,omitempty"` |
20
|
|
|
AmountCaptured *Amount `json:"amountCaptured,omitempty"` |
21
|
|
|
AmountRefunded *Amount `json:"amountRefunded,omitempty"` |
22
|
|
|
Status *OrderStatus `json:"status,omitempty"` |
23
|
|
|
IsCancelable bool `json:"isCancelable,omitempty"` |
24
|
|
|
BillingAddress *OrderAddress `json:"billingAddress,omitempty"` |
25
|
|
|
ConsumerDateOfBirth *ShortDate `json:"consumerDateOfBirth,omitempty"` |
26
|
|
|
OrderNumber string `json:"orderNumber,omitempty"` |
27
|
|
|
ShippingAddress *OrderAddress `json:"shippingAddress,omitempty"` |
28
|
|
|
Locale *Locale `json:"locale,omitempty"` |
29
|
|
|
Metadata interface{} `json:"metadata,omitempty"` |
30
|
|
|
RedirectURL string `json:"redirectUrl,omitempty"` |
31
|
|
|
Lines []*OrderLines `json:"lines,omitempty"` |
32
|
|
|
WebhookURL string `json:"webhookUrl,omitempty"` |
33
|
|
|
CreatedAt *time.Time `json:"createdAt,omitempty"` |
34
|
|
|
ExpiresAt *time.Time `json:"expiresAt,omitempty"` |
35
|
|
|
ExpiredAt *time.Time `json:"expiredAt,omitempty"` |
36
|
|
|
PaidAt *time.Time `json:"paidAt,omitempty"` |
37
|
|
|
AuthorizedAt *time.Time `json:"authorizedAt,omitempty"` |
38
|
|
|
CanceledAt *time.Time `json:"canceledAt,omitempty"` |
39
|
|
|
CompletedAt *time.Time `json:"completedAt,omitempty"` |
40
|
|
|
Embedded struct { |
41
|
|
|
Payments []Payment `json:"payments,omitempty"` |
42
|
|
|
Refunds []Refund `json:"refunds,omitempty"` |
43
|
|
|
} `json:"_embedded,omitempty"` |
44
|
|
|
Links *OrderLinks `json:"_links,omitempty"` |
45
|
|
|
OrderPayment *OrderPayment `json:"payment,omitempty"` |
46
|
|
|
Description string `json:"description,omitempty"` |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// OrderPayment describes payment specific parameters that can be passed during order creation |
50
|
|
|
type OrderPayment struct { |
51
|
|
|
ConsumerAccount string `json:"consumerAccount,omitempty"` |
52
|
|
|
CustomerID string `json:"customerId,omitempty"` |
53
|
|
|
CustomerReference string `json:"customerReference,omitempty"` |
54
|
|
|
Issuer string `json:"issuer,omitempty"` |
55
|
|
|
MandateID string `json:"mandateId,omitempty"` |
56
|
|
|
SequenceType *SequenceType `json:"sequenceType,omitempty"` |
57
|
|
|
VoucherNumber string `json:"voucherNumber,omitempty"` |
58
|
|
|
VoucherPin string `json:"voucherPin,omitempty"` |
59
|
|
|
WebhookURL string `json:"webhookUrl,omitempty"` |
60
|
|
|
ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"` |
61
|
|
|
Method *PaymentMethod `json:"method,omitempty"` |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// OrderStatus describes the valid order status. |
65
|
|
|
type OrderStatus string |
66
|
|
|
|
67
|
|
|
// Valid order status. |
68
|
|
|
const ( |
69
|
|
|
Created OrderStatus = "created" |
70
|
|
|
Paid OrderStatus = "paid" |
71
|
|
|
Authorized OrderStatus = "authorized" |
72
|
|
|
Canceled OrderStatus = "canceled" |
73
|
|
|
Shipping OrderStatus = "shipping" |
74
|
|
|
Completed OrderStatus = "completed" |
75
|
|
|
Expired OrderStatus = "expired" |
76
|
|
|
) |
77
|
|
|
|
78
|
|
|
// OrderAddress identify both the address and the person the order is billed or shipped to. |
79
|
|
|
type OrderAddress struct { |
80
|
|
|
OrganizationName string `json:"organizationName,omitempty"` |
81
|
|
|
Title string `json:"title,omitempty"` |
82
|
|
|
GivenName string `json:"givenName,omitempty"` |
83
|
|
|
FamilyName string `json:"familyName,omitempty"` |
84
|
|
|
Email string `json:"email,omitempty"` |
85
|
|
|
Phone *PhoneNumber `json:"phone,omitempty"` |
86
|
|
|
StreetAndNumber string `json:"streetAndNumber,omitempty"` |
87
|
|
|
StreetAdditional string `json:"streetAdditional,omitempty"` |
88
|
|
|
PostalCode string `json:"postalCode,omitempty"` |
89
|
|
|
City string `json:"city,omitempty"` |
90
|
|
|
Region string `json:"region,omitempty"` |
91
|
|
|
Country string `json:"country,omitempty"` |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// OrderLinks describes an object with several URL objects |
95
|
|
|
// relevant to the order. |
96
|
|
|
// Every URL object will contain an href and a type field. |
97
|
|
|
type OrderLinks struct { |
98
|
|
|
Self *URL `json:"self,omitempty"` |
99
|
|
|
Checkout *URL `json:"checkout,omitempty"` |
100
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
// OrderListLinks describes an object with several URL objects |
104
|
|
|
// relevant to the order. |
105
|
|
|
// Every URL object will contain an href and a type field. |
106
|
|
|
type OrderListLinks struct { |
107
|
|
|
Self *URL `json:"self,omitempty"` |
108
|
|
|
Previous *URL `json:"previous,omitempty"` |
109
|
|
|
Next *URL `json:"next,omitempty"` |
110
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
// OrderLines contain the actual things the customer bought. |
114
|
|
|
type OrderLines struct { |
115
|
|
|
Resource string `json:"resource,omitempty"` |
116
|
|
|
ID string `json:"id,omitempty"` |
117
|
|
|
OrderID string `json:"orderId,omitempty"` |
118
|
|
|
ProductType *ProductType `json:"type,omitempty"` |
119
|
|
|
Name string `json:"name,omitempty"` |
120
|
|
|
Amount *Amount `json:"amount,omitempty"` |
121
|
|
|
Status *OrderLineStatus `json:"status,omitempty"` |
122
|
|
|
IsCancelable bool `json:"isCancelable,omitempty"` |
123
|
|
|
Quantity int `json:"quantity,omitempty"` |
124
|
|
|
QuantityShipped int `json:"quantityShipped,omitempty"` |
125
|
|
|
AmountShipped *Amount `json:"amountShipped,omitempty"` |
126
|
|
|
QuantityRefunded int `json:"quantityRefunded,omitempty"` |
127
|
|
|
AmountRefunded *Amount `json:"amountRefunded,omitempty"` |
128
|
|
|
QuantityCanceled int `json:"quantityCanceled,omitempty"` |
129
|
|
|
AmountCanceled *Amount `json:"amountCanceled,omitempty"` |
130
|
|
|
ShippableQuantity int `json:"shippableQuantity,omitempty"` |
131
|
|
|
RefundableQuantity int `json:"refundableQuantity,omitempty"` |
132
|
|
|
CancelableQuantity int `json:"cancelableQuantity,omitempty"` |
133
|
|
|
UnitPrice *Amount `json:"unitPrice,omitempty"` |
134
|
|
|
DiscountAmount *Amount `json:"discountAmount,omitempty"` |
135
|
|
|
TotalAmount *Amount `json:"totalAmount,omitempty"` |
136
|
|
|
VatRate string `json:"vatRate,omitempty"` |
137
|
|
|
VatAmount *Amount `json:"vatAmount,omitempty"` |
138
|
|
|
SKU string `json:"sku,omitempty"` |
139
|
|
|
CreatedAt *time.Time `json:"createdAt,omitempty"` |
140
|
|
|
Links *OrderLineLinks `json:"_links,omitempty"` |
141
|
|
|
ImageURL string `json:"imageUrl,omitempty"` |
142
|
|
|
ProductURL string `json:"productUrl,omitempty"` |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
// OrderList for containing the response of list orders |
146
|
|
|
type OrderList struct { |
147
|
|
|
Count int `json:"count,omitempty"` |
148
|
|
|
Embedded struct { |
149
|
|
|
Orders []Orders `json:"orders,omitempty"` |
150
|
|
|
} `json:"_embedded,omitempty"` |
151
|
|
|
Links OrderListLinks `json:"links,omitempty"` |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
// OrderListRefund for containing the response of list orders |
155
|
|
|
type OrderListRefund struct { |
156
|
|
|
Count int `json:"count,omitempty"` |
157
|
|
|
Embedded struct { |
158
|
|
|
Refunds []Refund `json:"refund,omitempty"` |
159
|
|
|
} `json:"_embedded,omitempty"` |
160
|
|
|
Links OrderListLinks `json:"links,omitempty"` |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
// ProductType describes the type of product bought, for example, a physical or a digital product. |
164
|
|
|
type ProductType string |
165
|
|
|
|
166
|
|
|
// Valid product type. |
167
|
|
|
const ( |
168
|
|
|
Physical ProductType = "physical" |
169
|
|
|
Discount ProductType = "discount" |
170
|
|
|
Digital ProductType = "digital" |
171
|
|
|
ShippingFee ProductType = "shipping_fee" |
172
|
|
|
StoreCredit ProductType = "store_credit" |
173
|
|
|
GiftCardProduct ProductType = "gift_card" |
174
|
|
|
Surcharge ProductType = "surcharge" |
175
|
|
|
) |
176
|
|
|
|
177
|
|
|
// OrderLineStatus describes status of the order line. |
178
|
|
|
type OrderLineStatus string |
179
|
|
|
|
180
|
|
|
// Valid order line status. |
181
|
|
|
const ( |
182
|
|
|
OrderLineCreated OrderLineStatus = "created" |
183
|
|
|
OrderLineAuthorized OrderLineStatus = "authorized" |
184
|
|
|
OrderLinePaid OrderLineStatus = "paid" |
185
|
|
|
OrderLineShipping OrderLineStatus = "shipping" |
186
|
|
|
OrderLineCanceled OrderLineStatus = "canceled" |
187
|
|
|
OrderLineCompleted OrderLineStatus = "completed" |
188
|
|
|
) |
189
|
|
|
|
190
|
|
|
// OrderLineLinks describes object with several URL objects relevant to the order line. |
191
|
|
|
type OrderLineLinks struct { |
192
|
|
|
ProductURL *URL `json:"productUrl,omitempty"` |
193
|
|
|
ImageURL *URL `json:"imageUrl,omitempty"` |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
// OrderOptions describes order endpoint valid query string parameters. |
197
|
|
|
// See: https://docs.mollie.com/reference/v2/orders-api/get-order. |
198
|
|
|
type OrderOptions struct { |
199
|
|
|
Embed []EmbedValue `url:"embed,omitempty"` |
200
|
|
|
ProfileID string `url:"profileId,omitempty"` |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
// OrderListOptions describes order endpoint valid query string parameters. |
204
|
|
|
// See: https://docs.mollie.com/reference/v2/orders-api/list-orders. |
205
|
|
|
type OrderListOptions struct { |
206
|
|
|
ProfileID string `url:"profileId,omitempty"` |
207
|
|
|
From string `url:"from,omitempty"` |
208
|
|
|
Limit int `url:"limit,omitempty"` |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
// OrderListRefundOptions describes order endpoint valid query string parameters. |
212
|
|
|
// See: https://docs.mollie.com/reference/v2/orders-api/list-orders. |
213
|
|
|
type OrderListRefundOptions struct { |
214
|
|
|
From string `url:"from,omitempty"` |
215
|
|
|
Limit int `url:"limit,omitempty"` |
216
|
|
|
Embed EmbedValue `url:"embed,omitempty"` |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
// OrdersService instance operates over refund resources. |
220
|
|
|
type OrdersService service |
221
|
|
|
|
222
|
|
|
// Get retrieve a single order by its ID. |
223
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/get-order |
224
|
|
|
func (ors *OrdersService) Get(orID string, opt *OrderOptions) (order Orders, err error) { |
225
|
1 |
|
u := fmt.Sprintf("v2/orders/%s", orID) |
226
|
1 |
|
if opt != nil { |
227
|
1 |
|
v, _ := query.Values(opt) |
228
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
229
|
|
|
} |
230
|
|
|
|
231
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodGet, u, nil) |
232
|
1 |
|
if err != nil { |
233
|
|
|
return |
234
|
|
|
} |
235
|
|
|
|
236
|
1 |
|
res, err := ors.client.Do(req) |
237
|
1 |
|
if err != nil { |
238
|
|
|
return |
239
|
|
|
} |
240
|
|
|
|
241
|
1 |
|
if err = json.Unmarshal(res.content, &order); err != nil { |
242
|
|
|
return |
243
|
|
|
} |
244
|
|
|
|
245
|
1 |
|
return |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
// Create an order will automatically create the required payment to allow your customer to pay for the order. |
249
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/create-order |
250
|
|
|
func (ors *OrdersService) Create(ord Orders, opt *OrderOptions) (order Orders, err error) { |
251
|
1 |
|
u := fmt.Sprintf("v2/orders") |
252
|
1 |
|
if opt != nil { |
253
|
1 |
|
v, _ := query.Values(opt) |
254
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
255
|
|
|
} |
256
|
|
|
|
257
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodPost, u, ord) |
258
|
1 |
|
if err != nil { |
259
|
|
|
return |
260
|
|
|
} |
261
|
|
|
|
262
|
1 |
|
res, err := ors.client.Do(req) |
263
|
1 |
|
if err != nil { |
264
|
|
|
return |
265
|
|
|
} |
266
|
|
|
|
267
|
1 |
|
if err = json.Unmarshal(res.content, &order); err != nil { |
268
|
|
|
return |
269
|
|
|
} |
270
|
|
|
|
271
|
1 |
|
return |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
// Update is used to update the billing and/or shipping address of an order. |
275
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/update-order |
276
|
|
|
func (ors *OrdersService) Update(orderID string, ord Orders) (order Orders, err error) { |
277
|
1 |
|
u := fmt.Sprintf("v2/orders/%s", orderID) |
278
|
|
|
|
279
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodPatch, u, ord) |
280
|
1 |
|
if err != nil { |
281
|
|
|
return |
282
|
|
|
} |
283
|
|
|
|
284
|
1 |
|
res, err := ors.client.Do(req) |
285
|
1 |
|
if err != nil { |
286
|
|
|
return |
287
|
|
|
} |
288
|
|
|
|
289
|
1 |
|
if err = json.Unmarshal(res.content, &order); err != nil { |
290
|
|
|
return |
291
|
|
|
} |
292
|
|
|
|
293
|
1 |
|
return |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
// Cancel try to cancel the order that fulfill certain requirements |
297
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/cancel-order |
298
|
|
|
func (ors *OrdersService) Cancel(orderID string) (order Orders, err error) { |
299
|
1 |
|
u := fmt.Sprintf("v2/orders/" + orderID) |
300
|
|
|
|
301
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodDelete, u, nil) |
302
|
1 |
|
if err != nil { |
303
|
|
|
return |
304
|
|
|
} |
305
|
|
|
|
306
|
1 |
|
res, err := ors.client.Do(req) |
307
|
1 |
|
if err != nil { |
308
|
|
|
return |
309
|
|
|
} |
310
|
|
|
|
311
|
1 |
|
if err = json.Unmarshal(res.content, &order); err != nil { |
312
|
|
|
return |
313
|
|
|
} |
314
|
|
|
|
315
|
1 |
|
return |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
// List is to retrieve all orders. |
319
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/list-orders |
320
|
|
|
func (ors *OrdersService) List(opt *OrderListOptions) (ordList OrderList, err error) { |
321
|
1 |
|
u := fmt.Sprintf("v2/orders") |
322
|
1 |
|
if opt != nil { |
323
|
1 |
|
v, _ := query.Values(opt) |
324
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
325
|
|
|
} |
326
|
|
|
|
327
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodGet, u, nil) |
328
|
1 |
|
if err != nil { |
329
|
|
|
return |
330
|
|
|
} |
331
|
|
|
|
332
|
1 |
|
res, err := ors.client.Do(req) |
333
|
1 |
|
if err != nil { |
334
|
|
|
return |
335
|
|
|
} |
336
|
|
|
|
337
|
1 |
|
if err = json.Unmarshal(res.content, &ordList); err != nil { |
338
|
|
|
return |
339
|
|
|
} |
340
|
|
|
|
341
|
1 |
|
return |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
// UpdateOrderline can be used to update an order line. |
345
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/update-orderline |
346
|
|
|
func (ors *OrdersService) UpdateOrderline(orderID string, orderlineID string, orderline OrderLines) (order Orders, err error) { |
347
|
1 |
|
u := fmt.Sprintf("v2/orders/%s/lines/%s", orderID, orderlineID) |
348
|
|
|
|
349
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodPatch, u, nil) |
350
|
1 |
|
if err != nil { |
351
|
|
|
return |
352
|
|
|
} |
353
|
|
|
|
354
|
1 |
|
res, err := ors.client.Do(req) |
355
|
1 |
|
if err != nil { |
356
|
|
|
return |
357
|
|
|
} |
358
|
|
|
|
359
|
1 |
|
if err = json.Unmarshal(res.content, &order); err != nil { |
360
|
|
|
return |
361
|
|
|
} |
362
|
|
|
|
363
|
1 |
|
return |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
// CancelOrderLine can be used to cancel one or more order lines |
367
|
|
|
// that were previously authorized using a pay after delivery payment method. |
368
|
|
|
// Use the Cancel Order API if you want to cancel the entire order or the remainder of the order. |
369
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/cancel-order-lines |
370
|
|
|
func (ors *OrdersService) CancelOrderLine(orderID string, orderlines *Orders) (errorResponse *ErrorResponse, err error) { |
371
|
1 |
|
u := fmt.Sprintf("v2/orders/%s/lines", orderID) |
372
|
|
|
|
373
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodDelete, u, orderlines) |
374
|
1 |
|
if err != nil { |
375
|
|
|
return |
376
|
|
|
} |
377
|
|
|
|
378
|
1 |
|
res, err := ors.client.Do(req) |
379
|
1 |
|
if err != nil { |
380
|
1 |
|
err = json.Unmarshal(res.content, &errorResponse) |
381
|
1 |
|
if err != nil { |
382
|
1 |
|
return |
383
|
|
|
} |
384
|
|
|
return |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
if res.StatusCode == http.StatusNoContent { |
388
|
|
|
return nil, nil |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
return |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
// CreateOrderPayment can only be created while the status of the order is created, |
395
|
|
|
// and when the status of the existing payment is either expired, canceled or failed. |
396
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/create-order-payment |
397
|
|
|
func (ors *OrdersService) CreateOrderPayment(orderID string, ordPay *OrderPayment) (payment *Payment, errorResponse *ErrorResponse, err error) { |
398
|
1 |
|
u := fmt.Sprintf("v2/orders/%s/payments", orderID) |
399
|
|
|
|
400
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodPost, u, ordPay) |
401
|
1 |
|
if err != nil { |
402
|
|
|
return |
403
|
|
|
} |
404
|
|
|
|
405
|
1 |
|
res, err := ors.client.Do(req) |
406
|
1 |
|
if err != nil { |
407
|
1 |
|
err = json.Unmarshal(res.content, &errorResponse) |
408
|
1 |
|
if err != nil { |
409
|
1 |
|
return |
410
|
|
|
} |
411
|
|
|
return |
412
|
|
|
} |
413
|
|
|
|
414
|
1 |
|
if err = json.Unmarshal(res.content, &payment); err != nil { |
415
|
|
|
return |
416
|
|
|
} |
417
|
|
|
|
418
|
1 |
|
return |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
// CreateOrderRefund using the Orders API, refunds should be made against the order. |
422
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/create-order-refund |
423
|
|
|
func (ors *OrdersService) CreateOrderRefund(orderID string, order *Orders) (refund Refund, errorResponse *ErrorResponse, err error) { |
424
|
1 |
|
u := fmt.Sprintf("v2/orders/%s/refunds", orderID) |
425
|
|
|
|
426
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodPost, u, order) |
427
|
1 |
|
if err != nil { |
428
|
|
|
return |
429
|
|
|
} |
430
|
|
|
|
431
|
1 |
|
res, err := ors.client.Do(req) |
432
|
1 |
|
if err != nil { |
433
|
1 |
|
err = json.Unmarshal(res.content, &errorResponse) |
434
|
1 |
|
if err != nil { |
435
|
1 |
|
return |
436
|
|
|
} |
437
|
|
|
return |
438
|
|
|
} |
439
|
|
|
|
440
|
1 |
|
if err = json.Unmarshal(res.content, &refund); err != nil { |
441
|
|
|
return |
442
|
|
|
} |
443
|
|
|
|
444
|
1 |
|
return |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
// ListOrderRefunds retrieve all order refunds. |
448
|
|
|
// See https://docs.mollie.com/reference/v2/orders-api/list-order-refunds |
449
|
|
|
func (ors *OrdersService) ListOrderRefunds(orderID string, opt *OrderListRefundOptions) (orderListRefund OrderListRefund, err error) { |
450
|
1 |
|
u := fmt.Sprintf("v2/orders/%s/refunds", orderID) |
451
|
1 |
|
if opt != nil { |
452
|
1 |
|
v, _ := query.Values(opt) |
453
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
454
|
|
|
} |
455
|
|
|
|
456
|
1 |
|
req, err := ors.client.NewAPIRequest(http.MethodGet, u, nil) |
457
|
1 |
|
if err != nil { |
458
|
|
|
return |
459
|
|
|
} |
460
|
|
|
|
461
|
1 |
|
res, err := ors.client.Do(req) |
462
|
1 |
|
if err != nil { |
463
|
|
|
return |
464
|
|
|
} |
465
|
|
|
|
466
|
1 |
|
if err = json.Unmarshal(res.content, &orderListRefund); err != nil { |
467
|
|
|
return |
468
|
|
|
} |
469
|
|
|
|
470
|
1 |
|
return |
471
|
|
|
} |
472
|
|
|
|