{
  "info": {
    "name": "BankGateway API (2026-11-21)",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "Điền biến apiKey, accountToken, merchantId, secretKey. Tài liệu: https://developer.bankgateway.vn/api-docs"
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://api.bankgateway.vn"
    },
    {
      "key": "apiKey",
      "value": "bg_live_..."
    },
    {
      "key": "accountToken",
      "value": ""
    },
    {
      "key": "accountNumber",
      "value": ""
    },
    {
      "key": "merchantId",
      "value": "BGW_..."
    },
    {
      "key": "secretKey",
      "value": "sk_test_..."
    }
  ],
  "item": [
    {
      "name": "① Tra cứu tài khoản (API key)",
      "item": [
        {
          "name": "Tra cứu tên chủ tài khoản",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{$guid}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/lookup",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "lookup"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"bankCode\": \"MB\",\n  \"accountNumber\": \"0783825888\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Tạo batch",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{$guid}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/lookup/batch",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "lookup",
                "batch"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"items\": [\n    {\n      \"bankCode\": \"MB\",\n      \"accountNumber\": \"0783825888\",\n      \"clientRef\": \"NV-001\"\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Trạng thái batch",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/lookup/batch/:jobId",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "lookup",
                "batch",
                ":jobId"
              ]
            }
          }
        },
        {
          "name": "Số dư ví",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/wallet/balance",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "wallet",
                "balance"
              ]
            }
          }
        },
        {
          "name": "Sao kê ví",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/wallet/statement?limit=50",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "wallet",
                "statement"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "50"
                }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "② Lịch sử giao dịch (token tài khoản)",
      "item": [
        {
          "name": "Giao dịch & số dư tài khoản",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{accountToken}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/gateway/history?accountNumber={{accountNumber}}&limit=50",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "gateway",
                "history"
              ],
              "query": [
                {
                  "key": "accountNumber",
                  "value": "{{accountNumber}}"
                },
                {
                  "key": "limit",
                  "value": "50"
                }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "③ Cổng thanh toán (Merchant ID + chữ ký)",
      "item": [
        {
          "name": "Tạo đơn thanh toán (SANDBOX)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/payment-gateway/checkout",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "payment-gateway",
                "checkout"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"merchantId\": \"{{merchantId}}\",\n  \"orderId\": \"{{orderId}}\",\n  \"amount\": 10000,\n  \"timestamp\": {{timestamp}},\n  \"environment\": \"SANDBOX\",\n  \"signature\": \"{{signature}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const ts = Date.now();",
                  "const orderId = 'TEST_' + ts;",
                  "pm.variables.set('timestamp', ts);",
                  "pm.variables.set('orderId', orderId);",
                  "const raw = `${pm.variables.get('merchantId')}|${orderId}|10000|${ts}`;",
                  "pm.variables.set('signature', CryptoJS.HmacSHA256(raw, pm.variables.get('secretKey')).toString());"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "Hệ thống",
      "item": [
        {
          "name": "Trạng thái hệ thống",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/system/status",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "system",
                "status"
              ]
            }
          }
        }
      ]
    }
  ]
}
