# One payment, end to end (/docs/developers/payment-flow)

From a signed price to a release on QIE, with the real timings of a test-build order and every place it can turn into a refund.

<Diagram name="payment" alt="Sequence of a ₦500 MTN airtime order: signed price, payWithQIE, QIEDEX swap, OrderPaid, VTpass delivery, release, OrderReleased" caption="A ₦500 MTN airtime order on the test build (its receipt is on the Guide): paid 7:55:45, delivered 7:55:53, released 7:55:55." />

<Steps>
<Step>
### Price [#price]

`POST /api/quotes` checks the bill and the limits, converts naira to QUSDC at the reference rate less 1%, asks QIEDEX for an exact-out quote when paying in QIE, stores the order as `quoted` with a random 32-byte order id, and signs `Quote(payer, orderIds, amounts, expiry)` with EIP-712. The price expires in 60 seconds, which is also the swap's deadline.
</Step>

<Step>
### Pay [#pay]

The wallet simulates, then sends `payWithQIE(quote, sig)` with the "at most" QIE as value (gas limit = estimate × 1.2), or approves and sends `payWithQUSDC`. The app posts the transaction hash to `POST /api/orders/{id}/tx` at once and polls the order every 2 seconds.
</Step>

<Step>
### Held [#held]

The escrow emits `OrderPaid(orderId, payer, amount, asset)`. The indexer (every 4 seconds) or the fast path reads it, checks the payer and amount match the stored order, and moves it to `held`. That queues a `delivery.vend` job.
</Step>

<Step>
### Buy [#buy]

The worker writes a request id (Lagos `YYYYMMDDHHmm` + 12 random characters) and a dispatch stamp **before** calling VTpass, then calls `pay` once. It never retries a purchase blindly: an unclear answer becomes a requery.
</Step>

<Step>
### Settle [#settle]

Delivered → `release(orderId)`; failed → `refund(orderId, reason)`. Both go through the operator's signing lane, which first reads the order on chain to confirm it is still Held, stores the signed transaction, then broadcasts. `OrderReleased` or `OrderRefunded` moves the order to `released` or `refunded`.
</Step>

<Step>
### After [#after]

Released orders pay cashback and invite rewards; Telegram sends the notice. If nothing settles, the payer can `reclaim` after the delay.
</Step>
</Steps>

## Where it can turn [#where-it-can-turn]

| Moment | What happens |
| --- | --- |
| Price expires before payment | Order `expired`. A late `OrderPaid` before the on-chain expiry still counts |
| Provider closed, paused or out of float | Fails before buying, refunded |
| Provider says failed or reversed | Refunded, reason code on chain |
| Provider unsure | Asked again after 15 s, then 1 min later, 5 min later, then every 15 min; after 24 h, `needs_review` for an operator |
| Delivered after a refund | `delivered_after_refund`: the payer keeps the bill and the money; Todoku logs the loss |
| Nobody settles | The payer reclaims after `RECLAIM_DELAY` |