{
  "openapi": "3.0.3",
  "info": {
    "title": "BankGateway API",
    "version": "2026-11-21",
    "description": "Tra cứu tên chủ tài khoản, giao dịch tài khoản đã liên kết và cổng thanh toán VietQR. Tài liệu: https://developer.bankgateway.vn/api-docs"
  },
  "servers": [
    {
      "url": "https://api.bankgateway.vn"
    }
  ],
  "tags": [
    {
      "name": "① Tra cứu tài khoản (API key)",
      "description": "Header X-API-Key. Lấy ở Dashboard › Khóa API."
    },
    {
      "name": "② Lịch sử giao dịch (token tài khoản)",
      "description": "Header Authorization: Bearer <token của tài khoản ngân hàng>. Không cần API key. Lấy ở Dashboard › Tài khoản ngân hàng."
    },
    {
      "name": "③ Cổng thanh toán (Merchant ID + chữ ký)",
      "description": "Ký HMAC-SHA256 bằng Secret key, gửi signature trong request. Lấy ở Dashboard › Cổng thanh toán › Cài đặt."
    },
    {
      "name": "Hệ thống",
      "description": "Công khai."
    }
  ],
  "paths": {
    "/api/v1/lookup": {
      "post": {
        "tags": [
          "① Tra cứu tài khoản (API key)"
        ],
        "summary": "Tra cứu tên chủ tài khoản",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LookupRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tìm thấy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LookupSuccess"
                }
              }
            }
          },
          "400": {
            "description": "Đầu vào sai",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Lỗi xác thực",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Không đủ tiền / lượt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Không có quyền / hết hạn mức key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Tài khoản không tồn tại (tính phí)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Xung đột Idempotency-Key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Tài khoản đóng / không nhận tiền",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Vượt giới hạn tốc độ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Lỗi ngân hàng",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Bảo trì",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "Hết thời gian chờ ngân hàng",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/lookup/batch": {
      "post": {
        "tags": [
          "① Tra cứu tài khoản (API key)"
        ],
        "summary": "Tạo batch tra cứu (tối đa 1.000)",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Đã nhận"
          },
          "400": {
            "description": "Đầu vào sai",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Không đủ tiền",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Vượt giới hạn tài khoản dùng thử",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/lookup/batch/{jobId}": {
      "get": {
        "tags": [
          "① Tra cứu tài khoản (API key)"
        ],
        "summary": "Trạng thái và kết quả batch",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "404": {
            "description": "Không tìm thấy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/lookup/batch/{jobId}/cancel": {
      "post": {
        "tags": [
          "① Tra cứu tài khoản (API key)"
        ],
        "summary": "Hủy batch",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Đã hủy"
          },
          "400": {
            "description": "Không thể hủy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/wallet/balance": {
      "get": {
        "tags": [
          "① Tra cứu tài khoản (API key)"
        ],
        "summary": "Số dư ví và lượt gói",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Wallet"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/wallet/statement": {
      "get": {
        "tags": [
          "① Tra cứu tài khoản (API key)"
        ],
        "summary": "Sao kê ví",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/v1/gateway/history": {
      "get": {
        "tags": [
          "② Lịch sử giao dịch (token tài khoản)"
        ],
        "summary": "Giao dịch & số dư tài khoản đã liên kết",
        "security": [
          {
            "AccountToken": []
          }
        ],
        "parameters": [
          {
            "name": "accountNumber",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 50
            }
          },
          {
            "name": "sync",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "true"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HistoryResponse"
                }
              }
            }
          },
          "400": {
            "description": "Thiếu tham số",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HistoryResponse"
                }
              }
            }
          },
          "401": {
            "description": "Sai số tài khoản hoặc token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HistoryResponse"
                }
              }
            }
          },
          "429": {
            "description": "Vượt giới hạn / bị khóa tạm thời",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HistoryResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/payment-gateway/checkout": {
      "post": {
        "tags": [
          "③ Cổng thanh toán (Merchant ID + chữ ký)"
        ],
        "summary": "Tạo đơn thanh toán VietQR",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Đã tạo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutSession"
                }
              }
            }
          },
          "200": {
            "description": "Trả lại đơn đã tạo (cùng orderId, cùng tham số)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutSession"
                }
              }
            }
          },
          "400": {
            "description": "Đầu vào sai",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutError"
                }
              }
            }
          },
          "401": {
            "description": "Sai chữ ký / merchant / timestamp",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutError"
                }
              }
            }
          },
          "409": {
            "description": "orderId đã tồn tại với tham số khác",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutError"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/v1/payment-gateway/checkout/{sessionId}": {
      "get": {
        "tags": [
          "③ Cổng thanh toán (Merchant ID + chữ ký)"
        ],
        "summary": "Trạng thái đơn theo sessionId (ký merchantId|sessionId)",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "signature",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutSession"
                }
              }
            }
          },
          "401": {
            "description": "Sai chữ ký"
          },
          "404": {
            "description": "Không tìm thấy"
          }
        },
        "security": []
      }
    },
    "/api/v1/payment-gateway/checkout/by-order/{orderId}": {
      "get": {
        "tags": [
          "③ Cổng thanh toán (Merchant ID + chữ ký)"
        ],
        "summary": "Trạng thái đơn theo orderId (ký merchantId|orderId|timestamp)",
        "parameters": [
          {
            "name": "orderId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "signature",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "timestamp",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutSession"
                }
              }
            }
          },
          "401": {
            "description": "Sai chữ ký"
          },
          "404": {
            "description": "Không tìm thấy"
          }
        },
        "security": []
      }
    },
    "/api/v1/system/status": {
      "get": {
        "tags": [
          "Hệ thống"
        ],
        "summary": "Trạng thái hệ thống",
        "security": [],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "AccountToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "Token của từng tài khoản ngân hàng đã liên kết"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "requestId": {
                "type": "string"
              },
              "category": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              },
              "action": {
                "type": "string"
              },
              "feeChargedVnd": {
                "type": "number"
              },
              "autoReopenAt": {
                "type": "string",
                "nullable": true
              }
            },
            "required": [
              "code"
            ]
          }
        },
        "required": [
          "success",
          "error"
        ]
      },
      "LookupRequest": {
        "type": "object",
        "properties": {
          "bankCode": {
            "type": "string",
            "example": "MB"
          },
          "accountNumber": {
            "type": "string",
            "example": "0783825888",
            "minLength": 4,
            "maxLength": 30
          }
        },
        "required": [
          "bankCode",
          "accountNumber"
        ]
      },
      "LookupSuccess": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "data": {
            "type": "object",
            "properties": {
              "requestId": {
                "type": "string"
              },
              "bankCode": {
                "type": "string"
              },
              "accountNumber": {
                "type": "string"
              },
              "accountName": {
                "type": "string"
              },
              "cached": {
                "type": "boolean"
              },
              "verifiedAt": {
                "type": "string",
                "format": "date-time"
              },
              "feeChargedVnd": {
                "type": "number"
              },
              "chargeMethod": {
                "type": "string",
                "enum": [
                  "PAY_AS_YOU_GO",
                  "MONTHLY_PASS_30_DAYS",
                  "LIFETIME_VAULT"
                ]
              },
              "quotaRemaining": {
                "type": "object",
                "properties": {
                  "subscriptionQuota": {
                    "type": "integer"
                  },
                  "vaultQuota": {
                    "type": "integer"
                  },
                  "walletBalanceVnd": {
                    "type": "number"
                  }
                }
              },
              "latencyMs": {
                "type": "number"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "BatchRequest": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1000,
            "items": {
              "type": "object",
              "properties": {
                "bankCode": {
                  "type": "string"
                },
                "accountNumber": {
                  "type": "string"
                },
                "clientRef": {
                  "type": "string",
                  "maxLength": 128
                }
              },
              "required": [
                "accountNumber"
              ]
            }
          },
          "webhookUrl": {
            "type": "string",
            "format": "uri"
          },
          "webhookSecret": {
            "type": "string"
          }
        },
        "required": [
          "items"
        ]
      },
      "Wallet": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "data": {
            "type": "object",
            "properties": {
              "tenantId": {
                "type": "string"
              },
              "balanceVnd": {
                "type": "number"
              },
              "reservedVnd": {
                "type": "number"
              },
              "availableVnd": {
                "type": "number"
              },
              "currency": {
                "type": "string"
              },
              "subscriptionQuota": {
                "type": "integer"
              },
              "subscriptionExpiresAt": {
                "type": "string",
                "nullable": true
              },
              "vaultQuota": {
                "type": "integer"
              },
              "depositCode": {
                "type": "string"
              },
              "totalDepositedVnd": {
                "type": "number"
              }
            }
          }
        }
      },
      "BankTransaction": {
        "type": "object",
        "properties": {
          "transactionID": {
            "type": "string"
          },
          "amount": {
            "type": "number"
          },
          "currency": {
            "type": "string"
          },
          "balanceAfter": {
            "type": "number"
          },
          "description": {
            "type": "string"
          },
          "transactionDate": {
            "type": "string"
          },
          "bookingDateTime": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "IN",
              "OUT"
            ]
          },
          "creditDebitIndicator": {
            "type": "string",
            "enum": [
              "CRDT",
              "DBIT"
            ]
          },
          "bankCode": {
            "type": "string"
          },
          "counterPartyAccount": {
            "type": "string",
            "nullable": true
          },
          "counterPartyName": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "HistoryResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "success",
              "error"
            ]
          },
          "requestId": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "transactions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BankTransaction"
            }
          }
        }
      },
      "CheckoutRequest": {
        "type": "object",
        "properties": {
          "merchantId": {
            "type": "string"
          },
          "orderId": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_.-]{1,64}$"
          },
          "amount": {
            "type": "integer",
            "minimum": 2000,
            "maximum": 500000000
          },
          "timestamp": {
            "type": "integer",
            "description": "Unix ms, ±5 phút"
          },
          "signature": {
            "type": "string",
            "description": "HMAC-SHA256 hex. v1: merchantId|orderId|amount|timestamp"
          },
          "description": {
            "type": "string",
            "maxLength": 120
          },
          "environment": {
            "type": "string",
            "enum": [
              "LIVE",
              "SANDBOX"
            ]
          },
          "signatureVersion": {
            "type": "string",
            "enum": [
              "1",
              "2"
            ]
          },
          "returnUrl": {
            "type": "string"
          },
          "cancelUrl": {
            "type": "string"
          },
          "webhookUrl": {
            "type": "string"
          },
          "nodeId": {
            "type": "string"
          }
        },
        "required": [
          "merchantId",
          "orderId",
          "amount",
          "timestamp",
          "signature"
        ]
      },
      "CheckoutSession": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "reused": {
            "type": "boolean"
          },
          "data": {
            "type": "object",
            "properties": {
              "sessionId": {
                "type": "string"
              },
              "environment": {
                "type": "string"
              },
              "merchantId": {
                "type": "string"
              },
              "orderId": {
                "type": "string"
              },
              "paymentCode": {
                "type": "string"
              },
              "amount": {
                "type": "number"
              },
              "paidAmount": {
                "type": "number",
                "nullable": true
              },
              "status": {
                "type": "string",
                "enum": [
                  "PENDING",
                  "PAID",
                  "REVIEW_REQUIRED",
                  "REJECTED",
                  "EXPIRED",
                  "CANCELLED"
                ]
              },
              "checkoutUrl": {
                "type": "string"
              },
              "qrString": {
                "type": "string"
              },
              "bankCode": {
                "type": "string"
              },
              "bankName": {
                "type": "string"
              },
              "accountNumber": {
                "type": "string"
              },
              "accountName": {
                "type": "string"
              },
              "mismatchReason": {
                "type": "string",
                "nullable": true
              },
              "paidAt": {
                "type": "string",
                "nullable": true
              },
              "expiresAt": {
                "type": "string"
              }
            }
          }
        }
      },
      "CheckoutError": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}
