Skip to content

Commit

Permalink
feat: update paymentFields to be object mapped instead of array
Browse files Browse the repository at this point in the history
  • Loading branch information
KenLSM committed Feb 2, 2024
1 parent 3c0ebcd commit 922b6f6
Showing 1 changed file with 16 additions and 55 deletions.
71 changes: 16 additions & 55 deletions src/app/modules/payments/payment.service.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
: '-',
}
}

0 comments on commit 922b6f6

Please sign in to comment.