# Payment lifecycle (/payment-lifecycle) > The states an online payment moves through, how the checkout redirect, the webhook and the read fit together, and what to do with each outcome. An online payment starts `pending` and ends in one of three states: `executed`, `failed` or `abandoned`. Your backend learns which one from the [read endpoint](/online-payments#read-the-outcome); the shopper's return and the [webhook](/webhooks) only tell you when to read. > **Server only.** The API cannot be called from a browser. The gateway answers no cross-origin (CORS) requests, and the API key must never reach a browser. Call it from your server. ## States pending: create pending --> executed: paid pending --> failed: declined or failed pending --> abandoned: nothing paid for 24 hours failed --> executed: late ANNA payment abandoned --> executed: late ANNA payment executed --> [*] note right of pending Not paid. Also the state after the shopper cancels on the checkout page, or after five cards that were neither approved nor declined. end note note right of executed Paid. Compare amount with the order total: a partial approval reports less than you asked for. end note `} /> | `state` | Trigger | Final | Timeout | What you do | |---|---|---|---|---| | `pending` | You create the payment. Not paid yet: the shopper may still be on the checkout, or cancelled it and was sent to your failure URL. | No | Becomes `abandoned` 24 hours after it was created, if still unpaid. | Never treat it as paid. Poll on return, then let the webhook or a later read settle it. See [`pending`](#pending). | | `executed` | The payment is paid. `amount` is the amount actually approved. | Yes | — | Compare `amount` with the order total, then fulfil once. See [`executed`](#executed). | | `failed` | The card was declined or the payment did not go through. | Yes, except for a late ANNA payment | — | Offer a new payment. See [`failed`](#failed). | | `abandoned` | Not paid within **24 hours** of being created. The checkout no longer takes a payment for it. | Yes, except for a late ANNA payment | — | Release held stock, or create a new payment. See [`abandoned`](#abandoned). | `executed` never changes. `failed` and `abandoned` change only when an ANNA bank payment the shopper started on the checkout completes afterwards: the payment becomes `executed` and sends `payment.received`. See [A late ANNA payment](#a-late-anna-payment). A state you do not recognise is `pending`, never paid. ## From create to fulfilment >Backend: Place order Backend->>API: POST /api/payments/internet/create
Authorization: Bearer API key
Idempotency-Key: one per checkout attempt API-->>Backend: paymentReference, checkoutUrl Note over Backend: Store paymentReference
with the order first Backend-->>Shopper: 303 to checkoutUrl Shopper->>Checkout: Pay by card, or by ANNA alt Paid Checkout-->>Shopper: Redirect to successUrl else Declined or failed Checkout-->>Shopper: Redirect to failureUrl else Cancelled Checkout-->>Shopper: Redirect to failureUrl, still pending end Note over Shopper,Checkout: The return and the webhook arrive in either order, or only one of them par The shopper's return Shopper->>Backend: Lands on your return URL Backend->>API: GET /api/payments/internet/{paymentReference} API-->>Backend: state, amount and The webhook (once the payment is received and booked, and a callbackUrl was passed) API->>Backend: POST callbackUrl, payment.received
signed with X-Mps-Signature Backend->>Backend: Verify the signature and timestamp
(401 if invalid) Backend->>Backend: Store it, keyed on X-Mps-Delivery-Id
(5xx if that fails) Backend-->>API: 2xx, only now Note over Backend: Later, a worker reads the payment Backend->>API: GET /api/payments/internet/{paymentReference} API-->>Backend: state, amount end Note over Backend: Fulfil once, on whichever comes first:
state is executed and amount equals the order total `} /> Points the diagram cannot show: - **Nothing is appended to your return URLs.** Match the return to its order by your own order id in the URL, or by the `paymentReference` you stored before redirecting. - **The return and the webhook arrive in either order**, and a shopper who closes the tab never returns at all. Settle the order on whichever comes first, after reading the payment, and make the second a no-op: key on `paymentReference`. - **`payment.received` is the only payment webhook.** It is sent once a payment has been received and booked — for a test payment, once it is `executed`. A `failed`, `abandoned` or still `pending` payment sends nothing. Its refunds send their own events once decided (`refund.refunded`, `refund.failed`, `refund.canceled`; see [Webhooks](/webhooks#events)). No `callbackUrl`, or no [signing secret](/webhooks#the-signing-secret) on your key, and nothing is sent either. - **Delivery is at least once.** A webhook is attempted up to six times over about 8½ hours; see [Delivery](/webhooks#delivery). > **Warning.** Landing on successUrl is not proof of payment. Verify the webhook signature, read the payment, and check its state, amount, currency, and reference before marking an order paid. ## Processing a webhook Verify the webhook, then either read the payment, settle the order and answer `2xx` ([process, then answer](/webhooks#the-simple-handler-process-then-answer)), or store the webhook, answer `2xx` and settle the order from a worker ([store, answer, process](/webhooks#the-production-pattern-store-answer-process)), as the [integration examples](/integration-examples) do. ## Handling each outcome ### `pending` Never treat it as paid. On the shopper's return, poll the read every 2 seconds for up to about 30 seconds. If it is still `pending`, show "we are confirming your payment" and let the webhook or a later read settle the order. Do not poll faster: payment requests are limited to 100 a minute. A shopper who cancelled on the checkout page lands on your failure URL with the payment still `pending`, and can still pay it: send them back to the same `checkoutUrl`. After five cards that were neither approved nor declined (see [Card attempts](/online-payments#card-attempts-are-limited)) the checkout refuses more cards and does not send the shopper back; the payment stays `pending`. ### `executed` The payment is paid. Compare `amount` with the order total before you ship: on a partial approval it is **less** than you asked for, and this field is the only signal. Fulfil the order once, even if the webhook and the return both report it. **A partial approval** (`amount` less than the order total) is paid, but not in full. Do not ship it. Either refund it ([Refund a payment](/refunds#refund-a-payment), with no `amount`) and ask the shopper to pay again with a new payment, or settle the difference with them yourself. Never mark the order paid in full. **Fulfil once, act once.** Marking the order paid with an update that only succeeds once (`… WHERE paid_at IS NULL`) makes the *record* exact. Shipping, an e-mail or a call to another system can still fail or run twice. Record what must happen in the same database commit that marks the order paid (an outbox table), and have a worker carry it out, with an idempotency key of its own towards the other system. ### `failed` The card was declined or the payment failed. Let the shopper try again with a **new** payment: create is per checkout attempt, and a failed payment takes no new card. Keep the order open rather than cancelling it on the first decline: see [A late ANNA payment](#a-late-anna-payment). ### `abandoned` Nothing was paid within 24 hours of the payment being created, so MPS gave up on it and the checkout stops taking a payment for it. No webhook is sent. Release any stock you held, or create a new payment if the shopper comes back. Until those 24 hours are up an unpaid payment is `pending`: the shopper may still come back to the checkout page and pay. ### A late ANNA payment The checkout also offers ANNA, a bank payment the shopper confirms in their banking app. A shopper can start one, then let the payment fail on a card or expire, and complete the bank payment afterwards. The money then arrives: the payment turns `executed` and `payment.received` is sent, even though you already saw `failed` or `abandoned`. Keep handling `payment.received` for orders you closed. Reopen and fulfil the order, or [refund the payment](/refunds#refund-a-payment) if you can no longer deliver. ## Reconcile what you did not hear about The webhook is the fast path, not a guarantee: it can be given up after its last retry, and only a received payment sends one. For any order still waiting, read the payment by its `paymentReference` — the read is always authoritative. A schedule for the orders still open: 1. **Every 15 minutes**, take the orders that have a `paymentReference` and are neither settled nor closed. 2. **Read each one**, spread over the run rather than all at once: it shares the [rate limit](/errors-and-rate-limits#rate-limits) with your checkout. 3. **Act on the state.** `executed`: settle it once, as above. `failed` or `abandoned`: close the order or offer a new payment. `pending`: leave it for a later run, reading it less often as it ages (15 minutes, then hourly). 4. **Stop at 24 hours.** An unpaid payment reads `abandoned` 24 hours after it was created. Only a late ANNA payment changes it after that, and that sends `payment.received`. 5. **Escalate** what does not resolve: a read that keeps failing, or a payment still `pending` well after 24 hours. That needs a person, not another retry. **What this schedule does not cover:** a [late ANNA payment](#a-late-anna-payment) that arrives after you stopped reading, when every delivery of its `payment.received` failed. The payment reads `executed`, but nothing tells you. Keep the `paymentReference` of every payment an order had, closed orders included, so it can always be read. If your business must catch this case, keep reading the `failed` and `abandoned` payments of closed orders once a day, at a low rate, for as long as you would still fulfil or refund such an order. Money you cannot match to an order: contact MPS with the `paymentReference`, the time (UTC) and `state` of your last read, and the [`traceparent`](/errors-and-rate-limits#traceparent) header of that read. **A create whose answer you never got** has no `paymentReference` to read. Send the same request with the same `Idempotency-Key` within 24 hours: you get the payment it made, or a new one if it made none. There is no search by your own `reference`, which is why the key is stored before the call. ## Related - [Follow a payment's timeline](/payment-timeline): every step a payment went through, to explain its state - [Process webhooks reliably](/webhooks#processing-them-reliably) - [Accept a payment](/online-payments) - [Integration examples](/integration-examples) - [Production checklist](/production-checklist)