Authorization Reversal Holds
MediumSimulation · Visa
When a card is authorized, the issuer places a hold on the cardholder's funds until the merchant captures or reverses it. Process a list of events, each [type, auth_id, card, amount], in order:
"auth": addamountto the open hold of authorizationauth_id, which belongs tocard. The first"auth"for an id opens it with a hold of0before adding; later"auth"events for the same id (incremental authorizations) add to the same hold."reversal"or"capture": reduce the open hold ofauth_idbyamount. A hold never goes below0; any excess is ignored.- A
"reversal"or"capture"for anauth_idthat has not been opened by an earlier"auth"is ignored.
All events for the same auth_id carry the same card. A card can have several authorizations.
Return a list of [card, total_open_hold] rows, one per card that appeared in at least one "auth" event, where total_open_hold is the sum of the final holds of all its authorizations. Sort rows by card ascending. Cards whose total is 0 are still included.
Example 1
- Input:
- events = [["auth", "a1", "c1", 50], ["auth", "a2", "c2", 30], ["capture", "a1", "c1", 20], ["reversal", "a2", "c2", 40], ["auth", "a1", "c1", 10]]
- Output:
- [["c1", 40], ["c2", 0]]
- Explanation
a1goes 50, then 30 after the capture, then 40 after the incremental auth.a2is reversed by 40 against a 30 hold, which floors at 0, butc2is still listed.
Example 2
- Input:
- events = [["reversal", "a9", "c9", 5], ["auth", "a1", "c1", 10], ["auth", "a9", "c9", 7]]
- Output:
- [["c1", 10], ["c9", 7]]
- Explanation
- The reversal for
a9arrives beforea9exists, so it is dropped. The later auth opensa9with the full 7.
Example 3
- Input:
- events = [["auth", "a1", "c1", 10], ["auth", "a2", "c1", 5], ["capture", "a2", "c1", 3]]
- Output:
- [["c1", 12]]
- Explanation
- Card
c1holds 10 ona1and 5 - 3 = 2 ona2, for a total of 12.
Constraints
0 <= events.length <= 10^5typeis"auth","reversal", or"capture"auth_idandcardare non-empty strings; all events for oneauth_iduse the samecard0 <= amount <= 10^9