0

Get payment method

by
Published Apr 8, 2025

Retrieve a single payment method by its ID.

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 method
7
 * Retrieve a single payment method by its ID.
8
 */
9
export async function main(
10
  auth: Mollie,
11
  id: string,
12
  locale: string | undefined,
13
  currency: string | undefined,
14
  profileId: string | undefined,
15
  include: "issuers" | "pricing" | undefined,
16
  sequenceType: string | undefined,
17
  testmode: string | undefined,
18
) {
19
  const url = new URL(`https://api.mollie.com/v2/methods/${id}`);
20
  for (const [k, v] of [
21
    ["locale", locale],
22
    ["currency", currency],
23
    ["profileId", profileId],
24
    ["include", include],
25
    ["sequenceType", sequenceType],
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