# GET /orders/{id} — Получить заказ

Статус заказа и ключ, если заказ выполнен.

Возвращает только ваши заказы: чужой и несуществующий заказ одинаково дают `404`.

Ключ (`key`) приходит только здесь и в ответе `POST /purchase` — в вебхуке его нет.

Авторизация: заголовок `X-Entity-Key`.

**Параметры пути**

| Имя | Тип | Обязателен | Описание |
|---|---|---|---|
| `id` | integer | да | ID заказа, целое положительное число. Пример: `12`. |

**Ответы**

- `200 OK` — Выполнен

```json
{
  "status": "success",
  "order": {
    "id": 1842,
    "productId": 12,
    "quantity": 1,
    "price": 1490,
    "currency": "RUB",
    "status": "completed",
    "failureReason": null,
    "idempotencyKey": "order-7731",
    "webhookStatus": "delivered",
    "createdAt": "2026-11-13T12:36:53.000Z",
    "updatedAt": "2026-11-13T12:37:10.000Z",
    "key": [
      {
        "serial": "ABCDE-FGHIJ-KLMNO",
        "type": "text",
        "name": "Dead by Daylight"
      }
    ]
  }
}
```

- `200 OK` — В обработке

```json
{
  "status": "success",
  "order": {
    "id": 1842,
    "productId": 12,
    "quantity": 1,
    "price": 1490,
    "currency": "RUB",
    "status": "pending",
    "failureReason": null,
    "idempotencyKey": "order-7731",
    "webhookStatus": null,
    "createdAt": "2026-11-13T12:36:53.000Z",
    "updatedAt": "2026-11-13T12:37:10.000Z"
  }
}
```

- `200 OK` — Не выполнен

```json
{
  "status": "success",
  "order": {
    "id": 1842,
    "productId": 12,
    "quantity": 1,
    "price": 1490,
    "currency": "RUB",
    "status": "failed",
    "failureReason": "product_unavailable",
    "idempotencyKey": "order-7731",
    "webhookStatus": "delivered",
    "createdAt": "2026-11-13T12:36:53.000Z",
    "updatedAt": "2026-11-13T12:37:10.000Z"
  }
}
```

- `400 Bad Request` — Некорректный ID

```json
{
  "status": "error",
  "message": "Invalid order id"
}
```

- `404 Not Found` — Не найден

```json
{
  "status": "error",
  "message": "Order not found"
}
```

- `500 Internal Server Error` — Ключ временно недоступен

```json
{
  "status": "error",
  "code": "key_unavailable",
  "message": "The order is paid but its key can't be retrieved right now; contact support",
  "order": {
    "id": 1842,
    "productId": 12,
    "quantity": 1,
    "price": 1490,
    "currency": "RUB",
    "status": "completed",
    "failureReason": null,
    "idempotencyKey": "order-7731",
    "webhookStatus": "delivered",
    "createdAt": "2026-11-13T12:36:53.000Z",
    "updatedAt": "2026-11-13T12:37:10.000Z"
  }
}
```

- `401 Unauthorized` — Нет ключа

```json
{
  "status": "error",
  "message": "Missing X-Entity-Key header"
}
```

- `403 Forbidden` — Неверный ключ

```json
{
  "status": "error",
  "message": "Invalid entity key"
}
```

- `429 Too Many Requests` — Превышен лимит

```json
{
  "status": "error",
  "message": "Too many requests, try again later"
}
```

Веб-версия: https://docs.merchant.dbdlobby.com/ru/reference/get-order
