0

List order refunds

by
Published Apr 8, 2025

Retrieve a list of all refunds created for a specific order. The results are paginated. > 🔑 Access with > > API key > > Access token with **refunds.read**

Script mollie Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Mollie = {
3
  token: string;
4
};
5
/**
6
 * List order refunds
7
 * Retrieve a list of all refunds created for a specific order.
8

9
The results are paginated.
10

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