Merchant Fee Aggregation
EasyParsing · Stripe
Compute the processing fees each merchant owes from a CSV export of transactions.
csv_lines[0] is a header naming the columns; every other line is one transaction with the same columns in the same order. The header always contains merchant_id, amount_cents, payment_method, and status, but the column order varies between exports and extra columns (such as id or currency) may be present. Fields never contain commas, quotes, or surrounding spaces.
pricing maps each payment method to [basis_points, fixed_cents]. One basis point is 0.01%.
- Only transactions whose
statusis exactlysucceededincur a fee. - The fee for one transaction is
floor(amount_cents * basis_points / 10000) + fixed_cents, computed per transaction (round each fee down before summing). - Every
payment_methodthat appears is inpricing.
Return [merchant_id, total_fee_cents] for every merchant with at least one succeeded transaction, sorted by merchant_id.
Example 1
- Input:
- csv_lines = ["status,amount_cents,id,merchant_id,payment_method", "succeeded,1000,tx_1,acme,card", "failed,5000,tx_2,acme,card", "succeeded,2550,tx_3,bolt,ach", "succeeded,999,tx_4,acme,wallet"], pricing = {"card": [290, 30], "ach": [80, 0], "wallet": [340, 0]}
- Output:
- [["acme", 92], ["bolt", 20]]
- Explanation
- The header puts
statusfirst, so columns must be looked up by name. acme pays 1000 * 290 // 10000 + 30 = 59 on the card charge and 999 * 340 // 10000 = 33 on the wallet charge, totaling 92. The failed charge is free. bolt pays 2550 * 80 // 10000 = 20.
Example 2
- Input:
- csv_lines = ["merchant_id,payment_method,amount_cents,status", "m,ach,99,succeeded", "m,ach,99,succeeded"], pricing = {"ach": [80, 0]}
- Output:
- [["m", 0]]
- Explanation
- Each fee is 99 * 80 // 10000 = 0 on its own, so the total is 0, even though flooring the combined 198 * 80 / 10000 would give 1. The merchant still appears because it had succeeded transactions.
Example 3
- Input:
- csv_lines = ["merchant_id,amount_cents,payment_method,status", "m1,100,card,pending", "m2,100,card,refunded"], pricing = {"card": [290, 30]}
- Output:
- []
- Explanation
- Neither transaction succeeded, so no merchant owes a fee and the result is empty.
Constraints
0 <= csv_lines.length <= 10^50 <= amount_cents <= 10^120 <= basis_points <= 10000,0 <= fixed_cents <= 1000- Every data line has the same number of fields as the header