Replay Payment Lifecycle Events and Compute Refundable Balance

Last updated: November 29, 2026

Quick Overview

Given an ordered list of payment modification events (AUTHORISE, CAPTURE, CANCEL, REFUND) with amounts, replay them through a state machine, reject the first illegal event, and report the final state, captured amount and remaining refundable amount.

Adyen
Coding & Algorithms
Software Engineer
Adyen
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given an ordered list of payment modification events (AUTHORISE, CAPTURE, CANCEL, REFUND) with amounts, replay them through a state machine, reject the first illegal event, and report the final state, captured amount and remaining refundable amount.

Every Adyen payment moves through authorisation, captures, cancellations and refunds, often with partial amounts arriving from the merchant out of convenience order. The interviewer looks for an explicit state model, invariant checks like no over-capture and no over-refund, and clear error reporting tied to the offending event.

What the Interviewer Expects
  • Define states and allowed transitions explicitly before coding
  • Track authorised, captured and refunded totals as integers
  • Enforce invariants: captured at most authorised, refunded at most captured
  • Report which event failed and why
  • Discuss how this maps to persistent storage and concurrency
Key Topics to Cover
Finite state machines
Payment lifecycle
Invariants
Partial capture and refund
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you add chargebacks and chargeback reversals?
  • Events can arrive concurrently from two API calls. How do you prevent a double refund in the database?
  • An authorisation expires after seven days. How does that fit into the model?
  • How would you make replay idempotent when the same event id is delivered twice?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

States: NEW, AUTHORISED, PARTIALLY_CAPTURED, CAPTURED, CANCELLED, REFUNDED. A payment is authorised once. Captures may be partial and repeated until the authorised amount is reached. Cancel is only al...

High-Level Design

Keep three counters and one state variable. Each event handler first checks the transition is legal for the current state, then checks the amount invariant, then mutates. Raising on the first illegal ...


Submit Your Answer
Markdown supported

Related Questions