{
  "openapi": "3.1.0",
  "info": {
    "title": "BankGateway OpenBanking 2.0 API",
    "version": "2.0.0",
    "description": "Cổng API Tra cứu số tài khoản Napas 24/7, Giải mã VietQR EMVCo và Quản lý Ví theo chuẩn OpenBanking quốc tế. Hỗ trợ chữ ký số Ed25519, Idempotency RFC 8470 và độ trễ cực thấp O(1) Two-Tier Cache.",
    "contact": {
      "name": "BankGateway Support",
      "url": "https://t.me/bankgatewaypro",
      "email": "support@bankgateway.pro"
    }
  },
  "servers": [
    {
      "url": "https://api.bankgateway.pro",
      "description": "Production Server (HTTPS TLS 1.3)"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/api/v1/lookup": {
      "post": {
        "summary": "Tra cứu số tài khoản Napas 24/7",
        "description": "Tra cứu họ và tên chủ tài khoản thụ hưởng tại 68 Ngân hàng / Công ty tài chính theo thời gian thực (Real-time).",
        "operationId": "lookupAccount",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Mã UUID v4 duy nhất cho mỗi giao dịch chống trừ tiền trùng lặp khi mạng lag (RFC 8470).",
            "schema": {
              "type": "string",
              "example": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LookupRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tìm thấy thông tin tài khoản thụ hưởng (FOUND)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LookupSuccessResponse"
                }
              }
            }
          },
          "404": {
            "description": "Số tài khoản không tồn tại tại ngân hàng đích (NOT_FOUND)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Khóa API không hợp lệ hoặc thiếu header X-API-Key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP không nằm trong Whitelist hoặc hết hạn mức Quota",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "Cổng API đang tạm ngưng bảo trì định kỳ (Kill-Switch)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MaintenanceResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/wallet/balance": {
      "get": {
        "summary": "Kiểm tra số dư ví & Quota",
        "description": "Xem số dư khả dụng, tiền giữ chỗ và số lượt còn lại trong gói.",
        "operationId": "getWalletBalance",
        "responses": {
          "200": {
            "description": "Thông tin số dư ví và gói lượt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WalletBalanceResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/wallet/statement": {
      "get": {
        "summary": "Sao kê sổ cái (Ledger)",
        "description": "Lấy lịch sử giao dịch và biến động số dư đối soát.",
        "operationId": "getStatement",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Danh sách các bút toán biến động số dư"
          }
        }
      }
    },
    "/api/v1/vietqr/decode": {
      "post": {
        "summary": "Giải mã chuỗi VietQR EMVCo",
        "security": [],
        "operationId": "decodeVietQR",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["qrCode"],
                "properties": {
                  "qrCode": {
                    "type": "string",
                    "example": "00020101021238540010A00000072701240006970422011007838258880208QRIBFTTA53037045802VN63048596"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Dữ liệu ngân hàng và STK trích xuất từ mã QR"
          }
        }
      }
    },
    "/api/v1/banks": {
      "get": {
        "summary": "Danh mục 68 Ngân hàng / Công ty tài chính",
        "security": [],
        "operationId": "getBanksCatalog",
        "responses": {
          "200": {
            "description": "Danh sách mã ngân hàng và mã BIN Napas"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Khóa bí mật API cấp riêng cho tài khoản trên Dashboard."
      }
    },
    "schemas": {
      "LookupRequest": {
        "type": "object",
        "required": ["bankCode", "accountNumber"],
        "properties": {
          "bankCode": {
            "type": "string",
            "example": "MB",
            "description": "Mã ngân hàng (MB, VCB, TCB, ACB, CTG, BIDV, VPB,...)"
          },
          "accountNumber": {
            "type": "string",
            "example": "0783825888",
            "description": "Số tài khoản thụ hưởng dạng chuỗi (giữ nguyên số 0 đầu)"
          }
        }
      },
      "LookupSuccessResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "object",
            "properties": {
              "requestId": { "type": "string", "example": "REQ_20261017_9921FA80" },
              "bankCode": { "type": "string", "example": "MB" },
              "bankName": { "type": "string", "example": "MBBank (Ngân hàng Quân Đội)" },
              "accountNumber": { "type": "string", "example": "0783825888" },
              "accountName": { "type": "string", "example": "TRAN NHU KHANG" },
              "cached": { "type": "boolean", "example": true },
              "source": { "type": "string", "example": "L1_CACHE" },
              "verifiedAt": { "type": "string", "format": "date-time" },
              "feeChargedVnd": { "type": "number", "example": 0 },
              "chargeMethod": { "type": "string", "example": "SUBSCRIPTION_PASS" },
              "latencyMs": { "type": "number", "example": 1 },
              "signature": { "type": "string", "example": "ed25519:v1:e8f90c33a91b452d88fa7b89c02d..." },
              "message": { "type": "string", "example": "Xác thực tài khoản Napas 24/7 thành công" }
            }
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": false },
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string", "example": "NOT_FOUND" },
              "message": { "type": "string", "example": "Không tìm thấy thông tin tài khoản thụ hưởng" },
              "requestId": { "type": "string", "example": "REQ_20261017_9921FA81" },
              "feeChargedVnd": { "type": "number", "example": 125 }
            }
          }
        }
      },
      "MaintenanceResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": false },
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string", "example": "ENDPOINT_MAINTENANCE" },
              "message": { "type": "string", "example": "Cổng API Tra cứu tài khoản đang tạm dừng bảo trì định kỳ." },
              "autoReopenAt": { "type": "string", "example": "2026-10-17T18:00:00.000Z" }
            }
          }
        }
      },
      "WalletBalanceResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "data": {
            "type": "object",
            "properties": {
              "balanceVnd": { "type": "number", "example": 1500000 },
              "availableVnd": { "type": "number", "example": 1500000 },
              "reservedVnd": { "type": "number", "example": 0 },
              "subscriptionQuota": { "type": "number", "example": 49850 }
            }
          }
        }
      }
    }
  }
}
