← Questions

Transaction fees from a CSV of payments

0
StripeCodingLast asked Apr 2026

A coding interview question asked in Stripe's technical phone screen, last asked Apr 2026. It tests parsing, csv and payments.

A payment processor charges a percentage fee on each transaction. The rate depends on the payment type and the transaction's status. You get the fee rules and the transactions as CSV text; compute each transaction's fee and the total.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • compute_fees(transactions_csv: str, fee_rules: dict[tuple[str, str], int]) -> tuple[list[int], int]
  • transactions_csv has the header transaction_id,user_id,payment_type,status,amount_cents and one transaction per line.
  • fee_rules maps (payment_type, status) to a rate in basis points (1 bp = 0.01%).
  • fee = floor(amount_cents * rate_bps / 10000). A transaction with no matching rule pays 0.
  • Return the fees in input order and their sum.

Example

fee_rules = {("card", "paid"): 290, ("card", "refunded"): 100, ("bank_transfer", "paid"): 80}

transaction_id,user_id,payment_type,status,amount_cents
t1,u1,card,paid,2599             -> 75     # 2599 * 290 / 10000 = 75.37
t2,u2,bank_transfer,paid,50000   -> 400
t3,u1,card,refunded,1000         -> 10
t4,u3,wallet,paid,700            -> 0      # no rule for (wallet, paid)

compute_fees(...)  ->  ([75, 400, 10, 0], 485)

Constraints

  • Up to 10^5 rules and 10^5 transactions; 0 <= amount_cents <= 10^9; 0 <= rate_bps <= 10000.
  • Use integer arithmetic only, no floats.

Clarifying questions

  • Is the fee rounded down, to nearest, or per a banker's rule? Per transaction or on the total?
  • What should happen to a malformed line or an unknown status: skip, fail, or charge zero?
  • Does the rate also depend on the provider (for example the card network)?
  • Should results be grouped per user?

What a strong answer covers

  • A dict keyed by (payment_type, status); one pass over the rows: O(n + r) time.
  • Integer math so rounding is exact; a note on overflow in languages with fixed-width integers.
  • Robust CSV handling (header, blank lines, whitespace, quoted fields) using a real CSV parser.
  • Keeping the input order and testing the empty input, missing rules and boundary amounts.

Follow-ups

  • Return the total fees per user, sorted by user.
  • Refunds return part of the original fee, and disputes add a fixed charge. Model both.
  • Transactions arrive in several currencies with different minor units.
  • Rules gain a provider and a fallback: a rule for (type, any status) applies when no exact rule exists.

Where it's asked

  • Stripe · Technical phone screen · Last asked Apr 202660 min · One realistic task in parts, in a project editor (CoderPad project mode or HackerRank Projects) with several files and tests

What it tests

parsing · csv · payments

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding