0

Create payment link

by
Published Apr 8, 2025

With the Payment links API you can generate payment links that by default, unlike regular payments, do not expire. The payment link can be shared with your customers and will redirect them to them the payment page where they can complete the payment. A [payment](get-payment) will only be created once the customer initiates the payment. > 🔑 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
 * Create payment link
7
 * With the Payment links API you can generate payment links that by default, unlike regular payments, do not expire. The payment link can be shared with your customers and will redirect them to them the payment page where they can complete the payment. A [payment](get-payment) will only be created once the customer initiates the payment.
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
  body: {
18
    resource?: string;
19
    id?: string;
20
    mode?: string;
21
    description: string;
22
    amount?: { currency: string; value: string };
23
    minimumAmount?: { currency: string; value: string };
24
    archived?: false | true;
25
    redirectUrl?: string;
26
    webhookUrl?: string;
27
    profileId?: string;
28
    reusable?: false | true;
29
    createdAt?: string;
30
    paidAt?: string;
31
    expiresAt?: string;
32
    allowedMethods?:
33
      | "applepay"
34
      | "bancomatpay"
35
      | "bancontact"
36
      | "banktransfer"
37
      | "belfius"
38
      | "blik"
39
      | "creditcard"
40
      | "eps"
41
      | "giftcard"
42
      | "ideal"
43
      | "kbc"
44
      | "mybank"
45
      | "paybybank"
46
      | "paypal"
47
      | "paysafecard"
48
      | "pointofsale"
49
      | "przelewy24"
50
      | "satispay"
51
      | "trustly"
52
      | "twint"[];
53
    sequenceType?: "oneoff" | "first" | "recurring";
54
    customerId?: string;
55
    applicationFee?: {
56
      amount?: { currency: string; value: string };
57
      description?: string;
58
    };
59
    _links?: {
60
      self?: { href?: string; type?: string };
61
      paymentLink?: { href?: string; type?: string };
62
      documentation?: { href?: string; type?: string };
63
    };
64
  },
65
) {
66
  const url = new URL(`https://api.mollie.com/v2/payment-links`);
67

68
  const response = await fetch(url, {
69
    method: "POST",
70
    headers: {
71
      "Content-Type": "application/json",
72
      Authorization: "Bearer " + auth.token,
73
    },
74
    body: JSON.stringify(body),
75
  });
76
  if (!response.ok) {
77
    const text = await response.text();
78
    throw new Error(`${response.status} ${text}`);
79
  }
80
  return await response.text();
81
}
82