{
  "openapi": "3.1.0",
  "info": {
    "title": "Apkin API",
    "version": "1.0.0",
    "summary": "Установка на iPhone приложений, которых нет в российском App Store",
    "description": "Заявка на приложения → клиент входит в выданный Apple ID в App Store (логин, пароль, код из API) → ставит приложения по ссылкам. Строгая предоплата: сумма блокируется при создании заявки, списывается при первом нажатии «Установить» по приложению, по неустановленным приложениям возвращается через ~30 минут после окончания срока. Все суммы — целые копейки (20000 = 200 ₽), время — Unix-секунды. Ключ — только на сервере. Документация: https://docs.apkin.app",
    "contact": {
      "name": "Поддержка Apkin",
      "url": "https://t.me/ApkinAppBot"
    }
  },
  "servers": [
    {
      "url": "https://api.apkin.app/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "externalDocs": {
    "description": "Документация",
    "url": "https://docs.apkin.app"
  },
  "tags": [
    {
      "name": "Служебное",
      "description": "Проверка доступности"
    },
    {
      "name": "Каталог",
      "description": "Приложения и цены"
    },
    {
      "name": "Заявки",
      "description": "Создание и чтение заявок"
    },
    {
      "name": "Вход и код",
      "description": "Ожидание кода, реквизиты Apple ID"
    },
    {
      "name": "Перевыдача и блокировки",
      "description": "set_extend, extend, report-blocked"
    },
    {
      "name": "Баланс",
      "description": "Баланс и выписка"
    },
    {
      "name": "Песочница",
      "description": "Имитация событий с ключом apk_test_"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "Служебное"
        ],
        "operationId": "health",
        "summary": "Проверка доступности (без ключа)",
        "security": [],
        "responses": {
          "200": {
            "description": "Сервис работает",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "status",
                        "version"
                      ],
                      "properties": {
                        "status": {
                          "const": "ok"
                        },
                        "version": {
                          "type": "string",
                          "examples": [
                            "1.0.0"
                          ]
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/catalogs": {
      "get": {
        "tags": [
          "Каталог"
        ],
        "operationId": "listCatalogs",
        "summary": "Список каталогов (всегда один: all)",
        "responses": {
          "200": {
            "description": "Каталоги",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "catalogs"
                      ],
                      "properties": {
                        "catalogs": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Catalog"
                          }
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/catalogs/{catalog_id}/applications": {
      "get": {
        "tags": [
          "Каталог"
        ],
        "operationId": "listApplications",
        "summary": "Приложения каталога и ваша цена",
        "parameters": [
          {
            "name": "catalog_id",
            "in": "path",
            "required": true,
            "schema": {
              "const": "all"
            },
            "description": "Только all"
          }
        ],
        "responses": {
          "200": {
            "description": "Приложения",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "catalog",
                        "applications"
                      ],
                      "properties": {
                        "catalog": {
                          "type": "object",
                          "required": [
                            "id",
                            "name"
                          ],
                          "properties": {
                            "id": {
                              "const": "all"
                            },
                            "name": {
                              "type": "string"
                            }
                          }
                        },
                        "applications": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Application"
                          }
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "catalog_not_found",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders": {
      "post": {
        "tags": [
          "Заявки"
        ],
        "operationId": "createOrder",
        "summary": "Создать заявку (идемпотентно по external_order_id)",
        "description": "Блокирует price_kopecks × число приложений на балансе. Повтор с тем же external_order_id возвращает существующую заявку (200) без повторной блокировки; состав приложений при повторе не сравнивается. При 503 order_pending повторите тот же запрос.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateOrderRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Заявка с этим external_order_id уже существует",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Заявка создана",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientFunds"
          },
          "403": {
            "description": "account_blocked — доступ к API приостановлен",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "application_not_found — details.application_ids",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "get": {
        "tags": [
          "Заявки"
        ],
        "operationId": "listOrders",
        "summary": "Краткий список заявок режима ключа, новые сверху",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Заявки",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "orders"
                      ],
                      "properties": {
                        "orders": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/OrderSummary"
                          }
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders/{order_id}": {
      "get": {
        "tags": [
          "Заявки"
        ],
        "operationId": "getOrder",
        "summary": "Полный снимок заявки",
        "description": "Заменяйте сохранённое состояние целиком. Сопоставляйте приложения по applications[].id: id и порядок групп могут меняться.",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Номер заявки ord_…"
          }
        ],
        "responses": {
          "200": {
            "description": "Заявка",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "order_not_found",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders/{order_id}/credentials": {
      "get": {
        "tags": [
          "Вход и код"
        ],
        "operationId": "getCredentials",
        "summary": "Логины и пароли групп (10 запросов в минуту на кабинет)",
        "description": "Запрашивайте перед каждым показом, не храните в базе и не пишите в логи.",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Номер заявки ord_…"
          }
        ],
        "responses": {
          "200": {
            "description": "Реквизиты",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Credentials"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "order_not_found",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "410": {
            "description": "Срок заявки вышел",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders/{order_id}/code-waits": {
      "post": {
        "tags": [
          "Вход и код"
        ],
        "operationId": "startCodeWait",
        "summary": "Включить ожидание кода — до того, как клиент введёт пароль на iPhone",
        "description": "Первый запуск сокращает срок заявки до окна входа — используйте order_expires_at. Повтор с тем же Idempotency-Key возвращает то же ожидание.",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Номер заявки ord_…"
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Один ключ на одно нажатие клиента; при сетевом повторе — тот же"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeWaitRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Ожидание включено (и при повторе с тем же ключом)",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/CodeWait"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "order_not_found, group_not_found",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "410": {
            "description": "Срок заявки вышел",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/code-waits/{wait_id}": {
      "get": {
        "tags": [
          "Вход и код"
        ],
        "operationId": "getCodeWait",
        "summary": "Состояние ожидания и код (опрашивать раз в секунду)",
        "parameters": [
          {
            "name": "wait_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Номер ожидания wait_…"
          }
        ],
        "responses": {
          "200": {
            "description": "Ожидание",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/CodeWait"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "wait_not_found",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders/{order_id}/set_extend": {
      "post": {
        "tags": [
          "Перевыдача и блокировки"
        ],
        "operationId": "setExtend",
        "summary": "Разрешить перевыдачу (окно 48 часов)",
        "description": "Повторный вызов при действующем разрешении безопасен: prepare_applied=false. Ссылки, сроки и коды не меняются.",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Номер заявки ord_…"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetExtendRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Заявка с разрешением; prepare_applied",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "order_not_found",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders/{order_id}/extend": {
      "post": {
        "tags": [
          "Перевыдача и блокировки"
        ],
        "operationId": "extend",
        "summary": "Выполнить перевыдачу: новые ссылки и Apple ID на 12 часов",
        "description": "Если блокировка по неоплаченным приложениям уже возвращена, сумма блокируется снова (402 при нехватке). Не повторяйте вслепую: при потере ответа сначала GET /orders/{order_id}.",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Номер заявки ord_…"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExtendRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Заявка с новыми ссылками; repeat_applied",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientFunds"
          },
          "404": {
            "description": "order_not_found",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "410": {
            "description": "Разрешение на перевыдачу истекло — снова set_extend",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders/{order_id}/groups/{group_id}/report-blocked": {
      "post": {
        "tags": [
          "Перевыдача и блокировки"
        ],
        "operationId": "reportBlocked",
        "summary": "Сообщить о блокировке учётки (только при can_report_blocked=true)",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Номер заявки ord_…"
          },
          {
            "name": "group_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Группа grp_…"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReportBlockedRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Выдача учётки остановлена или уже была остановлена",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/ReportBlockedResult"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "Нет разрешения",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Заявка или группа не найдена; в песочнице метод недоступен",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "410": {
            "description": "Срок заявки вышел",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders/{order_id}/simulate": {
      "post": {
        "tags": [
          "Песочница"
        ],
        "operationId": "simulate",
        "summary": "Имитация событий (только ключ apk_test_)",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Номер заявки ord_…"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SimulateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Заявка после действия",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "not_found (боевой ключ), order_not_found, group_not_found, application_not_found",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/balance": {
      "get": {
        "tags": [
          "Баланс"
        ],
        "operationId": "getBalance",
        "summary": "Баланс кабинета",
        "responses": {
          "200": {
            "description": "Баланс",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Balance"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/ledger": {
      "get": {
        "tags": [
          "Баланс"
        ],
        "operationId": "getLedger",
        "summary": "Выписка по балансу, новые записи сверху",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "before",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "id записи: вернуть более старые"
          }
        ],
        "responses": {
          "200": {
            "description": "Записи",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "request_id"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "entries"
                      ],
                      "properties": {
                        "entries": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/LedgerEntry"
                          }
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    }
  },
  "webhooks": {
    "event": {
      "post": {
        "operationId": "webhookEvent",
        "summary": "Событие на адрес из кабинета lk.apkin.app",
        "description": "Подпись: X-Apkin-Signature = \"sha256=\" + hex(HMAC-SHA256(секрет whsec_…, X-Apkin-Timestamp + \".\" + сырое тело)). Ответ 2xx — доставлено. Иначе до 12 попыток с паузами 10 с, 30 с, 1 мин, 5 мин, 15 мин, 30 мин, 1 ч, 1 ч, 2 ч, 2 ч, 4 ч. Дубли отсекайте по X-Apkin-Event.",
        "security": [],
        "parameters": [
          {
            "name": "X-Apkin-Event",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "id события, совпадает с id в теле"
          },
          {
            "name": "X-Apkin-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/WebhookEventType"
            }
          },
          {
            "name": "X-Apkin-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unix-время отправки попытки"
          },
          {
            "name": "X-Apkin-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^sha256=[0-9a-f]{64}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Любой 2xx — событие доставлено"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Ключ apk_live_… (боевой) или apk_test_… (песочница) из кабинета https://lk.apkin.app"
      }
    },
    "headers": {
      "X-Request-ID": {
        "description": "Номер запроса: ваш X-Request-ID или созданный нами req_…",
        "schema": {
          "type": "string"
        }
      },
      "Retry-After": {
        "description": "Через сколько секунд повторить",
        "schema": {
          "type": "integer"
        }
      }
    },
    "responses": {
      "ValidationError": {
        "description": "validation_error — исправьте запрос",
        "headers": {
          "X-Request-ID": {
            "$ref": "#/components/headers/X-Request-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "unauthorized — нет ключа, ключ неверный или отозван",
        "headers": {
          "X-Request-ID": {
            "$ref": "#/components/headers/X-Request-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "InsufficientFunds": {
        "description": "insufficient_funds — не хватает свободных денег; ничего не создано",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "ok": false,
              "error": {
                "code": "insufficient_funds",
                "message": "Недостаточно средств: нужно 400 ₽, свободно 100 ₽",
                "details": {
                  "required_kopecks": 40000,
                  "available_kopecks": 10000
                }
              },
              "request_id": "req_0a1b2c3d4e5f60718293"
            }
          }
        }
      },
      "Conflict": {
        "description": "Состояние изменилось (access_revoked, replacement_hold, extension_not_prepared, already_extended и др.) — перечитайте заявку",
        "headers": {
          "X-Request-ID": {
            "$ref": "#/components/headers/X-Request-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "RateLimited": {
        "description": "rate_limited (600/мин на ключ, 60 заявок/мин, 10 реквизитов/мин) или лимит успешных кодов",
        "headers": {
          "X-Request-ID": {
            "$ref": "#/components/headers/X-Request-ID"
          },
          "Retry-After": {
            "$ref": "#/components/headers/Retry-After"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "InternalError": {
        "description": "internal_error — повторите с теми же идентификаторами",
        "headers": {
          "X-Request-ID": {
            "$ref": "#/components/headers/X-Request-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Unavailable": {
        "description": "order_pending, service_unavailable, catalog_unavailable — повторите через Retry-After с теми же идентификаторами",
        "headers": {
          "X-Request-ID": {
            "$ref": "#/components/headers/X-Request-ID"
          },
          "Retry-After": {
            "$ref": "#/components/headers/Retry-After"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string",
            "examples": [
              "validation_error"
            ]
          },
          "message": {
            "type": "string",
            "description": "Текст на русском"
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "ok",
          "error",
          "request_id"
        ],
        "properties": {
          "ok": {
            "const": false
          },
          "error": {
            "$ref": "#/components/schemas/Error"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "Catalog": {
        "type": "object",
        "required": [
          "id",
          "name",
          "applications_count"
        ],
        "properties": {
          "id": {
            "const": "all"
          },
          "name": {
            "type": "string"
          },
          "applications_count": {
            "type": "integer"
          }
        }
      },
      "Application": {
        "type": "object",
        "required": [
          "id",
          "name",
          "icon_url",
          "price_kopecks"
        ],
        "properties": {
          "id": {
            "type": "string",
            "examples": [
              "app_chatgpt"
            ]
          },
          "name": {
            "type": "string"
          },
          "icon_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "price_kopecks": {
            "type": "integer",
            "description": "Ваша цена за приложение в новой заявке, копейки (20000 = 200 ₽)"
          }
        }
      },
      "CreateOrderRequest": {
        "type": "object",
        "required": [
          "external_order_id",
          "applications"
        ],
        "properties": {
          "external_order_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:-]{1,100}$",
            "description": "Номер заказа в вашей системе; ключ идемпотентности в пределах кабинета и режима"
          },
          "source_mode": {
            "const": "auto",
            "default": "auto"
          },
          "applications": {
            "type": "array",
            "minItems": 1,
            "maxItems": 50,
            "uniqueItems": true,
            "items": {
              "type": "object",
              "required": [
                "id"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "maxLength": 100
                }
              }
            }
          }
        }
      },
      "Billing": {
        "type": "object",
        "required": [
          "charged",
          "amount_kopecks",
          "would_charge_kopecks"
        ],
        "description": "Оплата в ваших ценах",
        "properties": {
          "charged": {
            "type": "boolean",
            "description": "Есть хотя бы одно списание"
          },
          "amount_kopecks": {
            "type": "integer",
            "description": "Списано"
          },
          "would_charge_kopecks": {
            "type": "integer",
            "description": "Стоимость всех приложений"
          }
        }
      },
      "ApplicationBilling": {
        "type": "object",
        "required": [
          "install_clicked",
          "charged",
          "amount_kopecks",
          "would_charge_kopecks"
        ],
        "properties": {
          "install_clicked": {
            "type": "boolean",
            "description": "Было хотя бы одно нажатие «Установить»"
          },
          "charged": {
            "type": "boolean",
            "description": "Цена списана"
          },
          "amount_kopecks": {
            "type": "integer",
            "description": "Списано за приложение: цена или 0"
          },
          "would_charge_kopecks": {
            "type": "integer",
            "description": "Цена приложения в этой заявке"
          }
        }
      },
      "ApplicationLinks": {
        "type": "object",
        "required": [
          "main",
          "reserve"
        ],
        "properties": {
          "main": {
            "type": "string",
            "format": "uri",
            "description": "Основная ссылка «Установить»"
          },
          "reserve": {
            "type": "string",
            "format": "uri",
            "description": "Запасная ссылка"
          }
        }
      },
      "PartialRepeatResult": {
        "type": "object",
        "description": "Итог частичной перевыдачи (allow_partial)",
        "properties": {
          "attempt_id": {
            "type": "string"
          },
          "status": {
            "enum": [
              "complete",
              "partial",
              "unavailable"
            ]
          },
          "eligible_until": {
            "type": "integer",
            "description": "Крайний срок повторов; повтор его не сдвигает"
          },
          "retry_allowed": {
            "type": "boolean"
          },
          "repeat_number": {
            "type": [
              "integer",
              "null"
            ]
          },
          "total": {
            "type": "integer"
          },
          "issued": {
            "type": "integer"
          },
          "pending": {
            "type": "integer"
          },
          "applications": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "order_id": {
                  "type": "string"
                },
                "external_order_id": {
                  "type": "string"
                },
                "application_id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "group_id": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "status": {
                  "enum": [
                    "issued",
                    "temporarily_unavailable"
                  ]
                },
                "reason": {
                  "enum": [
                    "no_available_catalog",
                    null
                  ]
                },
                "message": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "issued_at": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "expires_at": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "links": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/ApplicationLinks"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          }
        }
      },
      "ApplicationReissue": {
        "type": "object",
        "description": "Перевыдача одного приложения",
        "properties": {
          "can_prepare_extend": {
            "type": "boolean"
          },
          "can_extend": {
            "type": "boolean"
          },
          "extend_ready_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "extend_ready_until": {
            "type": [
              "integer",
              "null"
            ]
          },
          "repeat_count": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2
          },
          "repeat_limit": {
            "const": 2
          },
          "repeat_remaining": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2
          },
          "result": {
            "$ref": "#/components/schemas/PartialRepeatResult"
          }
        }
      },
      "OrderApplication": {
        "type": "object",
        "required": [
          "id",
          "name",
          "links",
          "billing"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "links": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ApplicationLinks"
              },
              {
                "type": "null"
              }
            ],
            "description": "null — ссылки нет (срок вышел, учётка заблокирована, ждёт перевыдачи)"
          },
          "billing": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ApplicationBilling"
              },
              {
                "type": "null"
              }
            ]
          },
          "reissue": {
            "$ref": "#/components/schemas/ApplicationReissue"
          },
          "reissue_status": {
            "const": "temporarily_unavailable"
          }
        }
      },
      "OrderGroup": {
        "type": "object",
        "description": "Группа приложений на одном Apple ID",
        "required": [
          "id",
          "catalog",
          "status",
          "access_confirmed",
          "successful_codes",
          "successful_codes_limit",
          "applications"
        ],
        "properties": {
          "id": {
            "type": "string",
            "examples": [
              "grp_4x8c1z"
            ]
          },
          "catalog": {
            "type": "string",
            "description": "Служебная метка источника учётки"
          },
          "status": {
            "enum": [
              "waiting_for_code",
              "code_received"
            ]
          },
          "expires_at": {
            "type": "integer",
            "description": "Срок группы; после частичной перевыдачи может отличаться от срока заявки"
          },
          "access_confirmed": {
            "type": "boolean"
          },
          "access_inherited": {
            "type": "boolean"
          },
          "access_ever_confirmed": {
            "type": "boolean"
          },
          "successful_codes": {
            "type": "integer",
            "minimum": 0,
            "maximum": 3
          },
          "successful_codes_limit": {
            "const": 3
          },
          "successful_codes_total": {
            "type": "integer"
          },
          "access_revoked": {
            "type": "boolean"
          },
          "access_revocation_reason": {
            "const": "account_blocked"
          },
          "access_message": {
            "type": "string",
            "description": "Текст для клиента, показывать как есть"
          },
          "can_report_blocked": {
            "type": "boolean"
          },
          "account_report_reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "applications": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderApplication"
            }
          }
        }
      },
      "AutomaticReplacement": {
        "type": "object",
        "properties": {
          "status": {
            "enum": [
              "pending",
              "partial",
              "replaced"
            ]
          },
          "pending": {
            "type": "integer"
          },
          "replaced": {
            "type": "integer"
          },
          "limit_consumed": {
            "const": false
          },
          "available_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Раньше этого времени замены не будет"
          },
          "applications": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "application_id": {
                  "type": "string"
                },
                "status": {
                  "enum": [
                    "pending",
                    "replaced"
                  ]
                },
                "expires_at": {
                  "type": "integer"
                },
                "available_at": {
                  "type": [
                    "integer",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "Order": {
        "type": "object",
        "required": [
          "id",
          "external_order_id",
          "status",
          "source_mode",
          "sandbox",
          "created_at",
          "expires_at",
          "groups",
          "billing"
        ],
        "properties": {
          "id": {
            "type": "string",
            "examples": [
              "ord_7k2m9q"
            ]
          },
          "external_order_id": {
            "type": "string"
          },
          "status": {
            "enum": [
              "active",
              "completed",
              "expired"
            ],
            "description": "completed — вход подтверждён кодом, ссылки работают до expires_at"
          },
          "source_mode": {
            "const": "auto"
          },
          "sandbox": {
            "type": "boolean"
          },
          "created_at": {
            "type": "integer"
          },
          "expires_at": {
            "type": "integer",
            "description": "Текущий срок заявки"
          },
          "initial_ttl_seconds": {
            "type": "integer"
          },
          "code_window_ttl_seconds": {
            "type": "integer"
          },
          "code_window_started_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "groups": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderGroup"
            }
          },
          "billing": {
            "$ref": "#/components/schemas/Billing"
          },
          "can_prepare_extend": {
            "type": "boolean"
          },
          "extend_prepared": {
            "type": "boolean"
          },
          "can_extend": {
            "type": "boolean"
          },
          "extend_ready_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "extend_ready_until": {
            "type": [
              "integer",
              "null"
            ]
          },
          "extended_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "repeat_count": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2
          },
          "repeat_limit": {
            "const": 2
          },
          "repeat_remaining": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2
          },
          "repeat_result": {
            "$ref": "#/components/schemas/PartialRepeatResult"
          },
          "repeat_applied": {
            "type": "boolean",
            "description": "Только в ответе extend"
          },
          "prepare_applied": {
            "type": "boolean",
            "description": "Только в ответе set_extend"
          },
          "application_reissue": {
            "$ref": "#/components/schemas/ApplicationReissue"
          },
          "automatic_replacement": {
            "$ref": "#/components/schemas/AutomaticReplacement"
          }
        }
      },
      "OrderSummary": {
        "type": "object",
        "required": [
          "id",
          "external_order_id",
          "state",
          "sandbox",
          "created_at",
          "expires_at",
          "applications",
          "billing"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "external_order_id": {
            "type": "string"
          },
          "state": {
            "enum": [
              "creating",
              "active",
              "closed",
              "failed"
            ],
            "description": "closed — срок вышел, блокировка по неустановленным приложениям возвращена"
          },
          "sandbox": {
            "type": "boolean"
          },
          "created_at": {
            "type": "integer"
          },
          "expires_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "applications": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name",
                "price_kopecks",
                "state"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "price_kopecks": {
                  "type": "integer"
                },
                "state": {
                  "enum": [
                    "held",
                    "charged",
                    "released"
                  ]
                }
              }
            }
          },
          "billing": {
            "$ref": "#/components/schemas/Billing"
          }
        }
      },
      "CodeWaitRequest": {
        "type": "object",
        "required": [
          "group_id"
        ],
        "properties": {
          "group_id": {
            "type": "string",
            "maxLength": 100
          }
        }
      },
      "CodeWait": {
        "type": "object",
        "required": [
          "id",
          "status",
          "started_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "examples": [
              "wait_9d2f1a"
            ]
          },
          "status": {
            "enum": [
              "active",
              "succeeded",
              "code_expired",
              "timed_out",
              "cancelled"
            ]
          },
          "started_at": {
            "type": "integer"
          },
          "active_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "deadline_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "code": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[0-9]{6}$"
          },
          "valid_for_seconds": {
            "type": "integer",
            "minimum": 0,
            "maximum": 60
          },
          "order_expires_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Актуальный срок заявки"
          },
          "access_revoked": {
            "type": "boolean"
          },
          "access_revocation_reason": {
            "const": "account_blocked"
          },
          "access_message": {
            "type": "string"
          }
        }
      },
      "CredentialsGroup": {
        "type": "object",
        "required": [
          "id",
          "catalog",
          "login",
          "password"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "catalog": {
            "type": "string"
          },
          "login": {
            "type": "string",
            "description": "Пустая строка при access_revoked"
          },
          "password": {
            "type": "string",
            "description": "Пустая строка при access_revoked"
          },
          "access_revoked": {
            "type": "boolean"
          },
          "access_revocation_reason": {
            "const": "account_blocked"
          },
          "access_message": {
            "type": "string"
          }
        }
      },
      "Credentials": {
        "type": "object",
        "required": [
          "order_id",
          "expires_at",
          "storage_policy",
          "groups"
        ],
        "properties": {
          "order_id": {
            "type": "string"
          },
          "expires_at": {
            "type": "integer"
          },
          "storage_policy": {
            "type": "string"
          },
          "groups": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CredentialsGroup"
            }
          }
        }
      },
      "SetExtendRequest": {
        "type": "object",
        "properties": {
          "application_id": {
            "type": "string",
            "description": "Перевыдача одного приложения"
          }
        }
      },
      "ExtendRequest": {
        "type": "object",
        "properties": {
          "application_id": {
            "type": "string",
            "description": "Перевыдача одного приложения (то же значение, что в set_extend)"
          },
          "allow_partial": {
            "type": "boolean",
            "default": false,
            "description": "Выдать то, что доступно; итог — в repeat_result"
          }
        }
      },
      "ReportBlockedRequest": {
        "type": "object",
        "required": [
          "account_report_reference"
        ],
        "properties": {
          "account_report_reference": {
            "type": "string",
            "description": "Значение groups[].account_report_reference без изменений"
          }
        }
      },
      "ReportBlockedResult": {
        "type": "object",
        "required": [
          "incident_id",
          "status",
          "applied"
        ],
        "properties": {
          "incident_id": {
            "type": "string"
          },
          "status": {
            "const": "quarantined"
          },
          "applied": {
            "type": "boolean"
          }
        }
      },
      "SimulateRequest": {
        "type": "object",
        "required": [
          "action"
        ],
        "properties": {
          "action": {
            "enum": [
              "install",
              "block",
              "replace",
              "expire"
            ]
          },
          "application_id": {
            "type": "string",
            "description": "Для install"
          },
          "group_id": {
            "type": "string",
            "description": "Для block и replace"
          }
        }
      },
      "Balance": {
        "type": "object",
        "required": [
          "currency",
          "available_kopecks",
          "held_kopecks",
          "price_kopecks",
          "available_installs"
        ],
        "properties": {
          "currency": {
            "const": "RUB"
          },
          "available_kopecks": {
            "type": "integer",
            "description": "Свободно"
          },
          "held_kopecks": {
            "type": "integer",
            "description": "Заблокировано под открытые заявки"
          },
          "price_kopecks": {
            "type": "integer",
            "description": "Ваша цена за приложение"
          },
          "available_installs": {
            "type": [
              "integer",
              "null"
            ],
            "description": "floor(available / price); null при цене 0"
          }
        }
      },
      "LedgerEntry": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "amount_kopecks",
          "held_kopecks",
          "available_after_kopecks",
          "held_after_kopecks",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "kind": {
            "enum": [
              "topup",
              "adjust",
              "hold",
              "charge",
              "release",
              "refund"
            ]
          },
          "amount_kopecks": {
            "type": "integer",
            "description": "Изменение свободного баланса"
          },
          "held_kopecks": {
            "type": "integer",
            "description": "Изменение заблокированной суммы"
          },
          "available_after_kopecks": {
            "type": "integer",
            "description": "Свободно после записи"
          },
          "held_after_kopecks": {
            "type": "integer",
            "description": "Заблокировано после записи"
          },
          "order_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "external_order_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "application_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "note": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "WebhookEventType": {
        "enum": [
          "billing.charged",
          "billing.reversed",
          "order.created",
          "order.extended",
          "order.expired",
          "order.completed",
          "code.ready",
          "ping"
        ]
      },
      "WebhookEvent": {
        "type": "object",
        "required": [
          "id",
          "type",
          "created_at",
          "sandbox",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "examples": [
              "evt_3b9f0c2a7d1e4f5a6b7c8d9e"
            ]
          },
          "type": {
            "$ref": "#/components/schemas/WebhookEventType"
          },
          "created_at": {
            "type": "integer"
          },
          "sandbox": {
            "type": "boolean"
          },
          "data": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "order_id": {
                "type": "string"
              },
              "external_order_id": {
                "type": "string"
              },
              "application_id": {
                "type": "string",
                "description": "billing.*"
              },
              "amount_kopecks": {
                "type": "integer",
                "description": "billing.*"
              },
              "message": {
                "type": "string",
                "description": "ping"
              }
            }
          }
        }
      }
    }
  }
}
