0

Get payment

by
Published Apr 8, 2025

Retrieve a single payment object by its payment ID. > 🔑 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
 * Get payment
7
 * Retrieve a single payment object by its payment ID.
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
  paymentId: string,
18
  include: "details.qrCode" | "details.remainderDetails" | undefined,
19
  embed: "captures" | "refunds" | "chargebacks" | undefined,
20
  testmode: string | undefined,
21
) {
22
  const url = new URL(`https://api.mollie.com/v2/payments/${paymentId}`);
23
  for (const [k, v] of [
24
    ["include", include],
25
    ["embed", embed],
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