Match an incoming payment to its invoice using the payment's memo line.
Stripe's Invoicing product lets businesses send invoices, and standalone payments sometimes need to be reconciled with a customer's open invoices. Write a program that matches an incoming payment to its invoice.
Payment format: paymentId,amount,memo, with the amount in USD minor units ($1.00 = 100) and a memo like Paying off: {INVOICE}.
Invoice format: invoiceId,dueDate,amountDue, with the amount in USD minor units.
Example: f("payment5,1000,Paying off: invoiceC", ["invoiceA,2024-01-01,100", "invoiceB,2024-02-01,200", "invoiceC,2023-01-30,1000"]) returns "payment5 pays off 1000 for invoiceC due on 2023-01-30".
In another version the memo reference is XXXX:invoice_id and the output contains payment_name, amount, due_date and invoice_id.
Expect follow-ups like
- If the memo has no invoice_id or it doesn't match, match by amount instead, choosing the invoice with the earliest due_date when several match.
- Add an integer forgiveness so a payment matches when invoice_amount - forgiveness <= payment_amount <= invoice_amount + forgiveness, and include any difference in the output.
Format · A virtual onsite coding round in three parts, each building on the previous one.
Also asked as · Match a payment to an invoice using the invoice ID in the payment memo.
Community answers
Related courses


