CHARGEBACKS
A dispute is a state machine with a clock on every state
Emeka's bank files a chargeback on his ₦85,000 payment to Ojaline, and the acquirer takes ₦85,000 from Ojaline. The next day Bisi in support refunds ₦85,000 from Emeka's ticket. The bank then rules for Emeka. How much has Ojaline paid back?
A chargeback is the cardholder’s bank reversing a payment. The acquirer debits the amount from the merchant at once and passes it to the issuer; a win reverses the debit. The merchant accepts or sends evidence (a representment). The issuer can reject that and open pre-arbitration; then the scheme arbitrates. The dispute ends won or lost, and every stage that waits on someone has a deadline.
One processor’s guide says cardholders typically get 120 days to dispute and merchants usually 7 to 21 days to respond, depending on the network. Visa and Mastercard rules add pre-arbitration and arbitration stages; some processors stop before arbitration, and the same guide says Stripe does not support that phase. The rules differ and change, so the sim’s window is an illustrative parameter.
// any dispute notice
on('dispute.*', (n) => {
order.disputed = true;
ledger.book('chargeback', -n.amount); // a pre-arbitration notice books it again
});
// the refund button never reads order.disputed
// evidence goes in when someone runs the weekly "disputed orders" reportnone --inquiry--> inquiry --evidence (by due)--> inquiry_answered
none | inquiry | inquiry_answered --chargeback (debit once, store due)--> chargeback
chargeback --evidence (day ≤ due)--> represented
chargeback --accept--> lost
represented --issuer rejects--> pre_arbitration (same debit, new due)
pre_arbitration --evidence (day ≤ due)--> pre_arb_responded --> arbitration
represented | pre_arb_responded | arbitration --ruling--> won (debit reversed) | lost
chargeback | pre_arbitration, day > due --> lost
refund: refused while chargeback .. arbitration is open Watch the three invariants. In ONE “DISPUTED” FLAG, Ojaline pays back at most once goes red the moment Bisi’s refund lands on top of the chargeback, and reversals in the books = the acquirer's dispute debit goes red when the pre-arbitration notice books ₦85,000 again. Shrink the window and no response late goes red too. FIX: DISPUTE STATE MACHINE refuses the refund, answers from a due-date queue on day 16, and keeps one debit through pre-arbitration. FIX: ACCEPT, DON’T REFUND shows the right way to give the money back.
The double booking here is a state bug, not a retry: the pre-arbitration notice is a new, different message. Duplicate deliveries of the same notice are the idempotency lesson, and the payment’s own states before a dispute, up to capture and refund, are authorise, capture, refund. Inquiries mostly come from American Express and Discover; the same guide says Visa and Mastercard no longer use that phase.
The flag design answers disputes at a weekly review of disputed orders, on day 28 and day 42. Shrink the response window until the review misses the deadline. Then switch the sim to FIX: DISPUTE STATE MACHINE with the same window.
GOAL: the flag design loses the dispute by a missed deadline
Rewrite handle as the dispute state machine in the code tab. Return true if the event is accepted, false if not (and change nothing but the state). A chargeback debits its amount once (held); a pre-arbitration keeps the same debit. Evidence counts only if ev.day <= d.dueDay; any event that arrives after the due day of a chargeback or pre_arbitration first moves it to lost. A win returns the debit (held back to 0). Refunds are refused from chargeback onwards unless the dispute was won, and refunded + held never exceeds the amount.
Any merchant or platform that takes cards: marketplaces, wallets funded by card, subscriptions, travel. You meet it as dispute webhooks from the processor, a disputes queue in the back office, a refund button that must check for an open dispute, and a reconciliation where chargeback debits and reversals have to match the acquirer's statement. Card schemes also watch each merchant's dispute rate and put merchants with too many disputes into monitoring programmes.
“Design dispute handling for a payments platform.” Draw the states and who moves each one (issuer, merchant, scheme), store the deadline on each waiting state and alert from a queue ordered by it, book the debit once per dispute id, block refunds while a dispute is open and offer accept instead, and keep the evidence attached to the dispute so a response goes out in one submission.
USED IN
Chapters that build on this lesson.