0

Update payment

by
Published Apr 8, 2025

Certain details of an existing payment can be updated. For an in-depth explanation of each parameter, see [Create payment](create-payment). Updating the payment details will not result in a webhook call. > 🔑 Access with > > API key > > Access token with **payments.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
7
 * Certain details of an existing payment can be updated. For an in-depth explanation of each parameter, see [Create payment](create-payment).
8

9
Updating the payment details will not result in a webhook call.
10

11
> 🔑 Access with
12
>
13
> API key
14
>
15
> Access token with **payments.write**
16
 */
17
export async function main(
18
  auth: Mollie,
19
  paymentId: string,
20
  body: {
21
    description?: string;
22
    redirectUrl?: string;
23
    cancelUrl?: string;
24
    webhookUrl?: string;
25
    metadata?: string | {} | string[];
26
    method?:
27
      | "alma"
28
      | "applepay"
29
      | "bacs"
30
      | "bancomatpay"
31
      | "bancontact"
32
      | "banktransfer"
33
      | "belfius"
34
      | "blik"
35
      | "creditcard"
36
      | "directdebit"
37
      | "eps"
38
      | "giftcard"
39
      | "ideal"
40
      | "in3"
41
      | "kbc"
42
      | "mbway"
43
      | "multibanco"
44
      | "mybank"
45
      | "payconiq"
46
      | "paypal"
47
      | "paysafecard"
48
      | "pointofsale"
49
      | "przelewy24"
50
      | "satispay"
51
      | "trustly"
52
      | "twint"
53
      | "voucher";
54
    locale?: string;
55
    restrictPaymentMethodsToCountry?: string;
56
    testmode?: false | true;
57
  },
58
) {
59
  const url = new URL(`https://api.mollie.com/v2/payments/${paymentId}`);
60

61
  const response = await fetch(url, {
62
    method: "PATCH",
63
    headers: {
64
      "Content-Type": "application/json",
65
      Authorization: "Bearer " + auth.token,
66
    },
67
    body: JSON.stringify(body),
68
  });
69
  if (!response.ok) {
70
    const text = await response.text();
71
    throw new Error(`${response.status} ${text}`);
72
  }
73
  return await response.text();
74
}
75