0

List subscription payments

by
Published Apr 8, 2025

Retrieve all payments of a specific subscription. The results are paginated. > 🔑 Access with > > API key > > Access token with **subscriptions.read** **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 subscription payments
7
 * Retrieve all payments of a specific subscription.
8

9
The results are paginated.
10

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