1 | |
2 | type Mollie = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create profile |
7 | * Create a profile to process payments on. |
8 |
|
9 | Profiles are required for payment processing. Normally they are created via the Mollie dashboard. Alternatively, you can use this endpoint to automate profile creation. |
10 |
|
11 | > 🔑 Access with |
12 | > |
13 | > Access token with **profiles.write** |
14 | */ |
15 | export async function main( |
16 | auth: Mollie, |
17 | body: { |
18 | resource?: string; |
19 | id?: string; |
20 | mode?: string; |
21 | name: string; |
22 | website: string; |
23 | email: string; |
24 | phone: string; |
25 | description?: string; |
26 | countriesOfActivity?: unknown[]; |
27 | businessCategory?: string; |
28 | status?: string; |
29 | review?: { status?: string }; |
30 | createdAt?: string; |
31 | _links?: { |
32 | self?: { href?: string; type?: string }; |
33 | dashboard?: { href?: string; type?: string }; |
34 | chargebacks?: { href?: string; type?: string }; |
35 | methods?: { href?: string; type?: string }; |
36 | payments?: { href?: string; type?: string }; |
37 | refunds?: { href?: string; type?: string }; |
38 | checkoutPreviewUrl?: { href?: string; type?: string }; |
39 | documentation?: { href?: string; type?: string }; |
40 | }; |
41 | }, |
42 | ) { |
43 | const url = new URL(`https://api.mollie.com/v2/profiles`); |
44 |
|
45 | const response = await fetch(url, { |
46 | method: "POST", |
47 | headers: { |
48 | "Content-Type": "application/json", |
49 | Authorization: "Bearer " + auth.token, |
50 | }, |
51 | body: JSON.stringify(body), |
52 | }); |
53 | if (!response.ok) { |
54 | const text = await response.text(); |
55 | throw new Error(`${response.status} ${text}`); |
56 | } |
57 | return await response.text(); |
58 | } |
59 |
|