0

Cancel payment refund

by
Published Apr 8, 2025

Refunds will be executed with a delay of two hours. Until that time, refunds may be canceled manually via the Mollie Dashboard, or by using this endpoint. A refund can only be canceled while its `status` field is either `queued` or `pending`. See the [Get refund endpoint](get-refund) for more information. > 🔑 Access with > > API key > > Access token with **refunds.write**

Script mollie Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Mollie = {
3
  token: string;
4
};
5
/**
6
 * Cancel payment refund
7
 * Refunds will be executed with a delay of two hours. Until that time, refunds may be canceled manually via the Mollie Dashboard, or by using this endpoint.
8

9
A refund can only be canceled while its `status` field is either `queued` or `pending`. See the [Get refund endpoint](get-refund) for more information.
10

11
> 🔑 Access with
12
>
13
> API key
14
>
15
> Access token with **refunds.write**
16
 */
17
export async function main(
18
  auth: Mollie,
19
  paymentId: string,
20
  refundId: string,
21
  testmode: string | undefined,
22
) {
23
  const url = new URL(
24
    `https://api.mollie.com/v2/payments/${paymentId}/refunds/${refundId}`,
25
  );
26
  for (const [k, v] of [["testmode", testmode]]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "DELETE",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.text();
43
}
44