You are given a CSV-like multi-line string representing transactions with columns:
id,reference,amount,currency,date,merchant_id,buyer_country,transaction_type,payment_provider,status
You must compute and print fee lines in the format:
id, transaction_type, payment_provider, fee
with one output line per input row (excluding header), preserving order.
Part 1 — Provider-based fee
You are given a map provider_fee_rules describing how to compute a fee for each payment_provider.
Rules:
-
If
status
is not a successful status (e.g.,
payment_failed
), fee is
0
.
-
Otherwise fee is computed based on the provider’s rule (e.g., percentage + fixed, or tiered). The exact rule structure will be provided in the interview.
Part 2 — Support multiple transaction types
Extend Part 1 so that fee may depend on both transaction_type and payment_provider.
Part 3 — Country-based fee schedule with volume discounts
You are given:
-
A map
country_fee_rules[buyer_country] -> fee rule
(may override/extend provider rules).
-
A threshold
T
(number of successful transactions) after which a merchant receives a discount.
-
A discount definition (e.g., reduce percentage by X, or apply multiplier
d < 1
).
Requirements:
-
Discounts are computed
per merchant
(
merchant_id
) based on that merchant’s cumulative successful transaction count (or volume) up to the current transaction.
-
Output the computed fee for each row.
Notes
-
Specify how you parse
amount
(integer smallest unit) and how you round fees.
-
Aim for an efficient single pass over the rows while maintaining per-merchant aggregates.