1 | |
2 | type Mollie = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create order |
7 | * **⚠️ We no longer recommend implementing the Orders API. |
8 | */ |
9 | export async function main( |
10 | auth: Mollie, |
11 | embed: string | undefined, |
12 | body: { |
13 | resource?: string; |
14 | id?: string; |
15 | mode?: string; |
16 | orderNumber: string; |
17 | lines: { |
18 | resource?: string; |
19 | id?: string; |
20 | type?: string; |
21 | name: string; |
22 | quantity: number; |
23 | quantityUnit?: string; |
24 | unitPrice: { currency: string; value: string }; |
25 | discountAmount?: { currency: string; value: string }; |
26 | totalAmount: { currency: string; value: string }; |
27 | vatRate?: string; |
28 | vatAmount?: { currency: string; value: string }; |
29 | sku?: string; |
30 | category?: string; |
31 | status?: string; |
32 | isCancelable?: false | true; |
33 | metadata?: string | {} | string[]; |
34 | orderId?: string; |
35 | imageUrl?: string; |
36 | productUrl?: string; |
37 | createdAt?: string; |
38 | _links?: { |
39 | self?: { href?: string; type?: string }; |
40 | imageUrl?: { href?: string; type?: string }; |
41 | productUrl?: { href?: string; type?: string }; |
42 | }; |
43 | }[]; |
44 | amount: { currency: string; value: string }; |
45 | amountRefunded?: { currency: string; value: string }; |
46 | amountCaptured?: { currency: string; value: string }; |
47 | redirectUrl?: string; |
48 | cancelUrl?: string; |
49 | webhookUrl?: string; |
50 | billingAddress: { |
51 | title?: string; |
52 | givenName?: string; |
53 | familyName?: string; |
54 | organizationName?: string; |
55 | streetAndNumber: string; |
56 | streetAdditional?: string; |
57 | postalCode?: string; |
58 | email?: string; |
59 | phone?: string; |
60 | city: string; |
61 | region?: string; |
62 | country: string; |
63 | }; |
64 | shippingAddress?: { |
65 | title?: string; |
66 | givenName?: string; |
67 | familyName?: string; |
68 | organizationName?: string; |
69 | streetAndNumber: string; |
70 | streetAdditional?: string; |
71 | postalCode?: string; |
72 | email?: string; |
73 | phone?: string; |
74 | city: string; |
75 | region?: string; |
76 | country: string; |
77 | }; |
78 | locale: string; |
79 | method?: string; |
80 | shopperCountryMustMatchBillingCountry?: false | true; |
81 | metadata?: string | string[] | {}; |
82 | status?: string; |
83 | isCancelable?: false | true; |
84 | payment?: {}; |
85 | profileId?: string; |
86 | createdAt?: string; |
87 | authorizedAt?: string; |
88 | paidAt?: string; |
89 | canceledAt?: string; |
90 | expiresAt?: string; |
91 | expiredAt?: string; |
92 | completedAt?: string; |
93 | testmode?: false | true; |
94 | _links?: { |
95 | self?: { href?: string; type?: string }; |
96 | checkout?: { href?: string; type?: string }; |
97 | dashboard?: { href?: string; type?: string }; |
98 | documentation?: { href?: string; type?: string }; |
99 | }; |
100 | }, |
101 | ) { |
102 | const url = new URL(`https://api.mollie.com/v2/orders`); |
103 | for (const [k, v] of [["embed", embed]]) { |
104 | if (v !== undefined && v !== "" && k !== undefined) { |
105 | url.searchParams.append(k, v); |
106 | } |
107 | } |
108 | const response = await fetch(url, { |
109 | method: "POST", |
110 | headers: { |
111 | "Content-Type": "application/json", |
112 | Authorization: "Bearer " + auth.token, |
113 | }, |
114 | body: JSON.stringify(body), |
115 | }); |
116 | if (!response.ok) { |
117 | const text = await response.text(); |
118 | throw new Error(`${response.status} ${text}`); |
119 | } |
120 | return await response.text(); |
121 | } |
122 |
|