//native
type Mollie = {
token: string;
};
/**
* Create subscription
* With subscriptions, you can schedule recurring payments to take place at regular intervals.
*/
export async function main(
auth: Mollie,
customerId: string,
body: {
resource?: string;
id?: string;
mode?: string;
status?: string;
amount: { currency: string; value: string };
times?: number;
timesRemaining?: number;
interval: string;
startDate?: string;
nextPaymentDate?: string;
description: string;
method?: string;
applicationFee?: {
amount?: { currency: string; value: string };
description?: string;
};
metadata?: string | {} | string[];
webhookUrl?: string;
customerId?: string;
mandateId?: string;
profileId?: string;
createdAt?: string;
canceledAt?: string;
testmode?: false | true;
_links?: {
self?: { href?: string; type?: string };
customer?: { href?: string; type?: string };
payments?: { href?: string; type?: string };
documentation?: { href?: string; type?: string };
};
},
) {
const url = new URL(
`https://api.mollie.com/v2/customers/${customerId}/subscriptions`,
);
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