I ran into an issue (causing us to overpay an ACH split direct deposit).
When mantle.account.PaymentServices.create#InvoicePayment is called with a “false” amount (be it zero/null, etc.)
It assumes the desire is to create a payment for the the unpaid invoice amount. It specifically calls mantle.account.InvoiceServices.get#InvoiceTotal to acquire the unpaid invoice amount.
This amount is totaled using the payment applications (mantle.account.payment.PaymentApplication) matching invoiceId or toInvoiceId.
That is fine and expected behavior.
But, if forInvoiceId is set on the payment, no PaymentApplication is generated, as it will generate that later when the payment is marked Delivered or Confirmed (i.e. it is delayed).
When doing a split direct deposit, we had a customer define a rate and flat amount of 0 on their secondary bank account. When payments were being produced it allocated the full first amount, as it should have done. On the second payment, it allocated the full invoice amount (not what would end up being the unpaid invoice amount). These payments were direct deposited to the employee even though there is a balance left on the payment. I take responsibility for allowing that to get through.
We could adjust get#InvoiceTotal to further inspect payments with a forInvoiceId, but just because they are earmarked for that doesn’t mean they will have to be applied to that invoice…so that seems poor.
In the end, we left mantle’s implementation alone, changed the edit screen to disallow creating a $0 payment, changed the split direct deposit allocation to skip $0 payments, and for good measure now inquire about the amount create#InvoicePayment creates a payment for to make sure it doesn’t happen again (fairly overkill, but clawing back money from employees who like the bank error in their favor is sometimes more difficult than it would seem).
It is plausible mantle’s could be changed instead to instead check against null…and reject $0 payments, but I have a suspicion existing logic may at least accidentally pass a 0 in, and which case it seems safest to leave that alone.
Anyway, this is more of a “heads up”, passing $0 to create#InvoicePayment could conceivably cause you grief if you make multiple payments towards the same invoice while any of the payments have not been applied to the invoice.