← Questions
Payment ledger with partial refunds and date queries
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's onsite coding (debug, integrate, build) round, last asked Apr 2026. It tests design, hash map and date parsing.
Build a small payment ledger driven by text commands:
- record a payment with an ID, a UTC timestamp and an amount, rejecting a malformed timestamp or a duplicate ID;
- refund part or all of a payment, any number of times, never more than it was worth in total;
- report net revenue (payments minus refunds);
- list the IDs of payments made on a given date, or between two dates, in the order they were recorded, rejecting malformed dates.
Return one result for each command. A fully refunded payment still shows up in date queries. Think about how to index payments by date so the queries don't scan everything.
Clarifying questions
- What is the exact command syntax, and what should each command print, including errors?
- What timestamp format is expected (ISO 8601 with
Z?), and is a date such as February 30 malformed? - Is a date range inclusive on both ends, and are dates read in UTC?
- Are amounts integer cents? Are zero or negative payments rejected?
- Is a refund for an unknown payment an error? Is a refund larger than what is left rejected in full?
What a strong answer covers
- A parser that sends each command to its handler and returns one result per command, errors included, without crashing on bad input.
- A payment record with id, timestamp, amount and amount refunded so far; a refund is accepted only while the refunded total stays within the original amount; net revenue kept as a running total.
- Strict validation of timestamps and dates with a real date parser, not only a regular expression.
- A date index from day to the ids recorded on that day, in recording order; a range query walks the days in range and returns ids in recording order (keeping a sequence number per payment), instead of scanning every payment.
- Tests: duplicate id, malformed timestamp, over-refund, a fully refunded payment still in a date query, an empty range.
Follow-ups
- Several currencies.
- Persist the ledger and survive a crash midway through a command.
- Refund ids so a repeated refund command is applied once.
- Report by the merchant's local date instead of UTC.
Where it's asked
- Stripe · Onsite coding: debug, integrate, build · Last asked Apr 202660 min · Project editor with starter code and tests: fix bugs in an unfamiliar codebase, wire an external API spec into a service, or complete a skeleton in parts · Varies by session: some onsites have one AI-assisted session and an integration session without AI
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
