0

Revoke mandate

by
Published Apr 8, 2025

Revoke a customer's mandate. You will no longer be able to charge the customer's bank account or card with this mandate, and all connected subscriptions will be canceled. > 🔑 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
 * Revoke mandate
7
 * Revoke a customer's mandate. You will no longer be able to charge the customer's bank account or card with this mandate, and all connected subscriptions will be canceled.
8

9
> 🔑 Access with
10
>
11
> API key
12
>
13
> Access token with **mandates.write**
14
 */
15
export async function main(
16
  auth: Mollie,
17
  customerId: string,
18
  id: string,
19
  testmode: string | undefined,
20
) {
21
  const url = new URL(
22
    `https://api.mollie.com/v2/customers/${customerId}/mandates/${id}`,
23
  );
24
  for (const [k, v] of [["testmode", testmode]]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "DELETE",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.text();
41
}
42