0

Get payment link payments

by
Published Apr 8, 2025

Retrieve the list of payments for a specific payment link. The results are paginated. > 🔑 Access with > > API key > > Access token with **payment-links.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 link payments
7
 * Retrieve the list of payments for a specific payment link.
8

9
The results are paginated.
10

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