0

List customer payments

by
Published Apr 8, 2025

Retrieve all payments linked to the customer. > 🔑 Access with > > API key > > Access token with **payments.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 customer payments
7
 * Retrieve all payments linked to the customer.
8

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