openapi: 3.1.0
info:
  title: Wasabi API
  version: '1.0'
  description: |
    Partner API of the **Wasabi** digital store: a catalog of subscriptions, games and top-up codes.
    Ordering, charging the partner balance and delivering the item happen in **a single request** —
    the response to `POST /v1/orders` already contains the account, the code or the top-up confirmation.

    ## Authentication

    Every request requires an API key in the `Authorization` header:

    ```http
    Authorization: Bearer wsb_live_9f2c4a7e1b8d3f6a
    ```

    There are two kinds of keys: `wsb_live_…` for production and `wsb_test_…` for testing.
    Keys are issued and revoked in the partner dashboard. Never expose a key
    in frontend code and never commit it to a repository.

    ## Idempotency

    Send an `Idempotency-Key` header (any unique string up to 64 characters, e.g. a UUID)
    when creating an order. A repeated request with the same key returns the order that was already created
    and **does not charge you twice** — so it is safe to retry requests after a network failure.
    The key is kept for 24 hours. If you send a different request body with the same key, the API returns `409 idempotency_conflict`.

    ## Webhooks

    Set a URL in the partner dashboard and Wasabi will send `POST` requests with events
    (`order.delivered`, `order.processing`, `order.failed`, `balance.topup`).
    Every request is signed: the `X-Wasabi-Signature` header contains an HMAC-SHA256
    of the request body computed with the webhook secret (`whsec_…`), in hex.

    ```
    X-Wasabi-Signature: t=1764763200,v1=5f8a3c…e91b
    ```

    The signature is computed over the string `{t}.{raw_body}`. Compare signatures in constant time
    and reject events older than 5 minutes. If your server does not respond with `2xx`, delivery is retried
    with exponential backoff (1 min, 5 min, 30 min, 2 h, 6 h…) for up to 24 hours until a `2xx` is received.
    Events may arrive more than once — process them idempotently by `data.id`.

    ## Test mode

    With a `wsb_test_…` key the API behaves exactly like production, but without real charges or purchases:
    orders return test data, the balance is virtual and webhooks go to the test URL.
    Test and production data are fully isolated.

    ## MCP

    An MCP server is available for AI agents (Claude, ChatGPT, Cursor and others):

    ```
    https://api.wasabi.guru/mcp
    ```

    Authorization uses the same Bearer key. Tools:

    | Tool | What it does |
    |---|---|
    | `search_products` | Search the catalog with a category filter |
    | `create_order` | Create an order and deliver the item |
    | `get_order` | Order status and contents |
    | `get_balance` | Current partner balance |

    We recommend giving the agent a test key until the flow is fully debugged.
  contact:
    name: Wasabi support
    url: https://wasabi.guru
servers:
- url: https://api.wasabi.guru
  description: Production and test mode (determined by the key)
security:
- bearerAuth: []
tags:
- name: Catalog
  description: Products, prices, availability and the data required to order.
- name: Orders
  description: Create orders with instant delivery and view history.
- name: Balance
  description: Partner balance and transaction history.
- name: Webhooks
  description: Events that Wasabi sends to your server.
paths:
  /v1/products:
    get:
      tags:
      - Catalog
      operationId: listProducts
      summary: List products
      description: Returns catalog products with partner prices. Supports category filtering, search and pagination.
      parameters:
      - name: category
        in: query
        description: Product category.
        schema:
          $ref: '#/components/schemas/Category'
        example: ai
      - name: q
        in: query
        description: Search by name.
        schema:
          type: string
        example: chatgpt
      - name: page
        in: query
        description: Page number, starting from 1.
        schema:
          type: integer
          minimum: 1
          default: 1
      - name: limit
        in: query
        description: Number of products per page.
        schema:
          type: integer
          minimum: 1
          maximum: 100
          default: 20
      responses:
        '200':
          description: List of products.
          content:
            application/json:
              schema:
                type: object
                required:
                - data
                - page
                - limit
                - total
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Product'
                  page:
                    type: integer
                    example: 1
                  limit:
                    type: integer
                    example: 20
                  total:
                    type: integer
                    description: Total products matching the filter.
                    example: 3
              example:
                data:
                - id: chatgpt-plus-1m
                  name: ChatGPT Plus — 1 month
                  category: ai
                  type: account
                  price: 1990
                  currency: RUB
                  in_stock: true
                  fields:
                  - name: email
                    label: Account email
                    type: email
                    required: true
                - id: claude-pro-1m
                  name: Claude Pro — 1 month
                  category: ai
                  type: account
                  price: 2190
                  currency: RUB
                  in_stock: true
                  fields:
                  - name: email
                    label: Account email
                    type: email
                    required: true
                - id: midjourney-basic-1m
                  name: Midjourney Basic — 1 month
                  category: ai
                  type: code
                  price: 1090
                  currency: RUB
                  in_stock: false
                  fields: []
                page: 1
                limit: 20
                total: 3
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/products/{id}:
    get:
      tags:
      - Catalog
      operationId: getProduct
      summary: Get product
      description: Returns the product card with its price, availability and the list of fields required when ordering.
      parameters:
      - name: id
        in: path
        required: true
        description: Product ID.
        schema:
          type: string
        example: steam-topup
      responses:
        '200':
          description: Product.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Product'
              examples:
                topup:
                  summary: Steam top-up
                  value:
                    id: steam-topup
                    name: Steam top-up
                    category: topup
                    type: topup
                    price: null
                    currency: RUB
                    min_amount: 100
                    max_amount: 50000
                    fee_percent: 6
                    in_stock: true
                    fields:
                    - name: login
                      label: Steam login
                      type: string
                      required: true
                    - name: region
                      label: Account region
                      type: string
                      required: false
                      enum:
                      - RU
                      - KZ
                      - CIS
                account:
                  summary: ChatGPT Plus
                  value:
                    id: chatgpt-plus-1m
                    name: ChatGPT Plus — 1 month
                    category: ai
                    type: account
                    price: 1990
                    currency: RUB
                    in_stock: true
                    fields:
                    - name: email
                      label: Account email
                      type: email
                      required: true
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/orders:
    post:
      tags:
      - Orders
      operationId: createOrder
      summary: Create order
      description: |
        Creates an order, charges the partner balance and delivers the item right away.
        For most products the response comes with status `delivered` and a filled `item`.
        If delivery takes time, the order is returned with status `processing` — the final status arrives via webhook
        or through `GET /v1/orders/{id}`. If delivery fails, the funds are returned to the balance (`refunded`).
      parameters:
      - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOrderRequest'
            examples:
              chatgpt:
                summary: ChatGPT Plus for 1 month
                value:
                  product: chatgpt-plus-1m
                  qty: 1
                  fields:
                    email: anna@example.com
                  external_id: shop-10482
              steam:
                summary: Steam top-up of 1000 ₽
                value:
                  product: steam-topup
                  amount: 1000
                  fields:
                    login: player_one
                  external_id: shop-10483
      responses:
        '201':
          description: Order created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
              examples:
                chatgpt:
                  summary: ChatGPT Plus account delivered
                  value:
                    id: ord_8KQ2
                    status: delivered
                    product: chatgpt-plus-1m
                    qty: 1
                    external_id: shop-10482
                    charged: 1990
                    currency: RUB
                    balance: 86400
                    item:
                      type: account
                      login: anna@example.com
                      password: Wq7!rP2m-x9L
                      expires_at: '2027-01-03T12:00:00Z'
                      instructions: Sign in at chatgpt.com with these credentials and change the password.
                    created_at: '2026-12-03T12:00:00Z'
                    delivered_at: '2026-12-03T12:00:02Z'
                steam:
                  summary: Steam top-up completed
                  value:
                    id: ord_8KQ3
                    status: delivered
                    product: steam-topup
                    qty: 1
                    amount: 1000
                    external_id: shop-10483
                    charged: 1060
                    currency: RUB
                    balance: 85340
                    item:
                      type: topup
                      login: player_one
                      amount: 1000
                      currency: RUB
                    created_at: '2026-12-03T12:05:00Z'
                    delivered_at: '2026-12-03T12:05:04Z'
        '200':
          description: Repeated request with the same `Idempotency-Key` — the previously created order is returned, no second charge.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientBalance'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/IdempotencyConflict'
        '429':
          $ref: '#/components/responses/RateLimited'
    get:
      tags:
      - Orders
      operationId: listOrders
      summary: List orders
      description: Returns the partner's orders from newest to oldest. Pagination is cursor-based — pass `next_cursor` from the response to the `cursor` parameter.
      parameters:
      - name: status
        in: query
        description: Filter by status.
        schema:
          $ref: '#/components/schemas/OrderStatus'
      - $ref: '#/components/parameters/Cursor'
      - $ref: '#/components/parameters/Limit'
      responses:
        '200':
          description: Page of orders.
          content:
            application/json:
              schema:
                type: object
                required:
                - data
                - has_more
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Order'
                  has_more:
                    type: boolean
                  next_cursor:
                    type:
                    - string
                    - 'null'
              example:
                data:
                - id: ord_8KQ3
                  status: delivered
                  product: steam-topup
                  qty: 1
                  amount: 1000
                  external_id: shop-10483
                  charged: 1060
                  currency: RUB
                  balance: 85340
                  item:
                    type: topup
                    login: player_one
                    amount: 1000
                    currency: RUB
                  created_at: '2026-12-03T12:05:00Z'
                  delivered_at: '2026-12-03T12:05:04Z'
                - id: ord_8KQ2
                  status: delivered
                  product: chatgpt-plus-1m
                  qty: 1
                  external_id: shop-10482
                  charged: 1990
                  currency: RUB
                  balance: 86400
                  item:
                    type: account
                    login: anna@example.com
                    password: Wq7!rP2m-x9L
                    expires_at: '2027-01-03T12:00:00Z'
                  created_at: '2026-12-03T12:00:00Z'
                  delivered_at: '2026-12-03T12:00:02Z'
                has_more: true
                next_cursor: ord_8KQ1
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/orders/{id}:
    get:
      tags:
      - Orders
      operationId: getOrder
      summary: Get order
      description: Returns the order with its current status and the delivered item.
      parameters:
      - name: id
        in: path
        required: true
        description: Order ID.
        schema:
          type: string
        example: ord_8KQ2
      responses:
        '200':
          description: Order.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
              examples:
                code:
                  summary: Code delivered
                  value:
                    id: ord_8KR7
                    status: delivered
                    product: spotify-premium-3m
                    qty: 1
                    external_id: shop-10501
                    charged: 1290
                    currency: RUB
                    balance: 84050
                    item:
                      type: code
                      code: SPOT-7QH4-K9XM-2LPA
                      expires_at: '2027-12-31T23:59:59Z'
                      instructions: Redeem the code at spotify.com/redeem.
                    created_at: '2026-12-03T13:10:00Z'
                    delivered_at: '2026-12-03T13:10:01Z'
                processing:
                  summary: Order in progress
                  value:
                    id: ord_8KR8
                    status: processing
                    product: steam-topup
                    qty: 1
                    amount: 500
                    external_id: shop-10502
                    charged: 530
                    currency: RUB
                    balance: 83520
                    item: null
                    created_at: '2026-12-03T13:12:00Z'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/balance:
    get:
      tags:
      - Balance
      operationId: getBalance
      summary: Get balance
      description: Returns the partner's available balance and the amount reserved for orders in progress.
      responses:
        '200':
          description: Balance.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Balance'
              example:
                balance: 85340
                currency: RUB
                held: 530
                updated_at: '2026-12-03T12:05:04Z'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/balance/transactions:
    get:
      tags:
      - Balance
      operationId: listBalanceTransactions
      summary: Balance transactions
      description: Top-ups, order charges and refunds, from newest to oldest. Cursor-based pagination.
      parameters:
      - name: type
        in: query
        description: Filter by transaction type.
        schema:
          $ref: '#/components/schemas/TransactionType'
      - $ref: '#/components/parameters/Cursor'
      - $ref: '#/components/parameters/Limit'
      responses:
        '200':
          description: Page of transactions.
          content:
            application/json:
              schema:
                type: object
                required:
                - data
                - has_more
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Transaction'
                  has_more:
                    type: boolean
                  next_cursor:
                    type:
                    - string
                    - 'null'
              example:
                data:
                - id: txn_5Hd2
                  type: charge
                  amount: -1060
                  currency: RUB
                  balance_after: 85340
                  order_id: ord_8KQ3
                  description: Steam top-up — 1000 ₽
                  created_at: '2026-12-03T12:05:00Z'
                - id: txn_5Hd1
                  type: charge
                  amount: -1990
                  currency: RUB
                  balance_after: 86400
                  order_id: ord_8KQ2
                  description: ChatGPT Plus — 1 month
                  created_at: '2026-12-03T12:00:00Z'
                - id: txn_5Hc9
                  type: topup
                  amount: 50000
                  currency: RUB
                  balance_after: 88390
                  order_id: null
                  description: 'Balance top-up, invoice #2471'
                  created_at: '2026-12-02T09:30:00Z'
                has_more: false
                next_cursor: null
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
webhooks:
  order.delivered:
    post:
      tags:
      - Webhooks
      operationId: webhookOrderDelivered
      summary: Order delivered
      description: The item was delivered successfully. Sent both for orders delivered instantly and for those that were in progress.
      parameters:
      - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderEvent'
            example:
              event: order.delivered
              created_at: '2026-12-03T12:05:04Z'
              data:
                id: ord_8KQ3
                status: delivered
                product: steam-topup
                qty: 1
                amount: 1000
                external_id: shop-10483
                charged: 1060
                currency: RUB
                balance: 85340
                item:
                  type: topup
                  login: player_one
                  amount: 1000
                  currency: RUB
                created_at: '2026-12-03T12:05:00Z'
                delivered_at: '2026-12-03T12:05:04Z'
      responses:
        '200':
          description: Event accepted. Any `2xx` response stops retries.
  order.processing:
    post:
      tags:
      - Webhooks
      operationId: webhookOrderProcessing
      summary: Order in progress
      description: Delivery takes some time. The amount is already reserved; wait for `order.delivered` or `order.failed`.
      parameters:
      - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderEvent'
            example:
              event: order.processing
              created_at: '2026-12-03T13:12:00Z'
              data:
                id: ord_8KR8
                status: processing
                product: steam-topup
                qty: 1
                amount: 500
                external_id: shop-10502
                charged: 530
                currency: RUB
                balance: 83520
                item: null
                created_at: '2026-12-03T13:12:00Z'
      responses:
        '200':
          description: Event accepted.
  order.failed:
    post:
      tags:
      - Webhooks
      operationId: webhookOrderFailed
      summary: Order failed
      description: The item could not be delivered. The charged amount is returned to the balance and the order moves to `refunded`.
      parameters:
      - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderEvent'
            example:
              event: order.failed
              created_at: '2026-12-03T13:20:00Z'
              data:
                id: ord_8KR8
                status: refunded
                product: steam-topup
                qty: 1
                amount: 500
                external_id: shop-10502
                charged: 0
                currency: RUB
                balance: 84050
                item: null
                failure:
                  code: account_not_found
                  message: Steam account with login player_two was not found.
                created_at: '2026-12-03T13:12:00Z'
      responses:
        '200':
          description: Event accepted.
  balance.topup:
    post:
      tags:
      - Webhooks
      operationId: webhookBalanceTopup
      summary: Balance topped up
      description: Funds have been credited to the partner balance.
      parameters:
      - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BalanceTopupEvent'
            example:
              event: balance.topup
              created_at: '2026-12-02T09:30:00Z'
              data:
                id: txn_5Hc9
                type: topup
                amount: 50000
                currency: RUB
                balance_after: 88390
                order_id: null
                description: 'Balance top-up, invoice #2471'
                created_at: '2026-12-02T09:30:00Z'
      responses:
        '200':
          description: Event accepted.
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: wsb_live_… / wsb_test_…
      description: Partner API key. `wsb_live_…` for production, `wsb_test_…` for testing.
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: Unique request key. Repeating with the same key returns the same order without a second charge.
      schema:
        type: string
        maxLength: 64
      example: 3f1c9a52-7d4e-4b8a-9c21-6e0f5b7a8d13
    Cursor:
      name: cursor
      in: query
      description: Cursor of the next page (`next_cursor` from the previous response).
      schema:
        type: string
      example: ord_8KQ1
    Limit:
      name: limit
      in: query
      description: Number of records per page.
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 20
    WebhookSignature:
      name: X-Wasabi-Signature
      in: header
      required: true
      description: 'HMAC-SHA256 signature: `t={unix_time},v1={hex(hmac_sha256(secret, t + "." + raw_body))}`.'
      schema:
        type: string
      example: t=1764763504,v1=5f8a3c0d2b9e47a1c6f3e8d0b5a7294c1e6f8a3d0b2c9e47a15f8a3c0d2be91b
  schemas:
    Category:
      type: string
      description: |
        Product category:
        - `ai` — AI tools
        - `music` — music
        - `games` — games
        - `topup` — top-ups
        - `telegram` — Telegram
        - `study` — education
      enum:
      - ai
      - music
      - games
      - topup
      - telegram
      - study
    ProductType:
      type: string
      description: |
        How the item is delivered:
        - `account` — account credentials (login and password)
        - `code` — activation code
        - `topup` — top-up to the given login
      enum:
      - account
      - code
      - topup
    ProductField:
      type: object
      description: A field to pass in `fields` when ordering.
      required:
      - name
      - label
      - type
      - required
      properties:
        name:
          type: string
          description: Key in the `fields` object.
          example: login
        label:
          type: string
          description: Field name shown to the customer.
          example: Steam login
        type:
          type: string
          enum:
          - string
          - email
          - phone
          example: string
        required:
          type: boolean
          example: true
        enum:
          type: array
          description: Allowed values, if the list is restricted.
          items:
            type: string
          example:
          - RU
          - KZ
          - CIS
    Product:
      type: object
      required:
      - id
      - name
      - category
      - type
      - price
      - currency
      - in_stock
      - fields
      properties:
        id:
          type: string
          description: Product ID.
          example: chatgpt-plus-1m
        name:
          type: string
          example: ChatGPT Plus — 1 month
        category:
          $ref: '#/components/schemas/Category'
        type:
          $ref: '#/components/schemas/ProductType'
        price:
          type:
          - number
          - 'null'
          description: Partner price in rubles. `null` for top-ups — the total is calculated from `amount` including `fee_percent`.
          example: 1990
        currency:
          type: string
          const: RUB
          example: RUB
        min_amount:
          type: number
          description: '`topup` only — minimum top-up amount.'
          example: 100
        max_amount:
          type: number
          description: '`topup` only — maximum top-up amount.'
          example: 50000
        fee_percent:
          type: number
          description: '`topup` only — fee as a percentage of the amount.'
          example: 6
        in_stock:
          type: boolean
          description: Whether the product is in stock right now.
          example: true
        fields:
          type: array
          description: What data is required to order (email, login, region…).
          items:
            $ref: '#/components/schemas/ProductField'
    CreateOrderRequest:
      type: object
      required:
      - product
      properties:
        product:
          type: string
          description: Product ID.
          example: steam-topup
        qty:
          type: integer
          minimum: 1
          maximum: 50
          default: 1
          description: Quantity. Always 1 for top-ups.
          example: 1
        amount:
          type: number
          description: Top-up amount in rubles. Required for `topup` products.
          example: 1000
        fields:
          type: object
          description: Delivery data — keys from `Product.fields`.
          additionalProperties:
            type: string
          example:
            login: player_one
        external_id:
          type: string
          maxLength: 128
          description: Your order ID — returned in the response and in webhooks.
          example: shop-10483
    OrderStatus:
      type: string
      description: |
        - `processing` — amount reserved, item is being delivered
        - `delivered` — item delivered
        - `failed` — delivery failed
        - `refunded` — funds returned to the balance
      enum:
      - processing
      - delivered
      - failed
      - refunded
    OrderItem:
      type: object
      description: Delivered item. The set of fields depends on `type`.
      required:
      - type
      properties:
        type:
          $ref: '#/components/schemas/ProductType'
        code:
          type: string
          description: Activation code (`code`).
          example: SPOT-7QH4-K9XM-2LPA
        login:
          type: string
          description: Account login (`account`) or the account that was topped up (`topup`).
          example: anna@example.com
        password:
          type: string
          description: Account password (`account`).
          example: Wq7!rP2m-x9L
        amount:
          type: number
          description: Credited amount (`topup`).
          example: 1000
        currency:
          type: string
          example: RUB
        expires_at:
          type:
          - string
          - 'null'
          format: date-time
          description: When the subscription or code expires.
          example: '2027-01-03T12:00:00Z'
        instructions:
          type: string
          description: Instructions for the customer.
          example: Sign in at chatgpt.com with these credentials and change the password.
    Order:
      type: object
      required:
      - id
      - status
      - product
      - qty
      - charged
      - currency
      - balance
      - created_at
      properties:
        id:
          type: string
          example: ord_8KQ2
        status:
          $ref: '#/components/schemas/OrderStatus'
        product:
          type: string
          example: chatgpt-plus-1m
        qty:
          type: integer
          example: 1
        amount:
          type: number
          description: Top-up amount (for `topup`).
          example: 1000
        external_id:
          type:
          - string
          - 'null'
          example: shop-10482
        charged:
          type: number
          description: Charged from the balance, ₽.
          example: 1990
        currency:
          type: string
          example: RUB
        balance:
          type: number
          description: Partner balance after the transaction, ₽.
          example: 86400
        item:
          description: Delivered item. `null` until the order is delivered.
          oneOf:
          - $ref: '#/components/schemas/OrderItem'
          - type: 'null'
        failure:
          type: object
          description: Failure reason (for `failed` and `refunded`).
          properties:
            code:
              type: string
              example: account_not_found
            message:
              type: string
              example: Steam account with login player_two was not found.
        created_at:
          type: string
          format: date-time
          example: '2026-12-03T12:00:00Z'
        delivered_at:
          type: string
          format: date-time
          example: '2026-12-03T12:00:02Z'
    Balance:
      type: object
      required:
      - balance
      - currency
      - held
      properties:
        balance:
          type: number
          description: Available for orders, ₽.
          example: 85340
        currency:
          type: string
          example: RUB
        held:
          type: number
          description: Reserved for orders in progress, ₽.
          example: 530
        updated_at:
          type: string
          format: date-time
          example: '2026-12-03T12:05:04Z'
    TransactionType:
      type: string
      description: |
        - `topup` — balance top-up
        - `charge` — charge for an order
        - `refund` — refund for a failed order
      enum:
      - topup
      - charge
      - refund
    Transaction:
      type: object
      required:
      - id
      - type
      - amount
      - currency
      - balance_after
      - created_at
      properties:
        id:
          type: string
          example: txn_5Hd2
        type:
          $ref: '#/components/schemas/TransactionType'
        amount:
          type: number
          description: Transaction amount, ₽. Charges are negative.
          example: -1060
        currency:
          type: string
          example: RUB
        balance_after:
          type: number
          example: 85340
        order_id:
          type:
          - string
          - 'null'
          example: ord_8KQ3
        description:
          type: string
          example: Steam top-up — 1000 ₽
        created_at:
          type: string
          format: date-time
          example: '2026-12-03T12:05:00Z'
    OrderEvent:
      type: object
      required:
      - event
      - created_at
      - data
      properties:
        event:
          type: string
          enum:
          - order.delivered
          - order.processing
          - order.failed
          example: order.delivered
        created_at:
          type: string
          format: date-time
          example: '2026-12-03T12:05:04Z'
        data:
          $ref: '#/components/schemas/Order'
    BalanceTopupEvent:
      type: object
      required:
      - event
      - created_at
      - data
      properties:
        event:
          type: string
          const: balance.topup
        created_at:
          type: string
          format: date-time
          example: '2026-12-02T09:30:00Z'
        data:
          $ref: '#/components/schemas/Transaction'
    Error:
      type: object
      required:
      - error
      properties:
        error:
          type: object
          required:
          - code
          - message
          properties:
            code:
              type: string
              description: Machine-readable error code.
              example: insufficient_balance
            message:
              type: string
              description: Error description for the developer.
              example: Insufficient balance.
  responses:
    BadRequest:
      description: Invalid request — fields are missing or filled in incorrectly.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: invalid_fields
              message: The fields.login field is required for the steam-topup product.
    Unauthorized:
      description: The key is missing, revoked or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: unauthorized
              message: Invalid or revoked API key.
    InsufficientBalance:
      description: Insufficient balance for the order.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: insufficient_balance
              message: 'Insufficient funds: 1060 ₽ required, 420 ₽ available.'
    NotFound:
      description: Resource not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: not_found
              message: Product netflix-premium-12m was not found.
    IdempotencyConflict:
      description: The idempotency key was already used with a different request body.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: idempotency_conflict
              message: Idempotency-Key has already been used for a different request.
    RateLimited:
      description: Rate limit exceeded. Retry after `Retry-After` seconds.
      headers:
        Retry-After:
          description: How many seconds to wait before retrying.
          schema:
            type: integer
          example: 2
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: rate_limited
              message: Too many requests. The limit is 60 per minute.
