← Questions

Payment intents: create, update, confirm, fail and refund

0
StripeCodingLast asked Apr 2025

A payment intent tracks one payment from creation to completion as a small state machine: it waits for action, moves to processing when a payment is attempted, and becomes completed when it succeeds. Process a list of commands and print every merchant's final balance. Commands that don't fit an intent's current state, or that name unknown merchants or intents, do nothing.

  1. Initialize merchants with a starting balance, create intents for a merchant and amount, attempt them and mark them succeeded; success credits the merchant.
  2. Allow updating an intent's amount while it still waits for action.
  3. Add failure (a processing intent goes back to waiting for action) and refunds of completed intents, which debit the merchant.
  4. Commands now carry timestamps, and a merchant may set a refund window: refunds later than that after the payment succeeded are refused.
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