incorporate customer data into payment dump
This commit is contained in:
parent
7c017ec432
commit
81c7c6f346
13
src/app.ts
13
src/app.ts
|
@ -7,23 +7,26 @@ import { mollieKeys, listAll } from './mollie';
|
|||
|
||||
async function main() {
|
||||
const mollie = createMollieClient({ apiKey: mollieKeys.leden });
|
||||
exportMollieCustomers(mollie);
|
||||
exportMolliePayments(mollie);
|
||||
const customers = await exportMollieCustomers(mollie);
|
||||
const customerObj = Object.fromEntries(customers.map(({ id, name, email, createdAt }) => ([id, { name, email, createdAt }])));
|
||||
const payments = await exportMolliePayments(mollie, customerObj);
|
||||
}
|
||||
|
||||
async function exportMollieCustomers(mollie: MollieClient) {
|
||||
async function exportMollieCustomers(mollie: MollieClient): Promise<{[k: string]: any}[]> {
|
||||
const page$ = mollie.customers.list();
|
||||
const list = (await listAll(page$, 500))
|
||||
.map(({ id, name, email, createdAt }) => ({ id, name, email, createdAt }));
|
||||
writeFileSync('./data/customers.csv', unparse(list));
|
||||
return list;
|
||||
}
|
||||
|
||||
async function exportMolliePayments(mollie: MollieClient) {
|
||||
async function exportMolliePayments(mollie: MollieClient, customerObj: { [id: string]: { name: string, email: string, createdAt: string } }): Promise<{[k: string]: any}[]> {
|
||||
const page$ = mollie.payments.list();
|
||||
const list = (await listAll(page$, 500))
|
||||
// const list = Array.from(await page$)
|
||||
.map(({ id, createdAt, paidAt, description, method, status, isCancelable, sequenceType, profileId, customerId, mandateId, details, amount, settlementAmount, amountRefunded, amountRemaining }) => ({ id, createdAt, paidAt, description, method, status, isCancelable, sequenceType, profileId, customerId, mandateId, ...mapKeys(prepend('details.'))(details), ...mapKeys(prepend('amount.'))(amount), ...mapKeys(prepend('settlementAmount.'))(settlementAmount), ...mapKeys(prepend('amountRefunded.'))(amountRefunded), ...mapKeys(prepend('amountRemaining.'))(amountRemaining) }));
|
||||
.map(({ resource, id, createdAt, paidAt, description, method, status, isCancelable, sequenceType, profileId, customerId, mandateId, details, amount, settlementAmount, amountRefunded, amountRemaining }) => ({ resource, id, createdAt, paidAt, description, method, status, isCancelable, sequenceType, profileId, customerId, mandateId, ...mapKeys(prepend('details.'))(details), ...mapKeys(prepend('amount.'))(amount), ...mapKeys(prepend('settlementAmount.'))(settlementAmount), ...mapKeys(prepend('amountRefunded.'))(amountRefunded), ...mapKeys(prepend('amountRemaining.'))(amountRemaining), ...mapKeys(prepend('customer.'))(customerObj[customerId || '']) }));
|
||||
writeFileSync('./data/payments.csv', unparse(list));
|
||||
return list;
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
Loading…
Reference in New Issue