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