{
  "info": {
    "name": "Pay2S · Deeplink ngân hàng",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "Dành cho chủ tài khoản có gói Basic trở lên còn hiệu lực. Tạo một môi trường Postman cá nhân, chọn môi trường đó rồi đặt giá trị cục bộ cho pay2sAccessKey và pay2sSecretKey. Chạy lần lượt ba request. Nếu đã có token OneQR còn hạn, điền pay2sToken và bắt đầu từ request 2. Giữ khóa và token trong môi trường riêng."
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{pay2sToken}}",
        "type": "string"
      }
    ]
  },
  "item": [
    {
      "name": "1. Lấy token OneQR",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "https://api.pay2s.vn/api/auth/token",
          "protocol": "https",
          "host": [
            "api",
            "pay2s",
            "vn"
          ],
          "path": [
            "api",
            "auth",
            "token"
          ]
        },
        "description": "Điền pay2sAccessKey và pay2sSecretKey vào môi trường Postman đang chọn. Khi lấy token thành công, collection lưu token vào biến pay2sToken của môi trường này.",
        "auth": {
          "type": "basic",
          "basic": [
            {
              "key": "username",
              "value": "{{pay2sAccessKey}}",
              "type": "string"
            },
            {
              "key": "password",
              "value": "{{pay2sSecretKey}}",
              "type": "string"
            }
          ]
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.response.code === 200) {",
              "  const token = pm.response.json().data?.access_token;",
              "  pm.test('Nhận được Bearer token', () => pm.expect(token).to.be.a('string').and.not.empty);",
              "  if (typeof token === 'string' && token.length > 0) pm.environment.set('pay2sToken', token);",
              "}"
            ]
          }
        }
      ]
    },
    {
      "name": "2. Danh sách app ngân hàng",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "https://api.pay2s.vn/api/deeplink/v1/banks",
          "protocol": "https",
          "host": [
            "api",
            "pay2s",
            "vn"
          ],
          "path": [
            "api",
            "deeplink",
            "v1",
            "banks"
          ]
        },
        "description": "Chọn bankNo từ data.banks trong kết quả trả về."
      }
    },
    {
      "name": "3. Tạo deeplink",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "https://api.pay2s.vn/api/deeplink/v1/create",
          "protocol": "https",
          "host": [
            "api",
            "pay2s",
            "vn"
          ],
          "path": [
            "api",
            "deeplink",
            "v1",
            "create"
          ]
        },
        "description": "Ví dụ mở ACB ONE để chuyển 60.000 đồng đến một tài khoản Vietcombank. Điền đúng recipientBankNo và accountNumber của tài khoản đã liên kết. Với một yêu cầu mới, đặt requestId mới. Khi thử lại cùng yêu cầu, giữ nguyên requestId và dữ liệu. Mở nguyên data.url trên thiết bị của người mua.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"requestId\": \"{{requestId}}\",\n  \"bankNo\": \"{{bankNo}}\",\n  \"recipientBankNo\": \"{{recipientBankNo}}\",\n  \"accountNumber\": \"{{accountNumber}}\",\n  \"amount\": 60000,\n  \"note\": \"Thanh toan DH00079\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    }
  ],
  "variable": [
    {
      "key": "requestId",
      "value": "DH00079-ACB-01",
      "type": "string",
      "description": "Mã yêu cầu của shop"
    },
    {
      "key": "bankNo",
      "value": "970416",
      "type": "string",
      "description": "BIN của ứng dụng người mua muốn mở"
    },
    {
      "key": "recipientBankNo",
      "value": "970436",
      "type": "string",
      "description": "BIN ngân hàng nhận tiền của shop"
    },
    {
      "key": "accountNumber",
      "value": "",
      "type": "string",
      "description": "Số tài khoản hoặc VA đang liên kết với shop. Giữ nguyên các số 0 ở đầu."
    }
  ]
}
