0

Create mandate

by
Published Apr 8, 2025

Create a mandate for a specific customer. Mandates allow you to charge a customer's card, PayPal account or bank account recurrently. It is only possible to create mandates for IBANs and PayPal billing agreements with this endpoint. To create mandates for cards, your customers need to perform a 'first payment' with their card. > 🔑 Access with > > API key > > Access token with **mandates.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 mandate
7
 * Create a mandate for a specific customer. Mandates allow you to charge a customer's card, PayPal account or bank account recurrently.
8

9
It is only possible to create mandates for IBANs and PayPal billing agreements with this endpoint. To create mandates for cards, your customers need to perform a 'first payment' with their card.
10

11
> 🔑 Access with
12
>
13
> API key
14
>
15
> Access token with **mandates.write**
16
 */
17
export async function main(
18
  auth: Mollie,
19
  customerId: string,
20
  body: {
21
    resource?: string;
22
    id?: string;
23
    mode?: string;
24
    method: string;
25
    consumerName: string;
26
    consumerAccount?: string;
27
    consumerBic?: string;
28
    consumerEmail?: string;
29
    details?: {
30
      consumerName?: string;
31
      consumerAccount?: string;
32
      consumerBic?: string;
33
      cardHolder?: string;
34
      cardNumber?: string;
35
      cardExpiryDate?: string;
36
      cardLabel?: string;
37
      cardFingerprint?: string;
38
    };
39
    signatureDate?: string;
40
    mandateReference?: string;
41
    paypalBillingAgreementId?: string;
42
    payPalVaultId?: string;
43
    status?: string;
44
    customerId?: string;
45
    createdAt?: string;
46
    testmode?: false | true;
47
    _links?: {
48
      self?: { href?: string; type?: string };
49
      customer?: { href?: string; type?: string };
50
      documentation?: { href?: string; type?: string };
51
    };
52
  },
53
) {
54
  const url = new URL(
55
    `https://api.mollie.com/v2/customers/${customerId}/mandates`,
56
  );
57

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