//native
type Mollie = {
token: string;
};
/**
* Create order
* **⚠️ We no longer recommend implementing the Orders API.
*/
export async function main(
auth: Mollie,
embed: string | undefined,
body: {
resource?: string;
id?: string;
mode?: string;
orderNumber: string;
lines: {
resource?: string;
id?: string;
type?: string;
name: string;
quantity: number;
quantityUnit?: string;
unitPrice: { currency: string; value: string };
discountAmount?: { currency: string; value: string };
totalAmount: { currency: string; value: string };
vatRate?: string;
vatAmount?: { currency: string; value: string };
sku?: string;
category?: string;
status?: string;
isCancelable?: false | true;
metadata?: string | {} | string[];
orderId?: string;
imageUrl?: string;
productUrl?: string;
createdAt?: string;
_links?: {
self?: { href?: string; type?: string };
imageUrl?: { href?: string; type?: string };
productUrl?: { href?: string; type?: string };
};
}[];
amount: { currency: string; value: string };
amountRefunded?: { currency: string; value: string };
amountCaptured?: { currency: string; value: string };
redirectUrl?: string;
cancelUrl?: string;
webhookUrl?: string;
billingAddress: {
title?: string;
givenName?: string;
familyName?: string;
organizationName?: string;
streetAndNumber: string;
streetAdditional?: string;
postalCode?: string;
email?: string;
phone?: string;
city: string;
region?: string;
country: string;
};
shippingAddress?: {
title?: string;
givenName?: string;
familyName?: string;
organizationName?: string;
streetAndNumber: string;
streetAdditional?: string;
postalCode?: string;
email?: string;
phone?: string;
city: string;
region?: string;
country: string;
};
locale: string;
method?: string;
shopperCountryMustMatchBillingCountry?: false | true;
metadata?: string | string[] | {};
status?: string;
isCancelable?: false | true;
payment?: {};
profileId?: string;
createdAt?: string;
authorizedAt?: string;
paidAt?: string;
canceledAt?: string;
expiresAt?: string;
expiredAt?: string;
completedAt?: string;
testmode?: false | true;
_links?: {
self?: { href?: string; type?: string };
checkout?: { href?: string; type?: string };
dashboard?: { href?: string; type?: string };
documentation?: { href?: string; type?: string };
};
},
) {
const url = new URL(`https://api.mollie.com/v2/orders`);
for (const [k, v] of [["embed", embed]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 428 days ago