From 922b6f6a4e76306f505a32b5a1e90b9093729a53 Mon Sep 17 00:00:00 2001 From: Ken Date: Fri, 2 Feb 2024 16:58:50 +0800 Subject: [PATCH] feat: update paymentFields to be object mapped instead of array --- .../modules/payments/payment.service.utils.ts | 71 +++++-------------- 1 file changed, 16 insertions(+), 55 deletions(-) diff --git a/src/app/modules/payments/payment.service.utils.ts b/src/app/modules/payments/payment.service.utils.ts index 96603bea59..2807d7468f 100644 --- a/src/app/modules/payments/payment.service.utils.ts +++ b/src/app/modules/payments/payment.service.utils.ts @@ -4,59 +4,20 @@ import { centsToDollars } from '../../../../shared/utils/payments' import { getPaymentInvoiceDownloadUrlPath } from '../../../../shared/utils/urls' export const getPaymentFields = (payment: IPaymentSchema) => { - return [ - { - _id: '__PAYMENT__STATUS', // Payments will have prefixes - question: 'Payment status', // follows csv title - answer: payment.status, // value as per csv - fieldType: 'textfield', // all payment columns are textfields - }, - { - _id: '__PAYMENT__PAYER', - question: 'Payer', - answer: payment.email, - fieldType: 'textfield', - }, - { - _id: '__PAYMENT__PROOF_OF_PAYMENT', - question: 'Proof of Payment', - answer: getPaymentInvoiceDownloadUrlPath(payment.formId, payment._id), - fieldType: 'textfield', - }, - { - _id: '__PAYMENT__INTENT_ID', - question: 'Payment intent ID', - answer: payment.paymentIntentId, - fieldType: 'textfield', - }, - { - _id: '__PAYMENT__AMOUNT', - question: 'Payment amount', - answer: centsToDollars(payment.amount), - fieldType: 'textfield', - }, - { - _id: '__PAYMENT__PRODUCT_SERVICE', - question: 'Product/service', - answer: - payment.products - ?.map(({ data, quantity }) => `${data.name} x ${quantity}`) - .join(', ') || '-', - fieldType: 'textfield', - }, - { - _id: '__PAYMENT__DATETIME', - question: 'Payment date and time', - answer: payment.completedPayment?.paymentDate ?? '-', - fieldType: 'textfield', - }, - { - _id: '__PAYMENT__TRANSACTION_FEE', - question: 'Transaction fee', - answer: payment.completedPayment?.transactionFee - ? centsToDollars(payment.completedPayment.transactionFee) - : '-', - fieldType: 'textfield', - }, - ] + return { + type: 'payment_charge', + status: payment.status, + payer: payment.email, + url: getPaymentInvoiceDownloadUrlPath(payment.formId, payment._id), + paymentIntent: payment.paymentIntentId, + amount: centsToDollars(payment.amount), + productService: + payment.products + ?.map(({ data, quantity }) => `${data.name} x ${quantity}`) + .join(', ') || '-', + dateTime: payment.completedPayment?.paymentDate ?? '-', + transactionFee: payment.completedPayment?.transactionFee + ? centsToDollars(payment.completedPayment.transactionFee) + : '-', + } }