Canceling a Charge/invoice
An invoice or a specific Charge can be canceled when--
- The associated Enrollment is canceled.
- We want to issue a credit or refund for a Charge, like a fee we've decided to reverse.
To do this, we usually reverse complete Charges with a new opposing Charge. In some cases -- according to a Charge's "cancel behavior" -- we may take a different or no action at all.
Avoid confusion -- we use U.S. English spellings "cancel", "canceled", and "cancellation(s)".
This document is a spec. If the implementation is different from what is defined here, this spec takes precedence and the implementation is wrong. If you're changing the implementation, be sure to update this spec. Thanks!
Cancel behaviors
There are 3 ways that a Charge can be canceled:
Refundable
A "refundable" Charge is fully reversible when canceled and the refunded money can be cashed out. (Eventually, this will happen automatically.)
Creditable
For now, "creditable" Charges are canceled identically to "refundable" Charges but the reversals are labeled "Credits" and are processed separately from refunds.
Non-refundable
A "non-refundable" Charge is not reversible. When canceled, nothing happens -- the Charge is left in place.
Issuing a cancellation
Check if Charges can be deleted directly
To simplify cancellation, we ignore the cancel behavior and delete Charges directly if there are no Payments for any Charge on the same invoice. This follows the principle that an invoice is only meaningful once money has moved.
If Charges are deleted directly, then cancellation is complete.
Cancel refundable Charges
When a refundable Charge from A to B is canceled, these Charges are reversed with a new Cost and Charge. Both the new Cost and Charge have the name Refund from [Payer A] and are from B to A.
When refunding multiple Charges, collate and directionally sum all Charges for each pair of Payers. For example,
- 2 Charges, each $10 from A to B, should be refunded as a single Charge of $20 from B to A.
- A Charge of $10 from A to B and a Charge of $5 from B to A is a "net Charge" of $5 from A to B and should be refunded as a Charge of $5 from B to A.
When refunding Charges, add a matching refund Cost so that the Sum of Costs = Sum of Charges.
Cancel creditable Charges
Follow the "Cancel refundable Charges", but the new Cost and Charge have the name Credit from [Payer A].
Do not combine refundable Charges and creditable Charges for the same pair of Payers into one reversal Charge.
Mark the Charge as canceled
To prevent canceled Charges from being canceled again (which could allow for double refunds), once a Charge is canceled, the CANCELED tag is attached.
Attach the CANCELED tag for all Charges, even non-refundable Charges where no action was taken.
Run automatic completion
At this point, existing Charges have been updated and new Costs and Charges have been created.
To create payments, run automatic completion to automatically fulfill Charges in most case. Automatic completion will actually move money to complete the cancellation.