Skip to main content
A support agent issues refunds at Stripe from customer conversations. Small ones should run without a person, larger ones should wait for one, and nothing above a ceiling should run at all, whatever the customer said.

The policy

Amounts are integer minor units. Both ends of each band are bound, because an upper bound alone lets a negative amount through, and a refund of a negative amount is a charge.
runnable

The code

runnable file=main.py

What the agent sees

Two calls reached Stripe. The refusal for €20,000 names the rule that decided it, and the duplicate names nothing but the effect key, refund:txn_1, which had already committed.

The receipt

runnable
Four receipts: allow/committed, approve/committed with the approver, deny/denied, and allow/blocked for the duplicate.

When an AMBIGUOUS appears

A refund whose reply was lost is AMBIGUOUS and a retry is refused. Look up the payment in the Stripe dashboard, then ctrlrun resolve refund:txn_N --committed or --failed. A reconcile hook that queries stripe.Refund.list(payment_intent=...) does the same automatically: Reconcile against the remote.

Next