0

Create capture

by
Published Apr 8, 2025

**This feature is currently in open beta.

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 capture
7
 * **This feature is currently in open beta.
8
 */
9
export async function main(
10
  auth: Mollie,
11
  paymentId: string,
12
  body: {
13
    resource?: string;
14
    id?: string;
15
    mode?: string;
16
    description?: string;
17
    amount?: { currency: string; value: string };
18
    settlementAmount?: { currency: string; value: string };
19
    status?: string;
20
    metadata?: string | {} | string[];
21
    paymentId?: string;
22
    shipmentId?: string;
23
    settlementId?: string;
24
    createdAt?: string;
25
    _links?: {
26
      self?: { href?: string; type?: string };
27
      payment?: { href?: string; type?: string };
28
      settlement?: { href?: string; type?: string };
29
      shipment?: { href?: string; type?: string };
30
      documentation?: { href?: string; type?: string };
31
    };
32
  },
33
) {
34
  const url = new URL(
35
    `https://api.mollie.com/v2/payments/${paymentId}/captures`,
36
  );
37

38
  const response = await fetch(url, {
39
    method: "POST",
40
    headers: {
41
      "Content-Type": "application/json",
42
      Authorization: "Bearer " + auth.token,
43
    },
44
    body: JSON.stringify(body),
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.text();
51
}
52