//native
type Mollie = {
token: string;
};
/**
* Create payment
* Payment creation is elemental to the Mollie API: this is where most payment implementations start off.
*/
export async function main(
auth: Mollie,
include: "details.qrCode" | undefined,
body: {
resource?: string;
id?: string;
mode?: string;
description: string;
amount: { currency: string; value: string };
amountRefunded?: { currency: string; value: string };
amountRemaining?: { currency: string; value: string };
amountCaptured?: { currency: string; value: string };
amountChargedBack?: { currency: string; value: string };
settlementAmount?: { currency: string; value: string };
redirectUrl: string;
cancelUrl?: string;
webhookUrl?: string;
lines?: {
type?: string;
description: string;
quantity: number;
quantityUnit?: string;
unitPrice: { currency: string; value: string };
discountAmount?: { currency: string; value: string };
recurring?: {
description?: string;
interval: string;
amount?: { currency: string; value: string };
times?: number;
startDate?: string;
};
totalAmount: { currency: string; value: string };
vatRate?: string;
vatAmount?: { currency: string; value: string };
sku?: string;
categories?: "meal" | "eco" | "gift" | "sport_culture"[];
imageUrl?: string;
productUrl?: 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;
countryCode?: string;
method?: string;
issuer?: string;
restrictPaymentMethodsToCountry?: string;
metadata?: string | {} | string[];
captureMode?: string;
captureDelay?: string;
captureBefore?: string;
applicationFee?: {
amount?: { currency: string; value: string };
description?: string;
};
routing?: {
resource?: string;
id?: string;
mode?: string;
amount?: { currency: string; value: string };
destination?: { type?: string; organizationId?: string };
releaseDate?: string;
_links?: {
self?: { href?: string; type?: string };
payment?: { href?: string; type?: string };
};
}[];
sequenceType?: string;
subscriptionId?: string;
mandateId?: string;
customerId?: string;
profileId?: string;
settlementId?: string;
orderId?: string;
status?: string;
statusReason?: { code: string; message: string };
isCancelable?: false | true;
details?: {};
createdAt?: string;
authorizedAt?: string;
paidAt?: string;
canceledAt?: string;
expiresAt?: string;
expiredAt?: string;
failedAt?: string;
testmode?: false | true;
_links?: {
self?: { href?: string; type?: string };
checkout?: { href?: string; type?: string };
mobileAppCheckout?: { href?: string; type?: string };
changePaymentState?: { href?: string; type?: string };
dashboard?: { href?: string; type?: string };
refunds?: { href?: string; type?: string };
chargebacks?: { href?: string; type?: string };
captures?: { href?: string; type?: string };
settlement?: { href?: string; type?: string };
customer?: { href?: string; type?: string };
mandate?: { href?: string; type?: string };
subscription?: { href?: string; type?: string };
order?: { href?: string; type?: string };
terminal?: { href?: string; type?: string };
documentation?: { href?: string; type?: string };
};
},
) {
const url = new URL(`https://api.mollie.com/v2/payments`);
for (const [k, v] of [["include", include]]) {
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