1 | |
2 | type Mollie = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create payment refund |
7 | * Creates a refund for a specific payment. The refunded amount is credited to your customer usually either via a bank transfer or by refunding the amount to your customer's credit card. |
8 |
|
9 | > 🔑 Access with |
10 | > |
11 | > API key |
12 | > |
13 | > Access token with **refunds.write** |
14 | */ |
15 | export async function main( |
16 | auth: Mollie, |
17 | paymentId: string, |
18 | body: { |
19 | resource?: string; |
20 | id?: string; |
21 | mode?: string; |
22 | description?: string; |
23 | amount: { currency: string; value: string }; |
24 | settlementAmount?: { currency: string; value: string }; |
25 | metadata?: string | {} | string[]; |
26 | paymentId?: string; |
27 | settlementId?: string; |
28 | status?: string; |
29 | createdAt?: string; |
30 | externalReference?: { type?: string; id?: string }; |
31 | reverseRouting?: false | true; |
32 | routingReversals?: { |
33 | amount?: { currency: string; value: string }; |
34 | source?: { type?: string; organizationId?: string }; |
35 | }[]; |
36 | testmode?: false | true; |
37 | _links?: { |
38 | self?: { href?: string; type?: string }; |
39 | payment?: { href?: string; type?: string }; |
40 | settlement?: { href?: string; type?: string }; |
41 | documentation?: { href?: string; type?: string }; |
42 | }; |
43 | }, |
44 | ) { |
45 | const url = new URL( |
46 | `https://api.mollie.com/v2/payments/${paymentId}/refunds`, |
47 | ); |
48 |
|
49 | const response = await fetch(url, { |
50 | method: "POST", |
51 | headers: { |
52 | "Content-Type": "application/json", |
53 | Authorization: "Bearer " + auth.token, |
54 | }, |
55 | body: JSON.stringify(body), |
56 | }); |
57 | if (!response.ok) { |
58 | const text = await response.text(); |
59 | throw new Error(`${response.status} ${text}`); |
60 | } |
61 | return await response.text(); |
62 | } |
63 |
|