Settlement
Settlement is the process of transferring funds from the escrow to the receiver. The facilitator handles this automatically.The escrow settlement is powered by Base’s Commerce Payments Protocol, implementing the authorize-capture pattern used by traditional payment processors like Stripe and Adyen.
Capture Strategy
The facilitator uses a batched capture strategy to minimize gas costs:| Trigger | Action |
|---|---|
| Pending > $1 | Batch capture (cron job) |
| Expiry < 2h | Batch capture (cron job) |
| Expiry < 30min | Sync capture (per request) |
Captures are batched to reduce gas costs. Multiple pending amounts from different sessions are captured in a single transaction when possible.
Settlement Flow
Exact vs Escrow Settlement
Exact Scheme
1 transaction per request
- ERC-3009
transferWithAuthorization - Immediate on-chain transfer
- Higher gas cost per call
- Best for infrequent, high-value calls
Escrow Scheme
1 transaction to create session
- Session creation: 1 tx
- Session usage: 0 tx (off-chain)
- Batch capture: amortized gas
- Best for frequent, low-value calls
Session Timeline
Each session has two critical timestamps:| Timestamp | Default | Meaning |
|---|---|---|
authorizationExpiry | +1 hour | Deadline for facilitator to capture |
refundExpiry | +25 hours | Only affects refund() function (for captured amounts) |
refundExpiry does NOT affect reclaim. The payer can call reclaim() on the contract anytime after authorizationExpiry - there is no upper time limit.Who Can Do What, When
Before authorizationExpiry
| Actor | Can Do | How |
|---|---|---|
| Facilitator | Capture pending amounts | Automatic (cron job) |
| User | Reclaim unused funds | API: POST /api/payer/sessions/{id}/reclaim |
- Facilitator captures any pending amount first → receiver gets paid
- Facilitator voids remaining → user gets refund
After authorizationExpiry
| Actor | Can Do | How |
|---|---|---|
| Facilitator | ❌ Cannot capture | Authorization expired |
| User | Reclaim ALL remaining | API or direct contract call |
- Pending amounts are forfeited (receiver loses them)
- User gets back:
authorized - captured(everything not yet captured)
The reclaim API works both before and after
authorizationExpiry. The difference is that after expiry, the facilitator cannot capture pending amounts first - they are forfeited.Reclaim API
The reclaim API works both before and after
authorizationExpiry. Before expiry, it captures pending amounts first (receiver gets paid). After expiry, pending amounts are forfeited and you get back everything not yet captured.Balance Visualization
Understanding how a session balance changes over time ($10 deposit example):Gas Costs
| Operation | Gas (approx) | Who Pays |
|---|---|---|
| Session creation | ~150k | Facilitator |
| Batch capture | ~80k per session | Facilitator |
| Reclaim (via API) | ~100k | Facilitator |
| Reclaim (direct) | ~80k | User |
Gas costs are covered by the facilitator and factored into the service fee.
Refund vs Reclaim
These are two different contract functions - don’t confuse them:| Function | Purpose | Who Calls | When |
|---|---|---|---|
reclaim() | Get back uncaptured funds | Payer | After authorizationExpiry |
refund() | Get back already-captured funds | Operator (facilitator) | Before refundExpiry |
Reclaim (Implemented ✅)
For unused session balance that was never captured:reclaim() directly on the contract after authorizationExpiry to get back any amount that wasn’t captured.
Refund (Not Yet Implemented 🔜)
What is a refund? When an API provider (receiver) voluntarily returns money they already received back to the user. When would you need this?| Scenario | Example |
|---|---|
| Service failure | Your API returned an error but the user was still charged |
| Goodwill gesture | User complains, you decide to refund as good customer service |
| Accidental overcharge | You charged 0.50 |
| Partial refund | User paid for 10 API calls, only 7 worked |
Receiver-initiated only. Only the API provider (receiver) can trigger refunds. The facilitator executes the request - it does not arbitrate disputes.If you’re a payer with a complaint, contact the API provider directly.
How Refund Will Work (When Implemented)
| Constraint | Value |
|---|---|
| Who can request | Receiver (API provider) only |
| Facilitator role | Executes only (no arbitration) |
| Max refund amount | Total captured for that session |
| Time limit | Before refundExpiry (default: +25 hours from session creation) |
After
refundExpiry, the contract’s refund() function is locked and refunds are no longer possible through the escrow system.