Uploaded image for project: 'mod-invoice'
  1. mod-invoice
  2. MODINVOICE-109

Create payment or credit when Invoice marked as 'Paid'

    XMLWordPrintable

Details

    Description

      Overview

      When an invoice is processed payments or credits need to be created again the Funds that are responsible for accounting for the invoices value.

      Approach:

      Current assumption is that payments will be created for all positive fund distributions and credits will be created for all negative fund distributions.

      1. Determine the expected number of payments & credits.
      2. Check if the payments have already been processed. If yes, go to step 5
        • use GET /finance/transactions?query=invoiceInvoiceId==<invoiceId>.
      3. Create payment_summary
        • Use POST /finance/invoice-payment-summaries
      4. Generate and send payments & credits for processing
        • One payment or credit for each fundDistribution for each invoiceLine (see example below)
        • Use POST /finance/payments and POST /finance/credits
      5. Update invoice status to Paid.

      NOTE: If any of these steps fail, an appropriate error message should be returned to the client - saying that paying the invoice failed, and they can retry.
      NOTE: The transactions can happen in parallel. If needed we can look at batching these in the future but that's outside the scope of this story.

      Example of Generating Payments/Credits

      Invoice XYZ

      • invoiceLine A
        • Fund Distro $50, USHIST
        • Fund Distro $25, HIST
      • invoiceLine B
        • Fund Distro $25, LAW
        • Fund Distro $25, MATH
        • Fund Distro $25, HIST
      • invoiceLine C
        • Fund Distro -$10, USHIST

      InvoicePaymentSummary:

      • Invoice: XYZ
      • NumPayments: 6

      Payments:

      • $50 USHIST (Invoice: XYZ, InvoiceLine: A)
      • $25 HIST (Invoice: XYZ, InvoiceLine: A)
      • $25 LAW (Invoice: XYZ, InvoiceLine: B)
      • $25 MATH (Invoice: XYZ, InvoiceLine: B)
      • $25 HIST (Invoice: XYZ, InvoiceLine: B)

      Credits:

      • $10 USHIST (Invoice: XYZ, InvoiceLine: C)

      Additional Background/Context/Details

      See related section/flowchart on this spike page
      See the wiki for additional details

      Acceptance criteria:

      • The business logic described above has been added
      • Unit tests are updated
      • API tests are updated

      TestRail: Results

        Attachments

          Issue Links

            Activity

              People

                siarhei_hrabko Siarhei Hrabko
                dennisbridges Dennis Bridges
                Siarhei Hrabko Siarhei Hrabko
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  TestRail: Runs

                    TestRail: Cases