0

Create a delayed route

by
Published Apr 8, 2025

Create a route for a specific payment. The routed amount is credited to the account of your customer. > 🔑 Access with > > API key

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 a delayed route
7
 * Create a route for a specific payment. The routed amount is credited to the account of your customer.
8

9
> 🔑 Access with
10
>
11
> API key
12
 */
13
export async function main(
14
  auth: Mollie,
15
  paymentId: string,
16
  body: {
17
    resource?: string;
18
    id?: string;
19
    paymentId?: string;
20
    amount?: { currency: string; value: string };
21
    description?: string;
22
    destination?: { type?: string; organizationId?: string };
23
    _links?: {
24
      self?: { href?: string; type?: string };
25
      documentation?: { href?: string; type?: string };
26
    };
27
  },
28
) {
29
  const url = new URL(`https://api.mollie.com/v2/payments/${paymentId}/routes`);
30

31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.text();
44
}
45