Problem · String

Transaction Fee Calculator - Status Gate and Regional Rates

Learn this problem
EasyStripe logoStripeFULLTIMEPHONE SCREEN
See Stripe hiring insights

Problem statement

Compute the processing fee for each transaction in a CSV and emit a result CSV.

Input: csvData is a single CSV string. The first row is the header; the canonical columns are id,reference,amount,currency,date,merchant_id,buyer_country,transaction_type,payment_provider,status. amount is an integer in cents. payment_provider is one of card, klarna, bank_transfer. status is one of payment_completed, payment_failed, payment_pending.

Fee rules: the fee for a row is floor(amount * rate + fixed) using these rates by (buyer_country, payment_provider):

  • Standard (any country except Ireland): card = 2.9% + 30, klarna = 3.5% + 50, bank_transfer = 0.8% + 0.
  • Ireland (buyer_country == "ie"): card = 1.9% + 20, klarna = 2.5% + 40, bank_transfer = 0.6% + 0. Any other country falls back to the standard rates.

A fee is only charged when status == "payment_completed"; for failed or pending transactions the fee is 0. Always floor the final fee to an integer (truncate toward zero).

Output: return a String[] whose first element is the header "id,transaction_type,payment_provider,fee" and then one line "id,transaction_type,payment_provider,fee" per input transaction, in input order.

Function

calculateFees(csvData: String) → String[]

Examples

Example 1

csvData = "id,reference,amount,currency,date,merchant_id,buyer_country,transaction_type,payment_provider,status\npy_1,ref1,1000,eur,2026-01-01,m1,ie,payment,card,payment_completed\npy_2,ref2,2500,eur,2026-01-01,m1,ie,payment,card,payment_failed\npy_3,ref3,3400,eur,2026-01-01,m2,ie,payment,klarna,payment_completed\npy_4,ref4,5000,eur,2026-01-01,m2,fr,payment,bank_transfer,payment_completed\npy_5,ref5,2000,eur,2026-01-01,m3,ie,payment,card,payment_pending"return = ["id,transaction_type,payment_provider,fee", "py_1,payment,card,39", "py_2,payment,card,0", "py_3,payment,klarna,125", "py_4,payment,bank_transfer,40", "py_5,payment,card,0"]
py_1: Ireland card, completed -> 1000*0.019 + 20 = 39. py_2: failed -> 0. py_3: Ireland klarna, completed -> 3400*0.025 + 40 = 125. py_4: France falls back to the standard bank_transfer rate -> 5000*0.008 + 0 = 40. py_5: pending -> 0.

Example 2

csvData = "id,reference,amount,currency,date,merchant_id,buyer_country,transaction_type,payment_provider,status\npy_1,ref1,1000,usd,2026-01-01,m1,us,payment,card,payment_completed\npy_2,ref2,2500,usd,2026-01-01,m1,us,payment,card,payment_completed\npy_3,ref3,3400,usd,2026-01-01,m2,us,payment,klarna,payment_completed\npy_4,ref4,5000,usd,2026-01-01,m2,us,payment,bank_transfer,payment_completed"return = ["id,transaction_type,payment_provider,fee", "py_1,payment,card,59", "py_2,payment,card,102", "py_3,payment,klarna,169", "py_4,payment,bank_transfer,40"]
All US (standard rates), all completed. py_1: 1000*0.029 + 30 = 59. py_2: 2500*0.029 + 30 = 102.5 floored to 102. py_3: 3400*0.035 + 50 = 169. py_4: 5000*0.008 + 0 = 40. (This reproduces the page's Part-1 standard-rate example.)

Constraints

  • First CSV row is the header; amount is integer cents.
  • Fee = floor(amount * rate + fixed) by (buyer_country, payment_provider); Ireland has its own rates, all other countries use the standard rates.
  • Fee is 0 unless status == "payment_completed".
  • Floor (truncate) the final fee to an integer.
  • Return a String[]: header "id,transaction_type,payment_provider,fee" then one line per transaction in input order.

More Stripe problems

drafts saved locally
public String[] calculateFees(String csvData) {
  // write your code here
}
csvData"id,reference,amount,currency,date,merchant_id,buyer_country,transaction_type,payment_provider,status\npy_1,ref1,1000,eur,2026-01-01,m1,ie,payment,card,payment_completed\npy_2,ref2,2500,eur,2026-01-01,m1,ie,payment,card,payment_failed\npy_3,ref3,3400,eur,2026-01-01,m2,ie,payment,klarna,payment_completed\npy_4,ref4,5000,eur,2026-01-01,m2,fr,payment,bank_transfer,payment_completed\npy_5,ref5,2000,eur,2026-01-01,m3,ie,payment,card,payment_pending"
expected["id", "transaction_type", "payment_provider", "fee", "py_1", "payment", "card", "39", "py_2", "payment", "card", "0", "py_3", "payment", "klarna", "125", "py_4", "payment", "bank_transfer", "40", "py_5", "payment", "card", "0"]
checking account