0

List payment methods

by
Published Apr 8, 2025

Retrieve all enabled payment methods.

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 payment methods
7
 * Retrieve all enabled payment methods.
8
 */
9
export async function main(
10
  auth: Mollie,
11
  sequenceType: string | undefined,
12
  locale: string | undefined,
13
  amount: string | undefined,
14
  resource: string | undefined,
15
  billingCountry: string | undefined,
16
  includeWallets: string | undefined,
17
  orderLineCategories: string | undefined,
18
  profileId: string | undefined,
19
  include: "issuers" | "pricing" | undefined,
20
  testmode: string | undefined,
21
) {
22
  const url = new URL(`https://api.mollie.com/v2/methods`);
23
  for (const [k, v] of [
24
    ["sequenceType", sequenceType],
25
    ["locale", locale],
26
    ["amount", amount],
27
    ["resource", resource],
28
    ["billingCountry", billingCountry],
29
    ["includeWallets", includeWallets],
30
    ["orderLineCategories", orderLineCategories],
31
    ["profileId", profileId],
32
    ["include", include],
33
    ["testmode", testmode],
34
  ]) {
35
    if (v !== undefined && v !== "" && k !== undefined) {
36
      url.searchParams.append(k, v);
37
    }
38
  }
39
  const response = await fetch(url, {
40
    method: "GET",
41
    headers: {
42
      Authorization: "Bearer " + auth.token,
43
    },
44
    body: undefined,
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.text();
51
}
52