Chargeback Validation Summary
MediumParsing · Stripe
You receive a raw export of dispute records, one string per row, in the format:
text
dispute_id,merchant_id,amount_cents,statusSplit each row on commas and trim surrounding whitespace from every field. A row is valid when all of these hold:
- it has exactly 4 fields;
dispute_idandmerchant_idare non-empty;amount_centsis a non-negative integer written with digits only: no sign, no decimal point, and no leading zeros ("0"itself is fine,"007"is not);statusis exactly one ofopen,lost,won,withdrawn(case-sensitive);- no earlier valid row used the same
dispute_id. An invalid row does not reserve its id, so a later valid row with that id is still accepted.
Invalid rows are skipped. Return [valid_count, lost_amount_cents, withdrawn_ids] where lost_amount_cents is the sum of amount_cents over valid lost rows and withdrawn_ids is the list of dispute_ids of valid withdrawn rows, sorted lexicographically.
Example 1
- Input:
- rows = ["dp_9,acct_1,1200,lost", "dp_3,acct_2,450,withdrawn", "dp_4,acct_2,-20,lost", "dp_5,acct_1,300", "dp_1, acct_3 , 75 ,withdrawn", "dp_6,acct_1,999,Lost"]
- Output:
- [3, 1200, ["dp_1", "dp_3"]]
- Explanation
dp_4has a negative amount,dp_5has only three fields, anddp_6usesLost, which is not an allowed status, so those three are skipped. The three valid rows give a lost total of 1200 and withdrawn idsdp_1anddp_3(whitespace arounddp_1's fields is trimmed).
Example 2
- Input:
- rows = ["d1,m1,abc,lost", "d1,m1,40,lost", "d1,m2,60,lost", "d2,m1,0,won"]
- Output:
- [2, 40, []]
- Explanation
- The first
d1row is invalid (non-numeric amount), so it does not reserved1. The secondd1row is valid and adds 40. The third reusesd1after a valid row and is skipped.d2is valid with amount 0 (statuswonadds nothing), giving 2 valid rows.
Example 3
- Input:
- rows = ["a,m,007,lost", "b,m,12.50,lost", "c,m,+5,lost", "d,m,10,lost"]
- Output:
- [1, 10, []]
- Explanation
007has leading zeros,12.50is not an integer, and+5has a sign, so onlydis valid, contributing 10.
Constraints
0 <= rows.length <= 10^5- Each row has at most 200 characters
- Rows contain no quoted fields