{
  "openapi": "3.0.3",
  "info": {
    "title": "QRPAY88 API",
    "version": "1.0.0",
    "description": "REST API agregator QRIS — pay-in QRIS, payout transfer bank, cek status, saldo. Model dompet prabayar."
  },
  "servers": [{ "url": "https://api.qrpay88.net" }],
  "security": [{ "ApiKey": [], "ApiSecret": [] }],
  "components": {
    "securitySchemes": {
      "ApiKey": { "type": "apiKey", "in": "header", "name": "x-api-key" },
      "ApiSecret": { "type": "apiKey", "in": "header", "name": "x-api-secret" }
    },
    "schemas": {
      "Order": {
        "type": "object",
        "properties": {
          "orderId": { "type": "string" },
          "gatewayRef": { "type": "string", "nullable": true },
          "amount": { "type": "integer" },
          "fee": { "type": "integer" },
          "net": { "type": "integer" },
          "qrString": { "type": "string", "nullable": true },
          "qrImage": { "type": "string", "nullable": true },
          "status": { "type": "string", "enum": ["PENDING", "PAID", "EXPIRED", "FAILED", "PROCESSING", "SUCCESS", "REVERSED"] },
          "paidAt": { "type": "string", "format": "date-time", "nullable": true }
        }
      },
      "Error": { "type": "object", "properties": { "error": { "type": "string" } } }
    }
  },
  "paths": {
    "/v1/qris": {
      "post": {
        "summary": "Buat QRIS (pay-in)",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": {
            "type": "object", "required": ["amount"],
            "properties": {
              "amount": { "type": "integer", "example": 10000 },
              "client_order_id": { "type": "string", "description": "Idempotency key" },
              "remark": { "type": "string" }
            }
          } } }
        },
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Order" } } } },
          "400": { "description": "Input salah", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "description": "Auth gagal" }
        }
      }
    },
    "/v1/order": {
      "get": {
        "summary": "Cek status order (QRIS / payout)",
        "parameters": [{ "name": "orderId", "in": "query", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Order" } } } },
          "404": { "description": "Tidak ditemukan" }
        }
      }
    },
    "/v1/payout": {
      "post": {
        "summary": "Kirim payout (transfer bank)",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": {
            "type": "object", "required": ["amount", "account_name", "account_no", "bank_id"],
            "properties": {
              "amount": { "type": "integer", "example": 50000 },
              "account_name": { "type": "string" },
              "account_no": { "type": "string" },
              "bank_id": { "type": "string", "description": "Kode bank gateway" },
              "client_order_id": { "type": "string" },
              "remark": { "type": "string" }
            }
          } } }
        },
        "responses": {
          "200": { "description": "Diterima (PROCESSING)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Order" } } } },
          "400": { "description": "Input salah / saldo tidak cukup" },
          "502": { "description": "Gateway menolak (saldo dikembalikan)" }
        }
      }
    },
    "/v1/balance": {
      "get": {
        "summary": "Cek saldo dompet agen",
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": {
            "type": "object", "properties": {
              "agent": { "type": "string" }, "balance": { "type": "integer" }, "currency": { "type": "string" }
            }
          } } } }
        }
      }
    },
    "/v1/banks": {
      "get": {
        "summary": "Daftar bank / e-wallet (untuk bank_id payout)",
        "parameters": [{ "name": "type", "in": "query", "required": false, "schema": { "type": "integer", "enum": [1, 2] }, "description": "1=bank & VA, 2=e-wallet, kosong=semua" }],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": {
            "type": "object", "properties": { "banks": { "type": "array", "items": {
              "type": "object", "properties": { "bankId": { "type": "integer" }, "name": { "type": "string" }, "type": { "type": "integer" } }
            } } }
          } } } }
        }
      }
    }
  }
}
