{
  "openapi": "3.1.0",
  "info": {
    "title": "Pay with ment",
    "version": "1.1.0",
    "description": "Приём платежей через СБП и крипту (USDT, BTC, ETH, TON/GRAM, SOL и др. через xRocket, CryptoBot, Laveshka). Каждый API-ключ — отдельный проект со своим webhook, отдельным балансом, гибкой политикой комиссий (вся на клиенте, только сервис, только касса, всё на мерчанте или выбор клиента на оплате) и прогрессивной ставкой от 7% до 5% по обороту.",
    "contact": { "name": "Pay with ment", "url": "https://app.ment-pay.top/developers.html" }
  },
  "servers": [{ "url": "https://api.ment-pay.top/v1" }],
  "security": [{ "bearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "mp_live_... или mp_test_..."
      }
    },
    "schemas": {
      "Payment": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "pay_9f2c1a..." },
          "object": { "type": "string", "const": "payment" },
          "status": { "type": "string", "enum": ["pending", "paid", "expired", "canceled"] },
          "amount": { "type": "number", "example": 490 },
          "currency": { "type": "string", "enum": ["RUB", "USDT", "USDC", "BTC", "ETH", "GRAM", "TON", "SOL", "BNB", "TRX", "LTC", "XAUT", "DOGE"], "example": "RUB" },
          "fee": { "type": "number", "example": 34.3 },
          "fee_pct": { "type": ["number", "null"], "description": "Ставка комиссии MENT по проекту на момент создания (от 7% до 5% по обороту)", "example": 7 },
          "fee_bearer": { "type": "string", "enum": ["client", "merchant", "choice"], "description": "Устаревшее поле-алиас: client = client_gateway, merchant = merchant", "example": "client" },
          "fee_policy": { "type": "string", "enum": ["client_all", "client_service", "client_gateway", "merchant", "choice"], "description": "Кто платит комиссии: всю на клиента, только сервис, только кассу, всё на мерчанта или выбор клиента", "example": "client_gateway" },
          "fee_choices": { "type": ["array", "null"], "description": "Для fee_policy=choice: доступные варианты с pay_amount и net_amount", "items": { "type": "object" } },
          "selected_fee": { "type": ["string", "null"], "enum": ["client_all", "merchant", null], "description": "Что выбрал клиент в режиме choice" },
          "pay_asset": { "type": "string", "description": "В чём платит клиент: RUB, USDT или USDC (USDC зачисляется в USDT 1:1)", "example": "RUB" },
          "net_amount": { "type": "number", "example": 455.7 },
          "pay_amount": { "type": ["number", "null"], "description": "Сколько реально спишут с плательщика", "example": 512.05 },
          "gateway_amount": { "type": ["number", "null"], "description": "Сумма, выставленная кассе (в режиме merchant меньше номинала)", "example": 490 },
          "cashier_fee": { "type": ["number", "null"], "description": "Сколько забирает касса", "example": 22.05 },
          "gateway_fee": { "type": ["number", "null"], "description": "Наценка кассы к номиналу (pay_amount - amount)", "example": 22.05 },
          "project_id": { "type": ["string", "null"], "description": "ID проекта (API-ключа), создавшего платёж" },
          "description": { "type": ["string", "null"] },
          "merchant_name": { "type": ["string", "null"] },
          "metadata": { "type": "object", "additionalProperties": true },
          "payment_method": { "type": "string", "enum": ["sbp", "crypto"], "example": "sbp" },
          "provider": { "type": ["string", "null"], "enum": ["td", "cryptobot", "xrocket", "laveshka", "test", null], "description": "Кто выпустил счёт" },
          "asset": { "type": "string", "description": "Актив платежа: RUB или код крипто-актива" },
          "pay_url": { "type": ["string", "null"], "description": "Ссылка на счёт xRocket или CryptoBot для крипто-платежей" },
          "crypto_mode": { "type": ["string", "null"], "enum": ["invoice", "address", null], "description": "invoice — счёт xRocket/CryptoBot, address — прямой адрес USDT" },
          "network": { "type": ["string", "null"], "enum": ["TRX", "TON", "ETH", "BSC", null] },
          "network_label": { "type": ["string", "null"], "example": "TRON (TRC-20)" },
          "deposit_address": { "type": ["string", "null"], "description": "Адрес USDT для прямой оплаты" },
          "received_amount": { "type": ["number", "null"] },
          "credited_amount": { "type": ["number", "null"] },
          "test": { "type": "boolean" },
          "created_at": { "type": "string", "format": "date-time" },
          "expires_at": { "type": "string", "format": "date-time" },
          "paid_at": { "type": ["string", "null"], "format": "date-time" },
          "canceled_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean", "const": false },
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "param": { "type": "string" }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/payments": {
      "post": {
        "summary": "Создать платёж",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": { "type": "string", "maxLength": 128 }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["amount", "description"],
                "properties": {
                  "amount": { "type": "number", "minimum": 0.000001, "maximum": 1000000, "description": "RUB: от 9,35 до 100 000 (зависит от fee_policy); крипта: сумма в выбранном активе (USDT/USDC от 0.1, BTC от 0.0001)" },
                  "currency": { "type": "string", "enum": ["RUB", "USDT", "USDC", "BTC", "ETH", "GRAM", "TON", "SOL", "BNB", "TRX", "LTC", "XAUT", "DOGE"], "default": "RUB" },
                  "description": { "type": "string", "maxLength": 255 },
                  "metadata": { "type": "object", "additionalProperties": true },
                  "callback_url": { "type": "string", "format": "uri" },
                  "expires_in": { "type": "integer", "minimum": 300, "maximum": 7200, "default": 600, "description": "СБП: 300–1800 сек; крипта: 600–7200 сек" },
                  "payment_method": { "type": "string", "enum": ["sbp", "crypto", "crypto_address"], "default": "sbp" },
                  "provider": { "type": "string", "enum": ["auto", "cryptobot", "xrocket", "laveshka"], "default": "auto", "description": "Для crypto: cryptobot/xrocket; laveshka — только crypto_address" },
                  "fee_policy": { "type": "string", "enum": ["client_all", "client_service", "client_gateway", "merchant", "choice"], "description": "Кто платит комиссии. client_gateway — только касса на клиенте (старый client), client_service — только сервис, client_all — всё на клиенте, merchant — всё на мерчанте, choice — выбор клиента на оплате" },
                  "fee_bearer": { "type": "string", "enum": ["client", "merchant"], "description": "Устаревший алиас fee_policy: client = client_gateway, merchant = merchant" },
                  "pay_asset": { "type": "string", "enum": ["USDC"], "description": "Только для currency=USDT и provider=cryptobot: счёт в USDC, зачисление USDT 1:1" },
                  "network": { "type": "string", "enum": ["TRX", "TON", "ETH", "BSC"], "description": "Сеть USDT для прямой оплаты по адресу (TRON, TON, Ethereum, BNB Chain)" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Платёж создан",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean", "const": true },
                    "payment": { "$ref": "#/components/schemas/Payment" },
                    "checkout_url": { "type": "string", "format": "uri" },
                    "pay_amount": { "type": ["number", "null"] },
                    "fee_bearer": { "type": "string", "enum": ["client", "merchant", "choice"] },
                    "fee_policy": { "type": "string", "enum": ["client_all", "client_service", "client_gateway", "merchant", "choice"] },
                    "fee_choices": { "type": ["array", "null"], "items": { "type": "object" } },
                    "selected_fee": { "type": ["string", "null"], "enum": ["client_all", "merchant", null] },
                    "pay_asset": { "type": "string" },
                    "gateway_amount": { "type": ["number", "null"] },
                    "cashier_fee": { "type": ["number", "null"] },
                    "sbp_url": { "type": ["string", "null"], "format": "uri" },
                    "pay_url": { "type": ["string", "null"], "description": "Ссылка на счёт xRocket/CryptoBot" },
                    "deposit_address": { "type": ["string", "null"], "description": "Адрес USDT для прямой оплаты" },
                    "network": { "type": ["string", "null"] },
                    "network_label": { "type": ["string", "null"] },
                    "crypto_mode": { "type": ["string", "null"] },
                    "provider": { "type": ["string", "null"] },
                    "asset": { "type": "string" }
                  }
                }
              }
            }
          },
          "400": { "description": "Ошибка валидации", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "description": "Неверный ключ", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Лимит запросов", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "502": { "description": "Касса недоступна", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      },
      "get": {
        "summary": "Список платежей",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 25 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "minimum": 0, "default": 0 } },
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["pending", "paid", "expired", "canceled"] } }
        ],
        "responses": {
          "200": {
            "description": "Список платежей",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean", "const": true },
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/Payment" } },
                    "total": { "type": "integer" },
                    "limit": { "type": "integer" },
                    "offset": { "type": "integer" },
                    "has_more": { "type": "boolean" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/payments/{id}": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
      "get": {
        "summary": "Статус платежа",
        "responses": {
          "200": { "description": "Платёж", "content": { "application/json": { "schema": { "type": "object", "properties": { "ok": { "const": true }, "payment": { "$ref": "#/components/schemas/Payment" }, "checkout_url": { "type": "string" }, "sbp_url": { "type": ["string", "null"] } } } } } },
          "404": { "description": "Не найден", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      },
      "post": {
        "summary": "Отменить платёж",
        "responses": {
          "200": { "description": "Отменён", "content": { "application/json": { "schema": { "type": "object", "properties": { "ok": { "const": true }, "payment": { "$ref": "#/components/schemas/Payment" } } } } } },
          "409": { "description": "Уже оплачен или истёк", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/balance": {
      "get": {
        "summary": "Баланс проекта и общий кошелёк MENT PAY",
        "responses": {
          "200": {
            "description": "Баланс проекта и основного кошелька",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "const": true },
                    "object": { "const": "balance" },
                    "project": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "name": { "type": "string" },
                        "fee_bearer": { "type": "string", "enum": ["client", "merchant", "choice"] },
                        "fee_policy": { "type": "string", "enum": ["client_all", "client_service", "client_gateway", "merchant", "choice"] },
                        "fee_pct": { "type": "number", "example": 6.5 },
                        "fee_source": { "type": "string", "enum": ["tier", "custom", "default"] },
                        "fee_tier": { "type": "string" },
                        "auto_withdraw": { "type": "boolean" }
                      }
                    },
                    "commission": {
                      "type": "object",
                      "properties": {
                        "current_pct": { "type": "number", "example": 6.5 },
                        "base_pct": { "type": "number", "example": 7 },
                        "min_pct": { "type": "number", "example": 5 },
                        "volume_rub": { "type": "number" },
                        "progress_pct": { "type": "number" }
                      }
                    },
                    "available": {
                      "type": "object",
                      "additionalProperties": { "type": "number" },
                      "description": "Баланс проекта в RUB, USDT и любых зачисленных крипто-активах"
                    },
                    "project_balance": {
                      "type": "object",
                      "additionalProperties": { "type": "number" },
                      "description": "Баланс проекта в RUB, USDT и любых зачисленных крипто-активах"
                    },
                    "ment_balance": {
                      "type": "object",
                      "additionalProperties": { "type": "number" },
                      "description": "Баланс кошелька MENT PAY: RUB, USDT, GRAM и другие активы"
                    },
                    "currency": { "const": "RUB" },
                    "mode": { "type": "string", "enum": ["live", "test"] }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/withdraw": {
      "get": {
        "summary": "История выводов средств проекта на баланс MENT PAY",
        "responses": {
          "200": { "description": "Список выводов" }
        }
      },
      "post": {
        "summary": "Вывести средства проекта на основной баланс MENT PAY (0%, live-ключ)",
        "parameters": [
          { "name": "Idempotency-Key", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "asset": { "type": "string", "enum": ["RUB", "USDT", "USDC", "BTC", "ETH", "GRAM", "TON", "SOL", "BNB", "TRX", "LTC", "XAUT", "DOGE"], "default": "RUB", "description": "Любой актив с баланса проекта" },
                  "amount": { "type": "number", "minimum": 0.01 },
                  "all": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Средства переведены на баланс MENT PAY" },
          "400": { "description": "Некорректная сумма или недостаточно средств" },
          "403": { "description": "Требуется live-ключ" },
          "409": { "description": "Вывод по проекту уже выполняется" }
        }
      }
    }
  }
}
