# Errors and rate limits (/errors-and-rate-limits)
> Every status code the API answers, its error body, the rate limits and the retry policy, with what to do about each one.
Each section below resolves one class of error. The payments API links to it from the error itself,
in the `documentationUrl` of every problem response.
## Status codes
| Status | Meaning | What to do |
|---|---|---|
| `200` | Success | — |
| `201` | Created: a refund was requested (or replayed for its `Idempotency-Key`) | Read its `status` |
| `400` | The request was understood but is invalid | Fix the field named in the body; do not retry unchanged. See [Validation errors](#validation-errors) |
| `401` | No API key, or a wrong or revoked one | Check the key; do not retry. See [Authentication errors](#authentication-errors) |
| `403` | The API key is valid but may not do this: a missing scope, or a merchant (`x-wallet-number`) your key does not cover | Check the scopes and the wallet; do not retry. See [Authentication errors](#authentication-errors) |
| `404` | Not a published endpoint, or, on the payment read and the refund endpoints, no such payment or refund for this merchant | Check the path and the reference. See [Not found](#not-found) |
| `409` | A conflict, named by the body's `code` | Retry or stop, as the `code` says. See [Conflicts](#conflicts) |
| `429` | Rate limited | Wait `Retry-After` seconds, then retry. See [Rate limits](#rate-limits) |
| `5xx` | A problem on the MPS side | Retry reads with backoff; see [Server errors](#server-errors) for creates |
## Problem responses
The payments API answers an error with an [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) problem
document. Every problem response of the payments API carries two fields beside `status` and `detail`:
| Field | Type | Required | Description |
|---|---|---|---|
| `traceId` | string | Yes | The W3C trace id of the call, such as `00-a27c57cb…-01`. Quote it when you contact MPS about a failed call: it finds that exact call in the MPS logs. |
| `documentationUrl` | string | Yes | A link to the section of this page that resolves the error, such as [Validation errors](#validation-errors) for a `400`. |
The gateway's own `401`, `403` and `429` answers have no body, and so no `traceId` or `documentationUrl`.
The status code is the whole answer. The one exception is the `403` for an `x-wallet-number` your key does
not cover: its body is `{ "error": "invalid_request", "error_description": "…" }` (see
[Authentication errors](#authentication-errors)).
### The `traceparent` header [#traceparent]
**Every answer** carries a `traceparent` header naming the call's W3C trace: a success, a problem, and a
`401`, `404` or `429` that has no body. Log it with every call you make; quote it when you contact MPS
about a call, failed or not.
```http
traceparent: 00-a27c57cb2b3e4f5d8c9a0b1c2d3e4f50-1a2b3c4d5e6f7a8b-01
```
The second part is the trace id. On a problem response it is the same trace id as in the body's
`traceId`; the part after it can differ, as it names the step in MPS that answered.
## Validation errors [#validation-errors]
A payment endpoint answers a validation failure with `400` and a problem document whose `errors` object
maps each offending field to its messages:
```json title="400 Bad Request"
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"amount": ["Amount must be greater than zero (in cents)"]
},
"traceId": "00-a27c57cb…-01",
"documentationUrl": "https://docs.mps-emi.com/errors-and-rate-limits#validation-errors"
}
```
Each key is the field as you sent it in the JSON body (`amount`, `successUrl`), or the header
(`Idempotency-Key`). A body that cannot be read at all is refused the same way, naming the field when
there is one: a decimal or a string where a whole number of cents belongs, or malformed JSON. Show the
messages to a developer, not to a shopper: they are written in English for integrators.
Fix the named field and send the request again. Do not retry it unchanged.
## Authentication errors [#authentication-errors]
| Status | Code | Cause | Resolution |
|---|---|---|---|
| `401` | — | No API key, or a wrong or revoked one. No body. | Check the key; do not retry. See [API key errors](/authentication#api-key-errors). |
| `403` | — | The API key is valid but lacks the endpoint's scope. No body. | Use a key that holds the scope. See [Scopes](/authentication#scopes). |
| `403` | `invalid_request` | The `x-wallet-number` is not one of your merchants. The body is `{ "error": "invalid_request", "error_description": "…" }`. | Send a wallet your key covers. See [Choose the merchant](/authentication#choosing-the-merchant). |
| `403` | — | Create a payment with a partner key and no `x-wallet-number`. No body. | Send `x-wallet-number` on every call. See [Choose the merchant](/authentication#choosing-the-merchant). |
| `403` | — | Create a payment: the merchant has no shop name registered yet. No body. | Contact MPS. |
## Not found [#not-found]
A `404` carries no body. It means one of two things:
- The path is not a published endpoint. Check the path against the [API reference](/api-reference).
- On the payment read and the refund endpoints: no such payment or refund for the merchant the key acts
for. The reference has a typo, changed on the way (trimmed, re-cased, parsed as a UUID), or belongs to
a different merchant than the one the payment was created for. With a partner key, read it with the
same `x-wallet-number`.
Do not retry a `404` unchanged.
## Conflicts [#conflicts]
A `409` is a problem document with a stable `code` beside its `detail`. Decide on the `code`: it never
changes, while `detail` is English text for a person and can be reworded at any time.
```json title="409 Conflict"
{
"status": 409,
"detail": "A payment with this Idempotency-Key is still being created; retry shortly",
"code": "idempotency_key_in_use",
"traceId": "00-a27c57cb…-01",
"documentationUrl": "https://docs.mps-emi.com/errors-and-rate-limits#conflicts"
}
```
| `code` | Where | Meaning | Retry? |
|---|---|---|---|
| `idempotency_key_in_use` | Create a payment, refund a payment | The first request with this `Idempotency-Key` is still running | Yes, after a second, with the same key and body |
| `refund_in_progress` | Refund a payment, cancel a refund | Another refund of the same payment is being changed at this moment | Yes, after a second |
| `idempotency_key_expired` | Create a payment | The key is still kept, but the payment it made can no longer be returned (rare). After 24 hours a key is not kept at all and opens a new payment instead: see [Retrying safely](/online-payments#retrying-safely-idempotency-key) | No: create a new payment with a new key |
| `payment_not_refundable` | Refund a payment | The payment is not `executed` | No |
| `refund_not_cancelable` | Cancel a refund | The refund was sent or decided | No: read it |
| `payment_link_not_open` | Cancel a payment link | The link is paid or expired, so there is nothing left to cancel | No: read the link |
| `payment_link_unnamed` | Create a payment link | The merchant has no shop name, which the shopper would see | No: ask MPS to set it |
New codes may be added. Treat a `409` with a code you do not know as one not to retry.
## Rate limits
| | Limit |
|---|---|
| Requests per API key | 100 per minute, across every endpoint |
The limit counts **per API key**: creates, reads and refunds share it. A test key and a live key each
have their own; a partner key has one for all the merchants it acts for. The minute is a fixed window,
not a rolling one: all 100 calls may come at once, and the count starts again when the window ends. Over the limit the answer is `429 Too Many Requests` at once, with a
`Retry-After` header giving the seconds to wait. Nothing is queued.
A `429` also comes from too many failed keys from one address. See
[API key errors](/authentication#api-key-errors).
**Reuse connections.** Send your calls over kept-alive connections (HTTP/1.1 keep-alive or one HTTP/2
connection) from an HTTP client that pools them, as every common HTTP client does by default. Opening many
new connections at the same moment from one address can be refused at the network edge, before the
request reaches the API, as a reset connection rather than a `429`. A pooled client does not run into it.
Retry a reset like a network error.
**Budget for polling.** Reading four payments every 2 seconds is already 120 reads a minute. Poll only
while a shopper is on your return page, at most every 2 seconds and for about 30 seconds, then let the
webhook settle the order. Reconcile older orders on a schedule, spread out, with backoff. See
[Reconcile what you did not hear about](/payment-lifecycle#reconcile-what-you-did-not-hear-about). If your
volume needs more, ask MPS.
## Server errors [#server-errors]
A `5xx` is a problem on the MPS side. A `500` from the payments API is a problem document with a
`traceId` and a `documentationUrl`; other `5xx` answers can carry no body.
- **Reads** are safe to retry with backoff.
- **A create with an `Idempotency-Key`** is safe to retry with the same key and the same body: you get
the payment the first call made, or a new one if it made none.
- **A create without a key** is not safe to retry: the retry may open a second payment.
The [Retry policy](#retry-policy) lists every operation. Quote the `traceId` when you contact MPS.
## By endpoint
### `POST /api/payments/internet/create`
> **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.
| Status | Body | Common causes |
|---|---|---|
| `200` | `{ "data": { "paymentReference", "checkoutUrl" } }` | — |
| `400` | Problem document with `errors` per field (see [Validation errors](#validation-errors)) | `amount` of zero or missing; `successUrl` / `failureUrl` missing or not `https://`; a `callbackUrl` that is not an absolute HTTPS URL on a public host; an `Idempotency-Key` reused for a different request, or `Idempotency-Key` and `X-Idempotency-Key` naming different keys |
| `401` | none | No API key, or a wrong or revoked one |
| `403` | none, or `{ "error", "error_description" }` | The key lacks `internet:create`; a partner key sent no `x-wallet-number`, or one it does not cover (with a body); or the merchant has no shop name registered yet (contact MPS) |
| `409` | Problem document with a `code` | `idempotency_key_in_use`: a create with the same `Idempotency-Key` is still running; retry shortly. `idempotency_key_expired`: create a new payment with a new key |
| `429` | none, `Retry-After` header | The key's 100 requests a minute, shared by every endpoint ([Rate limits](#rate-limits)) |
| `5xx` | See [Server errors](#server-errors) | On the MPS side: do not retry blindly, see [Retry policy](#retry-policy) |
### `GET /api/payments/internet/{paymentReference}`
| Status | Body | Common causes |
|---|---|---|
| `200` | `{ "data": { "paymentReference", "state", "amount", "currency", "amountRefunded", "amountRemaining", "reference" } }` | — |
| `401` | none | No API key, or a wrong or revoked one |
| `403` | none | The key lacks `internet:read` |
| `404` | none | No such payment for the merchant the key acts for, or a partner key sent no `x-wallet-number` (see [Not found](#not-found)) |
| `429` | none, `Retry-After` header | The key's 100 requests a minute, shared by every endpoint ([Rate limits](#rate-limits)); poll every 2 seconds at most |
### `POST /api/payments/{paymentReference}/refunds`
| Status | Body | Common causes |
|---|---|---|
| `201` | `{ "data": { "refundId", "status", … } }`, `Location` header | — |
| `400` | Problem document with `errors` per field (see [Validation errors](#validation-errors)) | a malformed `paymentReference`; `amount` zero or less, or more than is left; nothing left to refund; an unknown `reason`; an `Idempotency-Key` reused for a different request, or with spaces or other characters than letters, digits and punctuation |
| `401` | none | No API key, or a wrong or revoked one |
| `403` | none, or `{ "error", "error_description" }` | The key lacks `payments:refund`; a partner key sent no `x-wallet-number`, or one it does not cover (with a body) |
| `404` | none | No such payment for this merchant, or a test key on a live payment (or the reverse) |
| `409` | Problem document with a `code` | `idempotency_key_in_use` or `refund_in_progress`: retry shortly. `payment_not_refundable`: the payment is not `executed` |
| `429` | none, `Retry-After` header | The key's 100 requests a minute, shared by every endpoint ([Rate limits](#rate-limits)) |
### `GET /api/payments/{paymentReference}/refunds/{refundId}` and `GET /api/payments/{paymentReference}/refunds`
| Status | Body | Common causes |
|---|---|---|
| `200` | `{ "data": { "refundId", "status", … } }`, or `{ "data": [ … ] }` for the list | — |
| `401` | none | No API key, or a wrong or revoked one |
| `403` | none, or `{ "error", "error_description" }` | The key lacks `payments:refund`; a partner key sent no `x-wallet-number`, or one it does not cover (with a body) |
| `404` | none | No such payment for this merchant, or no such refund under it |
| `429` | none, `Retry-After` header | The key's 100 requests a minute, shared by every endpoint ([Rate limits](#rate-limits)) |
### `DELETE /api/payments/{paymentReference}/refunds/{refundId}`
| Status | Body | Common causes |
|---|---|---|
| `204` | none | Canceled, or canceled before |
| `401` | none | No API key, or a wrong or revoked one |
| `403` | none, or `{ "error", "error_description" }` | The key lacks `payments:refund`; a partner key sent no `x-wallet-number`, or one it does not cover (with a body) |
| `404` | none | No such refund of this payment for this merchant |
| `409` | Problem document with a `code` | `refund_not_cancelable`: it was sent or decided; read it. `refund_in_progress`: retry shortly |
| `429` | none, `Retry-After` header | The key's 100 requests a minute, shared by every endpoint ([Rate limits](#rate-limits)) |
## Retry policy
| Operation | Retry on | Do not retry on |
|---|---|---|
| **Create a payment** (with an `Idempotency-Key`) | `5xx`, a network error or a timeout: same key, same body. `409` `idempotency_key_in_use`: after a second. `429`: after `Retry-After`. | `400`, `401`, `403`, `409` `idempotency_key_expired` |
| **Create a payment** (without a key) | `429` only | `5xx` or a timeout: the retry may open a second payment. Create a fresh one and abandon the first |
| **Read a payment** | `5xx`, a network error, `429` (after `Retry-After`): with backoff (1 s, 2 s, 4 s…, capped) | `400`, `401`, `403`, `404` |
| **Refund a payment** | `5xx`, a network error or a timeout: same key, same body. `409` `idempotency_key_in_use` or `refund_in_progress`: after a second. `429`. | `400`, `401`, `403`, `404`, `409` `payment_not_refundable` |
| **Cancel a refund** | `5xx`, a network error, `409` `refund_in_progress`, `429`. A repeated cancel is safe: a canceled refund answers `204` again. | `404`, `409` `refund_not_cancelable` |
Back off with jitter (a random part of the wait), and give up after a handful of attempts: a request
that keeps failing is something to look at, not to repeat.
## Related
- [Payment lifecycle](/payment-lifecycle)
- [Accept a payment](/online-payments)
- [Authentication](/authentication)
- [Refunds](/refunds)