0

Update payment link

by
Published Apr 8, 2025

Certain details of an existing payment link can be updated. > 🔑 Access with > > API key > > Access token with **payment-links.write**

Script mollie Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Mollie = {
3
  token: string;
4
};
5
/**
6
 * Update payment link
7
 * Certain details of an existing payment link can be updated.
8

9
> 🔑 Access with
10
>
11
> API key
12
>
13
> Access token with **payment-links.write**
14
 */
15
export async function main(
16
  auth: Mollie,
17
  paymentLinkId: string,
18
  testmode: string | undefined,
19
  body: {
20
    description?: string;
21
    minimumAmount?: { currency: string; value: string };
22
    archived?: false | true;
23
    allowedMethods?:
24
      | "applepay"
25
      | "bancomatpay"
26
      | "bancontact"
27
      | "banktransfer"
28
      | "belfius"
29
      | "blik"
30
      | "creditcard"
31
      | "eps"
32
      | "giftcard"
33
      | "ideal"
34
      | "kbc"
35
      | "mybank"
36
      | "paybybank"
37
      | "paypal"
38
      | "paysafecard"
39
      | "pointofsale"
40
      | "przelewy24"
41
      | "satispay"
42
      | "trustly"
43
      | "twint"[];
44
  },
45
) {
46
  const url = new URL(
47
    `https://api.mollie.com/v2/payment-links/${paymentLinkId}`,
48
  );
49
  for (const [k, v] of [["testmode", testmode]]) {
50
    if (v !== undefined && v !== "" && k !== undefined) {
51
      url.searchParams.append(k, v);
52
    }
53
  }
54
  const response = await fetch(url, {
55
    method: "PATCH",
56
    headers: {
57
      "Content-Type": "application/json",
58
      Authorization: "Bearer " + auth.token,
59
    },
60
    body: JSON.stringify(body),
61
  });
62
  if (!response.ok) {
63
    const text = await response.text();
64
    throw new Error(`${response.status} ${text}`);
65
  }
66
  return await response.text();
67
}
68