+ subscriptions

This commit is contained in:
Kiara Grouwstra 2023-01-05 14:39:06 +01:00
parent bb33415592
commit accb24c6c0
1 changed files with 9 additions and 0 deletions

View File

@ -13,6 +13,7 @@ async function main() {
const mollie = createMollieClient({ apiKey });
const customers = await exportMollieCustomers(mollie);
const customerObj = Object.fromEntries(customers.map(({ id, ...rest }) => [id, rest]));
const subscriptions = await exportMollieSubscriptions(mollie, customerObj);
const payments = await exportMolliePayments(mollie, customerObj);
const paymentObj: PaymentObj = Object.fromEntries(payments.map(({ id, ...rest }) => [id, rest]));
assert(apiKey.slice(0,5) == 'live_');
@ -28,6 +29,14 @@ async function exportMollieCustomers(mollie: MollieClient): Promise<{[k: string]
return list;
}
async function exportMollieSubscriptions(mollie: MollieClient, customerObj: { [id: string]: { name: string, email: string, createdAt: string } }): Promise<{[k: string]: any}[]> {
const page$ = mollie.subscription.list();
const list = (await listAll(page$, 500))
.map(({ resource, id, mode, createdAt, status, amount, times, timesRemaining, interval, startDate, nextPaymentDate, description, method, webhookUrl, _links }) => ({ resource, id, mode, createdAt, status, times, timesRemaining, interval, startDate, nextPaymentDate, description, method, webhookUrl, customerId: _links.customer.href.split('/')[5], ...mapKeys(prepend('amount.'))(amount)/*, ...mapKeys(prepend('_links.'))(_links)*/, ...mapKeys(prepend('customer.'))(customerObj[_links.customer.href.split('/')[5] || '']) }));
writeFileSync('./data/subscriptions.csv', unparse(list));
return list;
}
async function exportMollieRefunds(mollie: MollieClient, paymentObj: PaymentObj): Promise<{[k: string]: any}[]> {
const page$ = mollie.refunds.list();
const list = (await listAll(page$, 500))