{
  "openapi": "3.1.0",
  "info": {"title": "Hemera Pay Sandbox", "version": "1.0.0"},
  "servers": [{"url": "https://api.hemerapay.com"}],
  "security": [{"merchantToken": []}],
  "paths": {
    "/v1/quotes": {"post": {
      "operationId": "quote",
      "summary": "Calculate the 4% fee and total for a RUB order",
      "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/AmountInput"}}}},
      "responses": {"200": {"description": "Quote", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Quote"}}}}, "400": {"$ref": "#/components/responses/Invalid"}, "401": {"$ref": "#/components/responses/Unauthorized"}}
    }},
    "/v1/orders": {
      "post": {
        "operationId": "createOrder",
        "summary": "Create a checkout order",
        "description": "A merchant reference is idempotent. Reusing a reference with different order data returns 409.",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/OrderInput"}}}},
        "responses": {"201": {"$ref": "#/components/responses/Order"}, "200": {"$ref": "#/components/responses/Order"}, "400": {"$ref": "#/components/responses/Invalid"}, "401": {"$ref": "#/components/responses/Unauthorized"}, "409": {"description": "Merchant reference conflicts with existing order"}}
      },
      "get": {
        "operationId": "listOrders",
        "summary": "List the merchant's latest 100 orders",
        "responses": {"200": {"description": "Orders", "content": {"application/json": {"schema": {"type": "object", "required": ["orders"], "properties": {"orders": {"type": "array", "maxItems": 100, "items": {"$ref": "#/components/schemas/Order"}}}}}}}, "401": {"$ref": "#/components/responses/Unauthorized"}}
      }
    },
    "/v1/orders/{order_id}": {"get": {
      "operationId": "getOrder",
      "summary": "Get the verified status of a checkout order",
      "parameters": [{"name": "order_id", "in": "path", "required": true, "schema": {"type": "string", "pattern": "^hp_[0-9a-f]{28}$"}}],
      "responses": {"200": {"$ref": "#/components/responses/Order"}, "401": {"$ref": "#/components/responses/Unauthorized"}, "404": {"description": "Order not found for this merchant"}}
    }}
  },
  "components": {
    "securitySchemes": {"merchantToken": {"type": "http", "scheme": "bearer"}},
    "responses": {
      "Order": {"description": "Order and checkout URL", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Order"}}}},
      "Invalid": {"description": "Invalid request body"},
      "Unauthorized": {"description": "A valid merchant sandbox token is required"}
    },
    "schemas": {
      "AmountInput": {
        "type": "object", "required": ["amount_minor"],
        "properties": {"amount_minor": {"type": "integer", "minimum": 1, "maximum": 100000000, "description": "Order amount in kopecks", "examples": [10000]}, "currency": {"const": "RUB", "default": "RUB"}}
      },
      "OrderInput": {"allOf": [{"$ref": "#/components/schemas/AmountInput"}, {
        "type": "object", "required": ["reference", "description"],
        "properties": {"reference": {"type": "string", "pattern": "^[A-Za-z0-9._-]{1,80}$"}, "description": {"type": "string", "minLength": 1, "maxLength": 100}, "category": {"type": "integer", "enum": [1, 2], "default": 1, "description": "1 for goods, 2 for services"}}
      }]},
      "Quote": {
        "type": "object", "required": ["currency", "amount_minor", "fee_bps", "fee_minor", "total_minor"],
        "properties": {"currency": {"const": "RUB"}, "amount_minor": {"type": "integer"}, "fee_bps": {"const": 400}, "fee_minor": {"type": "integer"}, "total_minor": {"type": "integer"}}
      },
      "Order": {"allOf": [{"$ref": "#/components/schemas/Quote"}, {
        "type": "object", "required": ["order_id", "reference", "description", "status", "checkout_url", "created_at", "provider_transaction_id"],
        "properties": {
          "order_id": {"type": "string"}, "reference": {"type": "string"}, "description": {"type": "string"},
          "status": {"type": "string", "enum": ["created", "submitting", "pending", "verifying", "paid", "expired", "failed", "review"]},
          "checkout_url": {"type": "string", "format": "uri"}, "created_at": {"type": "string", "format": "date-time"}, "provider_transaction_id": {"type": ["string", "null"]}
        }
      }]}
    }
  }
}
