{
  "openapi": "3.1.0",
  "info": {
    "title": "Ручки подписок",
    "version": "1"
  },
  "servers": [
    {
      "url": "https://api.x-hub.online/api/v1"
    }
  ],
  "paths": {
    "/subscriptions": {
      "post": {
        "operationId": "createSubscription",
        "summary": "Создать подписку",
        "security": [
          {
            "apiKey": [],
            "apiSecret": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "UUID (RFC 4122). Повтор с тем же ключом возвращает исходный ресурс."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/createSubscriptionRequestBody"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listSubscriptions",
        "summary": "Список подписок",
        "security": [
          {
            "apiKey": [],
            "apiSecret": []
          }
        ]
      }
    },
    "/subscriptions/{id}": {
      "get": {
        "operationId": "getSubscription",
        "summary": "Получить подписку",
        "security": [
          {
            "apiKey": [],
            "apiSecret": []
          }
        ]
      },
      "patch": {
        "operationId": "patchSubscription",
        "summary": "Изменить подписку",
        "security": [
          {
            "apiKey": [],
            "apiSecret": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/patchSubscriptionRequestBody"
              }
            }
          }
        }
      }
    },
    "/subscriptions/{id}/charges": {
      "post": {
        "operationId": "createCharge",
        "summary": "Списать по подписке",
        "security": [
          {
            "apiKey": [],
            "apiSecret": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "UUID (RFC 4122). Повтор с тем же ключом возвращает исходный ресурс."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/createChargeRequestBody"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listCharges",
        "summary": "Списания по подписке",
        "security": [
          {
            "apiKey": [],
            "apiSecret": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key"
      },
      "apiSecret": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Secret"
      }
    },
    "schemas": {
      "createSubscriptionRequestBody": {
        "type": "object",
        "properties": {
          "amount_rub": {
            "type": "string",
            "pattern": "^\\d{1,10}(\\.\\d{1,2})?$"
          },
          "interval": {
            "type": "string",
            "enum": [
              "day",
              "week",
              "month"
            ]
          },
          "interval_count": {
            "type": "integer",
            "exclusiveMinimum": true,
            "minimum": 0,
            "default": 1
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32
          },
          "external_id": {
            "type": "string",
            "maxLength": 256
          },
          "success_url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048
          },
          "client_ref": {
            "type": "string",
            "maxLength": 256
          },
          "client_phone": {
            "type": "string",
            "maxLength": 32
          },
          "method_id": {
            "type": "string",
            "format": "uuid"
          },
          "shop_id": {
            "type": "string",
            "format": "uuid"
          },
          "binding_charge": {
            "type": "string",
            "enum": [
              "first",
              "none"
            ],
            "default": "first"
          }
        },
        "required": [
          "amount_rub",
          "interval",
          "description"
        ],
        "additionalProperties": false
      },
      "patchSubscriptionRequestBody": {
        "type": "object",
        "properties": {
          "amount_rub": {
            "type": "string",
            "pattern": "^\\d{1,10}(\\.\\d{1,2})?$"
          },
          "cap_amount_rub": {
            "type": "string",
            "pattern": "^\\d{1,10}(\\.\\d{1,2})?$"
          },
          "cap_window_rub": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^\\d{1,10}(\\.\\d{1,2})?$"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "additionalProperties": false,
        "description": "Хотя бы одно из полей amount_rub, cap_amount_rub, cap_window_rub обязательно."
      },
      "createChargeRequestBody": {
        "type": "object",
        "properties": {
          "amount_rub": {
            "type": "string",
            "pattern": "^\\d{1,10}(\\.\\d{1,2})?$"
          },
          "external_id": {
            "type": "string",
            "maxLength": 256
          }
        },
        "required": [
          "amount_rub"
        ],
        "additionalProperties": false
      }
    }
  }
}
