0

Get payment refund

by
Published Apr 8, 2025

Retrieve a single payment refund by its ID and the ID of its parent payment. > 🔑 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
 * Get payment refund
7
 * Retrieve a single payment refund by its ID and the ID of its parent payment.
8

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