{
  "openapi": "3.0.3",
  "info": {
    "title": "IBRESE merchant-pos HTTP API",
    "version": "0.1.0",
    "description": "Application-layer till and shop API. Not a payment company. consensusAuthority and finalityAuthority are always false. Run this service yourself; ibrese.com does not host it."
  },
  "servers": [
    {
      "url": "http://127.0.0.1:8101",
      "description": "Local merchant-pos (default)"
    }
  ],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/": {
      "get": {
        "summary": "Till UI",
        "security": [],
        "responses": { "200": { "description": "HTML kasa ekranı" } }
      }
    },
    "/v1/info": {
      "get": {
        "summary": "Servis kimliği",
        "security": [],
        "responses": {
          "200": {
            "description": "role merchant-pos; consensusAuthority false",
            "content": {
              "application/json": {
                "example": {
                  "role": "merchant-pos",
                  "consensusAuthority": false,
                  "finalityAuthority": false,
                  "networkId": "ibrese",
                  "chainId": "ibrese-l1"
                }
              }
            }
          }
        }
      }
    },
    "/v1/health": {
      "get": {
        "summary": "Sağlık",
        "security": [],
        "responses": { "200": { "description": "ok + info" } }
      }
    },
    "/v1/pos/devices": {
      "post": {
        "summary": "Kasa / shop cihazı kaydı",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/RegisterDevice" },
              "example": {
                "name": "Kasa-1",
                "webhookUrl": "https://shop.example/ibrese/webhook",
                "recipient": "optional-64-hex-override"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "apiKey ve webhookSecret yalnız bir kez döner",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DeviceCreated" }
              }
            }
          }
        }
      }
    },
    "/v1/pos/invoices": {
      "post": {
        "summary": "Fatura + QR + URI",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreateInvoice" },
              "example": {
                "amount": "1250000",
                "merchantReference": "ORDER-123",
                "memo": "IBRESE POS"
              }
            }
          }
        },
        "responses": {
          "201": { "description": "Invoice payload + qrPng data URL" }
        }
      },
      "get": {
        "summary": "Bu cihazın faturaları",
        "responses": { "200": { "description": "{ invoices: [...] }" } }
      }
    },
    "/v1/pos/invoices/{paymentId}": {
      "get": {
        "summary": "Fatura durumu (node gözlemi, otorite değil)",
        "parameters": [
          {
            "name": "paymentId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": { "200": { "description": "Invoice + lastVerification" } }
      }
    },
    "/v1/pos/webhooks/test": {
      "post": {
        "summary": "Kayıtlı URL'ye pos.ping gönder",
        "responses": {
          "200": { "description": "Teslim 2xx" },
          "502": { "description": "Webhook URL yanıt vermedi" }
        }
      }
    },
    "/v1/pos/poll": {
      "post": {
        "summary": "Bekleyen faturaları node'dan yenile ve webhook dağıt",
        "responses": { "200": { "description": "{ results, authoritative: false }" } }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "apiKey",
        "description": "Cihaz kaydında bir kez dönen apiKey"
      }
    },
    "schemas": {
      "RegisterDevice": {
        "type": "object",
        "required": ["name", "webhookUrl"],
        "properties": {
          "name": { "type": "string" },
          "webhookUrl": {
            "type": "string",
            "description": "http(s). Kullanıcı/şifre yok. Üretimde https."
          },
          "recipient": {
            "type": "string",
            "description": "64-hex IBR adresi. Yoksa POS_MERCHANT_ADDRESS."
          }
        }
      },
      "DeviceCreated": {
        "type": "object",
        "properties": {
          "deviceId": { "type": "string" },
          "name": { "type": "string" },
          "webhookUrl": { "type": "string" },
          "apiKey": { "type": "string" },
          "webhookSecret": { "type": "string" },
          "recipient": { "type": "string" },
          "createdAt": { "type": "integer" },
          "note": { "type": "string" }
        }
      },
      "CreateInvoice": {
        "type": "object",
        "required": ["amount"],
        "properties": {
          "amount": {
            "type": "string",
            "description": "Pozitif ondalık string; native IBR alt birim (5 ondalık). 12,50 IBR = \"1250000\"."
          },
          "merchantReference": { "type": "string" },
          "memo": { "type": "string" },
          "expiration": {
            "type": "integer",
            "description": "unix ms; 0 = yok"
          },
          "alias": { "type": "string" }
        }
      }
    }
  }
}
