{
  "openapi": "3.1.0",
  "info": {
    "title": "Finex Partner Open API — Mở thẻ tín dụng VPBank",
    "version": "1.0.0",
    "description": "Cho phép đối tác mở thẻ tín dụng VPBank cho khách hàng ngay trên app/web của mình. Điều hướng hoàn toàn theo `lead.next_step`. Mọi request phải ký HMAC-SHA256 (xem /developers/reference/authentication).",
    "contact": {
      "name": "Finex",
      "email": "hi@finex.vn",
      "url": "https://www.finex.vn/developers"
    }
  },
  "servers": [
    {
      "url": "https://api.finex.studio/v1/partner",
      "description": "Development / sandbox (API key fx_test_…)"
    },
    {
      "url": "https://prod.finex.vn/v1/partner",
      "description": "Production (API key fx_live_…, bắt buộc IP whitelist)"
    }
  ],
  "security": [
    {
      "ApiKey": [],
      "Timestamp": [],
      "Signature": []
    }
  ],
  "tags": [
    {
      "name": "Danh mục",
      "description": "Dữ liệu tham chiếu cho form."
    },
    {
      "name": "Hồ sơ",
      "description": "Kiểm tra, tạo, nộp và đọc hồ sơ."
    },
    {
      "name": "eKYC",
      "description": "Ảnh CCCD, QR và khuôn mặt."
    },
    {
      "name": "Hoàn tất hồ sơ",
      "description": "Thông tin bổ sung, hợp đồng điện tử, Video KYC."
    },
    {
      "name": "Công cụ",
      "description": "Thử callback và gỡ lỗi chữ ký."
    }
  ],
  "paths": {
    "/reference-data/{list}": {
      "get": {
        "operationId": "listReferenceData",
        "summary": "Danh mục",
        "description": "Trả các danh mục cho form. Mã trả về là **mã gốc của VPBank** (không phải mã hành chính), bạn gửi lại nguyên văn trong `POST /v1/partner/leads`.\n\n- Địa chỉ chỉ có 2 cấp: tỉnh/thành và quận/huyện, không có phường/xã.\n- `districts` lọc theo `parent_code` là mã tỉnh; `job-positions` lọc theo `parent_code` là `employer_status`.\n- `name` có thể là `null` nếu VPBank chưa có tên. Kết quả xếp theo tên.\n- Nên lưu lại phía bạn, cập nhật mỗi ngày một lần.",
        "tags": [
          "Danh mục"
        ],
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "provinces",
                "districts",
                "companies",
                "employment-statuses",
                "job-positions",
                "marital-statuses",
                "id-issue-places",
                "relationships",
                "card-types"
              ]
            },
            "description": "Tên danh mục."
          },
          {
            "name": "parent_code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Lọc theo mã cha: mã tỉnh với `districts`, `employer_status` với `job-positions`."
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "Tìm theo tên (chứa chuỗi, không phân biệt hoa thường). Dùng cho ô tìm công ty."
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            },
            "description": "Trang, ≥ 1."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            },
            "description": "Số bản ghi mỗi trang, 1–100."
          }
        ],
        "responses": {
          "200": {
            "description": "Danh sách mục",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/LovItem"
                          }
                        },
                        "page": {
                          "type": "integer"
                        },
                        "limit": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "items": [
                      {
                        "code": "34B108C4F55200D6E0530A2510AB2319",
                        "name": "Khác",
                        "parent_code": "b37b139eba3549c3a7550d4a1a1a414f"
                      },
                      {
                        "code": "34B108C4F54300D6E0530A2510AB2319",
                        "name": "Quận 1",
                        "parent_code": "b37b139eba3549c3a7550d4a1a1a414f"
                      }
                    ],
                    "page": 1,
                    "limit": 2,
                    "total": 22
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": null,
        "x-valid-steps": null,
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR",
            "description": "page, limit hoặc q sai (trả hết lỗi một lần)"
          },
          {
            "status": 404,
            "code": "NOT_FOUND",
            "description": "list không tồn tại; error.details liệt kê các giá trị hợp lệ"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ]
      }
    },
    "/leads/check": {
      "post": {
        "operationId": "checkLead",
        "summary": "Kiểm tra khách",
        "description": "Gọi ngay khi khách nhập số điện thoại và email. Bạn tự xác thực số điện thoại của khách trước (ví dụ bằng OTP của bạn).\n\nLuôn trả `200`. Nếu `eligible` là `false`, `reason` cho biết lý do:\n\n- `LEAD_IN_PROGRESS`: khách đang có hồ sơ khác, kể cả ở kênh khác của Finex.\n- `CUSTOMER_ALREADY_HAS_CARD`: khách đã được duyệt hoặc đã có thẻ.\n- `VPBANK_REJECTED`: VPBank chưa nhận đăng ký với số điện thoại hoặc email này.",
        "tags": [
          "Hồ sơ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "phone_number",
                  "email"
                ],
                "properties": {
                  "phone_number": {
                    "type": "string",
                    "pattern": "^0(3|5|7|8|9)\\d{8}$"
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 100
                  }
                }
              },
              "example": {
                "phone_number": "0900000001",
                "email": "an@example.com"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Kết quả kiểm tra",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "eligible": {
                          "type": "boolean"
                        },
                        "reason": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            null,
                            "LEAD_IN_PROGRESS",
                            "CUSTOMER_ALREADY_HAS_CARD",
                            "VPBANK_REJECTED"
                          ]
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "eligible": true,
                    "reason": null
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": null,
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR",
            "description": "SĐT/email sai định dạng"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ]
      }
    },
    "/leads": {
      "post": {
        "operationId": "createLead",
        "summary": "Tạo hồ sơ",
        "description": "Một lần gọi vừa tạo hồ sơ vừa nộp sang VPBank.\n\n- `201`: VPBank đã nhận (`SUBMITTED`, `next_step = null`). Chờ callback `lead.ekyc_required`.\n- `202`: VPBank chưa phản hồi (`PENDING`, `next_step = submit`). Sau 1–5 phút gọi `POST /v1/partner/leads/{id}/submit` với key mới.\n- `422 VPBANK_REJECTED`: VPBank từ chối ngay, `error.lead` đã bị huỷ. Trường hợp này **không** có callback `lead.cancelled`.\n\nMọi lỗi dữ liệu trả về cùng lúc trong `error.details[]`. Nhớ lưu `lead_id` cùng mã khách của bạn.",
        "tags": [
          "Hồ sơ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateLeadRequest"
              },
              "example": {
                "ip_address": "113.161.10.20",
                "device": {
                  "user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X)",
                  "type_of_device": "mobile",
                  "operating_system": "iOS 17.5",
                  "browser_name": "Safari",
                  "country": "VN",
                  "city": "Ho Chi Minh"
                },
                "full_name": "Nguyễn Văn An",
                "phone_number": "0900000001",
                "email": "an@example.com",
                "dob": "15/08/1996",
                "gender": "M",
                "marital_status": "SINGLE",
                "document_number": "079096001234",
                "date_of_issue": "10/05/2021",
                "date_of_expiry": "15/08/2036",
                "place_of_issue": "Cuc canh sat QLHC ve TTXH",
                "permanent_province": "b37b139eba3549c3a7550d4a1a1a414f",
                "permanent_district": "34B108C4F54300D6E0530A2510AB2319",
                "permanent_address": "12 Nguyễn Huệ",
                "current_province": "b37b139eba3549c3a7550d4a1a1a414f",
                "current_district": "D2255A062C2F0140E0530A2518AB85EC",
                "current_address": "45 Lê Lợi",
                "employer_status": "EMPL1",
                "job_position": "POSH29",
                "income_amount": 25000000,
                "employer_name": "ADIDAS VIETNAM",
                "employer_province": "b37b139eba3549c3a7550d4a1a1a414f",
                "employer_district": "34B108C4F54300D6E0530A2510AB2319",
                "employer_address": "1 Lê Duẩn",
                "consent0": "DONG_Y",
                "consent1": "DONG_Y",
                "consent2": "DONG_Y",
                "consent3": "KHONG_DONG_Y",
                "consent_timestamp": "2026-11-25T21:00:00+07:00"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "VPBank đã nhận hồ sơ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": null,
                      "kyc_segment": null,
                      "offer": null,
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "202": {
            "description": "VPBank tạm thời chưa nhận — nộp lại sau",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "PENDING",
                      "next_step": "submit",
                      "kyc_segment": null,
                      "offer": null,
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "LEAD_IN_PROGRESS, CUSTOMER_ALREADY_HAS_CARD",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "description": "PAYLOAD_TOO_LARGE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "VPBANK_REJECTED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": null,
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR",
            "description": "Dữ liệu sai — hiển thị details[] trên form"
          },
          {
            "status": 409,
            "code": "LEAD_IN_PROGRESS",
            "description": "Khách đang có hồ sơ xử lý"
          },
          {
            "status": 409,
            "code": "CUSTOMER_ALREADY_HAS_CARD",
            "description": "Khách đã được duyệt / có thẻ"
          },
          {
            "status": 413,
            "code": "PAYLOAD_TOO_LARGE",
            "description": "Body > 10 MB"
          },
          {
            "status": 422,
            "code": "VPBANK_REJECTED",
            "description": "VPBank từ chối ngay; error.lead đã CANCELLED kèm cancel"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ],
        "x-client-timeout-seconds": 90
      }
    },
    "/leads/{id}": {
      "get": {
        "operationId": "getLead",
        "summary": "Xem hồ sơ",
        "description": "Trả `data.lead`. Finex lấy dữ liệu mới nhất từ VPBank trước khi trả, nên dùng được khi:\n\n- khách mở lại app và cần quay về đúng màn hình;\n- bạn nghi đã lỡ một callback;\n- `contract_url` đã hết hạn.\n\nĐừng gọi liên tục. Nếu phải hỏi trạng thái, cách nhau ít nhất 30 giây cho mỗi hồ sơ.",
        "tags": [
          "Hồ sơ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "responses": {
          "200": {
            "description": "Hồ sơ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": "ocr",
                      "kyc_segment": "EKYC",
                      "offer": {
                        "limit": 50000000,
                        "cards": [
                          "MTSC",
                          "MLT"
                        ]
                      },
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:read",
        "x-valid-steps": [
          "(mọi lúc)"
        ],
        "x-errors": [
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ]
      }
    },
    "/leads/{id}/submit": {
      "post": {
        "operationId": "submitLead",
        "summary": "Nộp lại hồ sơ",
        "description": "Chỉ dùng khi `next_step = submit`, tức là `POST /v1/partner/leads` đã trả `202`. Không có body, nhưng vẫn cần `Idempotency-Key`.\n\n- `200`: đã nộp, `next_step = null`.\n- `202`: VPBank vẫn chưa nhận, thử lại sau.",
        "tags": [
          "Hồ sơ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Đã nộp",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": null,
                      "kyc_segment": null,
                      "offer": null,
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "202": {
            "description": "VPBank vẫn chưa nhận",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "PENDING",
                      "next_step": "submit",
                      "kyc_segment": null,
                      "offer": null,
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "VPBANK_REJECTED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": [
          "submit"
        ],
        "x-errors": [
          {
            "status": 422,
            "code": "VPBANK_REJECTED"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 409,
            "code": "INVALID_STATE"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ],
        "x-client-timeout-seconds": 90
      }
    },
    "/leads/{id}/ekyc-config": {
      "get": {
        "operationId": "getEkycConfig",
        "summary": "Cấu hình SDK eKYC",
        "description": "Trả `client_settings`, bạn truyền nguyên vào SDK chụp ảnh của VPBank (số lần thử, số khung hình…). Trên sandbox trả `{ \"sandbox\": true, … }`.",
        "tags": [
          "eKYC"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "responses": {
          "200": {
            "description": "Cấu hình",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "client_settings": {
                          "type": "object",
                          "additionalProperties": true
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "client_settings": {
                      "sandbox": true
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "KYC_SEGMENT_PENDING, INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "UPSTREAM_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:read",
        "x-valid-steps": [
          "ocr",
          "qr",
          "liveness"
        ],
        "x-errors": [
          {
            "status": 409,
            "code": "KYC_SEGMENT_PENDING",
            "description": "Chưa có kết quả R1"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 409,
            "code": "INVALID_STATE"
          },
          {
            "status": 502,
            "code": "UPSTREAM_ERROR"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ]
      }
    },
    "/leads/{id}/ocr": {
      "post": {
        "operationId": "submitOcr",
        "summary": "Ảnh CCCD",
        "description": "Gửi ảnh hai mặt CCCD, có thể kèm ảnh QR. Thành công thì `next_step` là:\n\n- `liveness` (EKYC);\n- `additional_info` (VKYC);\n- `qr` — VPBank cần ảnh QR riêng (`message = \"Xử lý thành công.\"`).\n\nKhi ảnh không đạt, `error.action` cho biết nên làm gì (`retry`, `try_later`, `cancelled`) và `error.message` là câu hiện cho khách. Khách chụp lại thì dùng **Idempotency-Key mới**.",
        "tags": [
          "eKYC"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/SandboxScenario"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "image_front",
                  "image_back"
                ],
                "properties": {
                  "image_front": {
                    "type": "string",
                    "contentEncoding": "base64",
                    "description": "Mặt trước CCCD"
                  },
                  "image_back": {
                    "type": "string",
                    "contentEncoding": "base64",
                    "description": "Mặt sau CCCD"
                  },
                  "image_qr": {
                    "type": "string",
                    "contentEncoding": "base64",
                    "description": "Ảnh vùng QR (tuỳ chọn)"
                  },
                  "device_type": {
                    "type": "string",
                    "enum": [
                      "mobile",
                      "desktop"
                    ],
                    "default": "mobile"
                  }
                }
              },
              "example": {
                "image_front": "/9j/4AAQSkZJRgABAQ…",
                "image_back": "/9j/4AAQSkZJRgABAQ…",
                "device_type": "mobile"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Đã nhận ảnh CCCD",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Câu nên hiển thị cho khách"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": "liveness",
                      "kyc_segment": "EKYC",
                      "offer": {
                        "limit": 50000000,
                        "cards": [
                          "MTSC",
                          "MLT"
                        ]
                      },
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": "Thêm CCCD/CMND thành công."
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "KYC_SEGMENT_PENDING, INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "description": "PAYLOAD_TOO_LARGE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "EKYC_FAILED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "UPSTREAM_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": [
          "ocr"
        ],
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR",
            "description": "Base64 hỏng / không phải JPEG-PNG / device_type sai"
          },
          {
            "status": 409,
            "code": "KYC_SEGMENT_PENDING"
          },
          {
            "status": 413,
            "code": "PAYLOAD_TOO_LARGE"
          },
          {
            "status": 422,
            "code": "EKYC_FAILED",
            "description": "Theo error.action"
          },
          {
            "status": 502,
            "code": "UPSTREAM_ERROR",
            "description": "action: try_later"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 409,
            "code": "INVALID_STATE"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ],
        "x-client-timeout-seconds": 90
      }
    },
    "/leads/{id}/qr": {
      "post": {
        "operationId": "submitQr",
        "summary": "Ảnh QR trên CCCD",
        "description": "Chỉ dùng khi `next_step = qr`. Thành công thì `next_step` là `liveness` (EKYC) hoặc `additional_info` (VKYC). Lỗi xử lý giống API OCR.",
        "tags": [
          "eKYC"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/SandboxScenario"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "image_qr"
                ],
                "properties": {
                  "image_qr": {
                    "type": "string",
                    "contentEncoding": "base64",
                    "description": "Base64 của JPEG/PNG (chấp nhận tiền tố data:image/jpeg;base64,)"
                  }
                }
              },
              "example": {
                "image_qr": "/9j/4AAQSkZJRgABAQ…"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Đã nhận ảnh QR",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": "liveness",
                      "kyc_segment": "EKYC",
                      "offer": {
                        "limit": 50000000,
                        "cards": [
                          "MTSC",
                          "MLT"
                        ]
                      },
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": "Thêm CCCD/CMND thành công."
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "description": "PAYLOAD_TOO_LARGE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "EKYC_FAILED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "UPSTREAM_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": [
          "qr"
        ],
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR"
          },
          {
            "status": 413,
            "code": "PAYLOAD_TOO_LARGE"
          },
          {
            "status": 422,
            "code": "EKYC_FAILED"
          },
          {
            "status": 502,
            "code": "UPSTREAM_ERROR"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 409,
            "code": "INVALID_STATE"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ],
        "x-client-timeout-seconds": 90
      }
    },
    "/leads/{id}/liveness": {
      "post": {
        "operationId": "submitLiveness",
        "summary": "Ảnh khuôn mặt",
        "description": "Chỉ có ở nhánh EKYC. Gửi kết quả của SDK chụp khuôn mặt. Thành công thì `next_step = additional_info` và `message` là \"Thêm dữ liệu khuôn mặt thành công.\"\n\nBody tối đa 10 MB: nén ảnh JPEG ở chất lượng 70–80%, cạnh dài không quá 1280 px.",
        "tags": [
          "eKYC"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/SandboxScenario"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "images_liveness",
                  "frames"
                ],
                "properties": {
                  "images_liveness": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 30,
                    "items": {
                      "type": "string",
                      "contentEncoding": "base64",
                      "description": "Base64 của JPEG/PNG (chấp nhận tiền tố data:image/jpeg;base64,)"
                    }
                  },
                  "frames": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 60,
                    "items": {
                      "type": "string",
                      "contentEncoding": "base64",
                      "description": "Base64 của JPEG/PNG (chấp nhận tiền tố data:image/jpeg;base64,)"
                    }
                  },
                  "video": {
                    "type": "string",
                    "contentEncoding": "base64",
                    "description": "Base64 MP4 (tuỳ chọn)"
                  }
                }
              },
              "example": {
                "images_liveness": [
                  "/9j/4AAQ…"
                ],
                "frames": [
                  "/9j/4AAQ…",
                  "/9j/4AAQ…"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Đã nhận dữ liệu khuôn mặt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": "additional_info",
                      "kyc_segment": "EKYC",
                      "offer": {
                        "limit": 50000000,
                        "cards": [
                          "MTSC",
                          "MLT"
                        ]
                      },
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": "Thêm dữ liệu khuôn mặt thành công."
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "description": "PAYLOAD_TOO_LARGE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "EKYC_FAILED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "UPSTREAM_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": [
          "liveness"
        ],
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR"
          },
          {
            "status": 413,
            "code": "PAYLOAD_TOO_LARGE"
          },
          {
            "status": 422,
            "code": "EKYC_FAILED"
          },
          {
            "status": 502,
            "code": "UPSTREAM_ERROR"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 409,
            "code": "INVALID_STATE"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ],
        "x-client-timeout-seconds": 90
      }
    },
    "/leads/{id}/additional-info": {
      "put": {
        "operationId": "updateAdditionalInfo",
        "summary": "Chọn thẻ và thông tin thêm",
        "description": "Khách chọn thẻ trong `offer.cards`, địa chỉ nhận thẻ, người tham chiếu, câu hỏi bảo mật và FATCA. Kết quả:\n\n- VKYC → `next_step = vkyc`;\n- EKYC, hợp đồng đã sẵn → `econtract` (+ callback `lead.contract_ready`);\n- EKYC, hợp đồng chưa sẵn → `awaiting_contract`.\n\n Gặp `502 UPSTREAM_ERROR` thì gửi lại sau ít phút, cùng key hay key mới đều được.",
        "tags": [
          "Hoàn tất hồ sơ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AdditionalInfoRequest"
              },
              "example": {
                "card_type": "MTSC",
                "card_delivery_address": "CUADDR",
                "reference1_fullname": "Tran Thi Binh",
                "reference1_relationship": "SB",
                "reference1_mobile_phone_number": "0912345678",
                "security_question": "Trường tiểu học của bạn là gì?",
                "security_answer": "Le Loi",
                "fatca": "N",
                "tin_number": null
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Đã lưu",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": "econtract",
                      "kyc_segment": "EKYC",
                      "offer": {
                        "limit": 50000000,
                        "cards": [
                          "MTSC",
                          "MLT"
                        ]
                      },
                      "contract_url": "https://…/partner_contract/6b070048cee4381886a66adb.pdf?expires=1764039600&signature=9f2c…",
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "UPSTREAM_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": [
          "additional_info"
        ],
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR"
          },
          {
            "status": 502,
            "code": "UPSTREAM_ERROR"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 409,
            "code": "INVALID_STATE"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ],
        "x-client-timeout-seconds": 90
      }
    },
    "/leads/{id}/econtract/otp": {
      "post": {
        "operationId": "sendEcontractOtp",
        "summary": "Gửi OTP ký hợp đồng",
        "description": "Không có body. VPBank nhắn OTP tới số điện thoại của khách. Gọi lại là gửi mã mới, đồng thời số lần nhập sai được tính lại từ đầu.",
        "tags": [
          "Hoàn tất hồ sơ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Đã gửi OTP",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": "econtract",
                      "kyc_segment": "EKYC",
                      "offer": {
                        "limit": 50000000,
                        "cards": [
                          "MTSC",
                          "MLT"
                        ]
                      },
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "UPSTREAM_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": [
          "econtract"
        ],
        "x-errors": [
          {
            "status": 502,
            "code": "UPSTREAM_ERROR"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 409,
            "code": "INVALID_STATE"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ],
        "x-client-timeout-seconds": 90
      }
    },
    "/leads/{id}/econtract/confirm": {
      "post": {
        "operationId": "confirmEcontract",
        "summary": "Ký hợp đồng bằng OTP",
        "description": "OTP gồm đúng 6 chữ số. Thành công thì `next_step = awaiting_result`.\n\n- `OTP_INVALID`: cho khách nhập lại, dùng key mới.\n- `OTP_EXPIRED` (hết hạn, hoặc chưa gọi `/econtract/otp`) và `OTP_LIMIT_EXCEEDED` (sai từ 5 lần): gọi `/econtract/otp` để gửi mã mới.",
        "tags": [
          "Hoàn tất hồ sơ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "otp"
                ],
                "properties": {
                  "otp": {
                    "type": "string",
                    "pattern": "^\\d{6}$"
                  }
                }
              },
              "example": {
                "otp": "000000"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Đã ký",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "lead"
                      ],
                      "properties": {
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": "awaiting_result",
                      "kyc_segment": "EKYC",
                      "offer": {
                        "limit": 50000000,
                        "cards": [
                          "MTSC",
                          "MLT"
                        ]
                      },
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "OTP_INVALID, OTP_EXPIRED, OTP_LIMIT_EXCEEDED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "UPSTREAM_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": [
          "econtract"
        ],
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR",
            "description": "OTP không phải 6 số"
          },
          {
            "status": 422,
            "code": "OTP_INVALID"
          },
          {
            "status": 422,
            "code": "OTP_EXPIRED"
          },
          {
            "status": 422,
            "code": "OTP_LIMIT_EXCEEDED"
          },
          {
            "status": 502,
            "code": "UPSTREAM_ERROR"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 409,
            "code": "INVALID_STATE"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ],
        "x-client-timeout-seconds": 90
      }
    },
    "/leads/{id}/vkyc-link": {
      "post": {
        "operationId": "createVkycLink",
        "summary": "Lấy link Video KYC",
        "description": "Chỉ có ở nhánh VKYC. Gọi được khi `next_step` là `vkyc`, hoặc `awaiting_result` để lấy lại link.\n\n- `redirect_url` phải trùng khớp từng ký tự với một URL đã đăng ký với Finex.\n- Mở `vkyc_url` trong trình duyệt hoặc WebView có quyền camera và micro.\n- Gọi xong, `next_step` chuyển sang `awaiting_result`. Sau cuộc gọi, khách được đưa về `redirect_url?lead_id=<lead_id>` (dùng `&` nếu URL đã có query).\n\nKhách quay về **không** có nghĩa là đã đạt. Kết quả chỉ đến qua callback hoặc `GET /v1/partner/leads/{id}`.",
        "tags": [
          "Hoàn tất hồ sơ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "redirect_url"
                ],
                "properties": {
                  "redirect_url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              },
              "example": {
                "redirect_url": "https://your-app.com/card/done"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Link Video KYC",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "vkyc_url": {
                          "type": "string",
                          "format": "uri"
                        },
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "vkyc_url": "https://…",
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "SUBMITTED",
                      "next_step": "awaiting_result",
                      "kyc_segment": "VKYC",
                      "offer": {
                        "limit": 50000000,
                        "cards": [
                          "MTSC",
                          "MLT"
                        ]
                      },
                      "contract_url": null,
                      "approval": null,
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "UPSTREAM_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": [
          "vkyc",
          "awaiting_result"
        ],
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR",
            "description": "redirect_url thiếu/chưa đăng ký"
          },
          {
            "status": 409,
            "code": "INVALID_STATE",
            "description": "Không phải VKYC hoặc sai bước"
          },
          {
            "status": 502,
            "code": "UPSTREAM_ERROR"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ],
        "x-client-timeout-seconds": 90
      }
    },
    "/callbacks/test": {
      "post": {
        "operationId": "testCallback",
        "summary": "Gửi thử callback",
        "description": "Finex gửi **một** callback mẫu đã ký (`lead_id = \"lead_test\"`) tới `callback_url` của bạn, không gửi lại. `http_status` là mã server bạn trả về, `null` nếu không kết nối được. Chưa đăng ký `callback_url` thì nhận `400 INVALID_REQUEST`.",
        "tags": [
          "Công cụ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "event_type": {
                    "type": "string",
                    "enum": [
                      "lead.ekyc_required",
                      "lead.contract_ready",
                      "lead.approved",
                      "lead.issued",
                      "lead.cancelled"
                    ],
                    "default": "lead.issued"
                  }
                }
              },
              "example": {
                "event_type": "lead.issued"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Kết quả gửi thử",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "event_id": {
                          "type": "string"
                        },
                        "http_status": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "event_id": "evt_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                    "http_status": 200
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": null,
        "x-valid-steps": null,
        "x-errors": [
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ]
      }
    },
    "/debug/signature": {
      "post": {
        "operationId": "debugSignature",
        "summary": "Kiểm tra chữ ký (sandbox)",
        "description": "**Chỉ có trên sandbox** (production trả `404 NOT_FOUND`). Không cần `x-signature`, vẫn cần `x-api-key`, `x-timestamp` và `Idempotency-Key`. Finex trả về chuỗi cần ký và chữ ký đúng để bạn so với kết quả của mình.\n\nKèm theo là `sandbox_mode` của ứng dụng: `simulated` (Finex đóng vai VPBank, dùng được số điện thoại thử và header `x-sandbox-scenario`) hoặc `vpbank_uat` (gọi hệ thống UAT thật của VPBank).",
        "tags": [
          "Công cụ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "method",
                  "path",
                  "timestamp"
                ],
                "properties": {
                  "method": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Path cần ký, kèm query, ví dụ /v1/partner/reference-data/provinces (dạng rút gọn /v1/... cũng được)"
                  },
                  "timestamp": {
                    "type": "string"
                  },
                  "body": {
                    "type": "string",
                    "description": "Body đúng như sẽ gửi, rỗng với GET"
                  }
                }
              },
              "example": {
                "method": "GET",
                "path": "/v1/partner/reference-data/provinces",
                "timestamp": "1764036000",
                "body": ""
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chuỗi cần ký và chữ ký",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "string_to_sign",
                        "signature",
                        "sandbox_mode"
                      ],
                      "properties": {
                        "string_to_sign": {
                          "type": "string"
                        },
                        "signature": {
                          "type": "string"
                        },
                        "sandbox_mode": {
                          "type": "string",
                          "enum": [
                            "simulated",
                            "vpbank_uat"
                          ],
                          "description": "simulated: Finex đóng vai VPBank; vpbank_uat: gọi VPBank UAT thật"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "string_to_sign": "1764036000.GET./v1/partner/reference-data/provinces.",
                    "signature": "<64 ký tự hex>",
                    "sandbox_mode": "simulated"
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": null,
        "x-valid-steps": null,
        "x-errors": [
          {
            "status": 404,
            "code": "NOT_FOUND",
            "description": "Ứng dụng production"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ]
      }
    },
    "/sandbox/leads/{id}/vpbank-event": {
      "post": {
        "operationId": "sandboxVpbankEvent",
        "summary": "Giả lập kết quả VPBank (sandbox)",
        "description": "**Chỉ có trên sandbox** (ứng dụng production nhận `404 NOT_FOUND`). Bạn chọn kết quả VPBank trả về cho hồ sơ, Finex xử lý như khi VPBank gửi thật: cập nhật `lead` và gửi callback. Dùng được ở cả chế độ giả lập lẫn VPBank UAT.\n\n- `r1_ekyc`, `r1_vkyc`: có kết quả thẩm định sơ bộ, đi nhánh EKYC hoặc VKYC.\n- `r1_reject`: VPBank từ chối ở bước thẩm định sơ bộ.\n- `contract_ready`: hợp đồng đã sẵn sàng (EKYC).\n- `approve`, `issue`: VPBank duyệt, phát hành thẻ. Có thể kèm `limit_approved`, `approved_card`.\n- `cancel`: huỷ hồ sơ, có thể kèm `cancel_reason` (mặc định `DS01_001`, tức `RESTRICTED_SCORE`).\n- `vkyc_fail`: Video KYC không đạt (`VKYC_EXPIRED_OR_REJECTED`).\n\nỞ chế độ giả lập, gọi `approve` thủ công **không** tự kéo theo `issue`: hãy gọi `issue` riêng. Trả về `event` và `lead` sau khi cập nhật.",
        "tags": [
          "Công cụ"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "event"
                ],
                "properties": {
                  "event": {
                    "type": "string",
                    "enum": [
                      "r1_ekyc",
                      "r1_vkyc",
                      "r1_reject",
                      "contract_ready",
                      "approve",
                      "issue",
                      "cancel",
                      "vkyc_fail"
                    ]
                  },
                  "cancel_reason": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Mã lý do huỷ của VPBank, mặc định DS01_001. Dùng với cancel, vkyc_fail."
                  },
                  "limit_approved": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Hạn mức được duyệt. Dùng với approve, issue."
                  },
                  "approved_card": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Mã thẻ được duyệt. Dùng với approve, issue."
                  }
                }
              },
              "example": {
                "event": "approve",
                "limit_approved": "30000000",
                "approved_card": "MTSC"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Đã áp dụng",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "request_id",
                    "data",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "event": {
                          "type": "string"
                        },
                        "lead": {
                          "$ref": "#/components/schemas/Lead"
                        }
                      }
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                },
                "example": {
                  "success": true,
                  "request_id": "req_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                  "data": {
                    "event": "approve",
                    "lead": {
                      "lead_id": "6b070048cee4381886a66adb",
                      "status": "APPROVED",
                      "next_step": "awaiting_result",
                      "kyc_segment": "EKYC",
                      "offer": {
                        "limit": 50000000,
                        "cards": [
                          "MTSC",
                          "MLT"
                        ]
                      },
                      "contract_url": null,
                      "approval": {
                        "limit": 30000000,
                        "card": "MTSC"
                      },
                      "cancel": null,
                      "updated_at": "2026-11-25T21:00:05+07:00"
                    }
                  },
                  "message": null
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR, INVALID_REQUEST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "AUTH_INVALID_KEY, INVALID_SIGNATURE, TIMESTAMP_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "IP_NOT_ALLOWED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "NOT_FOUND, LEAD_NOT_FOUND",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "INVALID_STATE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "INTERNAL_ERROR",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-scope": "leads:write",
        "x-valid-steps": null,
        "x-errors": [
          {
            "status": 400,
            "code": "VALIDATION_ERROR",
            "description": "event không hợp lệ"
          },
          {
            "status": 404,
            "code": "NOT_FOUND",
            "description": "Ứng dụng production"
          },
          {
            "status": 404,
            "code": "LEAD_NOT_FOUND"
          },
          {
            "status": 409,
            "code": "INVALID_STATE",
            "description": "Hồ sơ đã ISSUED/CANCELLED, hoặc app UAT mà hồ sơ chưa nộp được sang VPBank"
          },
          {
            "status": 400,
            "code": "INVALID_REQUEST"
          },
          {
            "status": 401,
            "code": "AUTH_INVALID_KEY"
          },
          {
            "status": 401,
            "code": "INVALID_SIGNATURE"
          },
          {
            "status": 401,
            "code": "TIMESTAMP_EXPIRED"
          },
          {
            "status": 403,
            "code": "IP_NOT_ALLOWED"
          },
          {
            "status": 429,
            "code": "RATE_LIMITED"
          },
          {
            "status": 500,
            "code": "INTERNAL_ERROR"
          }
        ]
      }
    }
  },
  "webhooks": {
    "leadEvent": {
      "post": {
        "summary": "Callback trạng thái hồ sơ",
        "description": "Finex POST tới `callback_url` với header `x-timestamp`, `x-signature` = hex(HMAC-SHA256(callback_secret, x-timestamp + \".\" + raw_body)), `x-finex-event-id`. Trả 2xx trong 10 giây. Retry sau 1 phút → 5 phút → 15 phút → 1 giờ → 6 giờ → 24 giờ (tổng 7 lần).",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CallbackEvent"
              },
              "example": {
                "event_id": "evt_0MH8Q2K1X4F2A9C0D1E2F3A4B5C6D7",
                "event_type": "lead.ekyc_required",
                "occurred_at": "2026-11-25T21:02:03+07:00",
                "lead": {
                  "lead_id": "6b070048cee4381886a66adb",
                  "status": "SUBMITTED",
                  "next_step": "ocr",
                  "kyc_segment": "EKYC",
                  "offer": {
                    "limit": 50000000,
                    "cards": [
                      "MTSC",
                      "MLT"
                    ]
                  },
                  "contract_url": null,
                  "approval": null,
                  "cancel": null,
                  "updated_at": "2026-11-25T21:02:03+07:00"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Đã nhận (bất kỳ 2xx)"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "API key fx_test_… / fx_live_… (≤ 256 ký tự)."
      },
      "Timestamp": {
        "type": "apiKey",
        "in": "header",
        "name": "x-timestamp",
        "description": "Unix time tính bằng giây, lệch tối đa ±300 giây."
      },
      "Signature": {
        "type": "apiKey",
        "in": "header",
        "name": "x-signature",
        "description": "hex(HMAC-SHA256(api_secret, \"{x-timestamp}.{METHOD}.{path_with_query}.{raw_body}\")), chữ thường."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        },
        "description": "Một UUID (nên dùng v4), bắt buộc với mọi POST và PUT. Finex nhớ key trong 24 giờ."
      },
      "LeadId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "maxLength": 64
        },
        "description": "Mã hồ sơ (`lead_id`)."
      },
      "SandboxScenario": {
        "name": "x-sandbox-scenario",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string",
          "enum": [
            "REQUIRE_QR",
            "EKYC_RETRY",
            "EKYC_TRY_LATER",
            "EKYC_CANCELLED",
            "UPSTREAM_ERROR"
          ]
        },
        "description": "Chỉ có trên sandbox: chọn trước kết quả của bước chụp ảnh."
      }
    },
    "schemas": {
      "Lead": {
        "type": "object",
        "description": "Cùng một cấu trúc trong data.lead, error.lead và callback. Trường chưa có giá trị thì là null.",
        "required": [
          "lead_id",
          "status",
          "next_step",
          "kyc_segment",
          "offer",
          "contract_url",
          "approval",
          "cancel",
          "updated_at"
        ],
        "properties": {
          "lead_id": {
            "type": "string",
            "maxLength": 64,
            "description": "Mã hồ sơ, hiện là 24 ký tự hex. Coi là một chuỗi, lưu bằng cột ≥ 64 ký tự."
          },
          "status": {
            "type": "string",
            "enum": [
              "PENDING",
              "SUBMITTED",
              "APPROVED",
              "ISSUED",
              "CANCELLED"
            ],
            "description": "ISSUED và CANCELLED là trạng thái cuối."
          },
          "next_step": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "submit",
              "ocr",
              "qr",
              "liveness",
              "additional_info",
              "awaiting_contract",
              "econtract",
              "vkyc",
              "awaiting_result",
              "none",
              null
            ],
            "description": "Việc cần làm tiếp. null nghĩa là đang chờ kết quả thẩm định sơ bộ."
          },
          "kyc_segment": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "EKYC",
              "VKYC",
              null
            ],
            "description": "Có sau bước thẩm định sơ bộ."
          },
          "offer": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Offer"
              },
              {
                "type": "null"
              }
            ]
          },
          "contract_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Link PDF hợp đồng, chỉ có khi next_step = econtract, về null ngay sau khi ký OTP. Hết hạn sau khoảng 1 giờ (hết hạn hoặc bị sửa thì trả 404), mở được mà không cần API key."
          },
          "approval": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Approval"
              },
              {
                "type": "null"
              }
            ]
          },
          "cancel": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Cancel"
              },
              {
                "type": "null"
              }
            ]
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 +07:00."
          }
        }
      },
      "Offer": {
        "type": "object",
        "properties": {
          "limit": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Hạn mức đề xuất (VND)."
          },
          "cards": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Các loại thẻ khách được chọn (xem bảng mã thẻ)."
          }
        }
      },
      "Approval": {
        "type": "object",
        "properties": {
          "limit": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Hạn mức được cấp (VND)."
          },
          "card": {
            "type": [
              "string",
              "null"
            ],
            "description": "Mã thẻ được duyệt."
          }
        }
      },
      "Cancel": {
        "type": "object",
        "properties": {
          "reason_code": {
            "type": "string",
            "description": "Mã lý do huỷ, dùng để thống kê. Finex có thể thêm mã mới."
          },
          "customer_message": {
            "type": "string",
            "description": "Câu hiện nguyên văn cho khách."
          }
        }
      },
      "LovItem": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "Mã gốc VPBank, gửi lại nguyên văn."
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "parent_code": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ErrorDetail": {
        "type": "object",
        "properties": {
          "field": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "success",
          "request_id",
          "error"
        ],
        "properties": {
          "success": {
            "const": false
          },
          "request_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "retryable"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "Xử lý theo trường này. Finex có thể thêm mã mới."
              },
              "message": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              },
              "action": {
                "type": "string",
                "enum": [
                  "retry",
                  "try_later",
                  "cancelled"
                ],
                "description": "Chỉ có ở bước chụp ảnh."
              },
              "details": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ErrorDetail"
                }
              },
              "lead": {
                "$ref": "#/components/schemas/Lead"
              }
            }
          }
        }
      },
      "Device": {
        "type": "object",
        "required": [
          "user_agent"
        ],
        "properties": {
          "user_agent": {
            "type": "string",
            "maxLength": 512
          },
          "type_of_device": {
            "type": "string",
            "maxLength": 64
          },
          "operating_system": {
            "type": "string",
            "maxLength": 64
          },
          "browser_name": {
            "type": "string",
            "maxLength": 64
          },
          "country": {
            "type": "string",
            "maxLength": 64
          },
          "city": {
            "type": "string",
            "maxLength": 64
          }
        }
      },
      "CreateLeadRequest": {
        "type": "object",
        "required": [
          "ip_address",
          "device",
          "full_name",
          "phone_number",
          "email",
          "dob",
          "gender",
          "marital_status",
          "document_number",
          "date_of_issue",
          "place_of_issue",
          "permanent_province",
          "permanent_district",
          "permanent_address",
          "current_province",
          "current_district",
          "current_address",
          "employer_status",
          "job_position",
          "income_amount",
          "consent0",
          "consent1",
          "consent2",
          "consent3",
          "consent_timestamp"
        ],
        "properties": {
          "ip_address": {
            "type": "string",
            "format": "ipv4",
            "description": "IPv4 của điện thoại/máy khách, không phải IP server."
          },
          "device": {
            "$ref": "#/components/schemas/Device"
          },
          "full_name": {
            "type": "string",
            "description": "6–32 ký tự, 2–6 từ, chỉ chữ cái Latin (có dấu tiếng Việt), các từ cách nhau đúng 1 dấu cách, không số/ký tự đặc biệt/tab. Finex lưu IN HOA."
          },
          "phone_number": {
            "type": "string",
            "pattern": "^0(3|5|7|8|9)\\d{8}$"
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 100
          },
          "dob": {
            "type": "string",
            "description": "DD/MM/YYYY, ngày có thật, không ở tương lai."
          },
          "gender": {
            "type": "string",
            "enum": [
              "M",
              "F"
            ]
          },
          "marital_status": {
            "type": "string",
            "enum": [
              "SINGLE",
              "MARRIED",
              "DIVORCED"
            ]
          },
          "document_number": {
            "type": "string",
            "pattern": "^0\\d{2}[0-3]\\d{8}$",
            "description": "CCCD 12 số."
          },
          "date_of_issue": {
            "type": "string",
            "description": "DD/MM/YYYY, không ở tương lai."
          },
          "date_of_expiry": {
            "type": [
              "string",
              "null"
            ],
            "description": "DD/MM/YYYY, sau ngày cấp và còn hạn > 5 ngày. Để trống/null chỉ khi CCCD \"Không thời hạn\"."
          },
          "place_of_issue": {
            "type": "string",
            "description": "Mã từ GET /v1/partner/reference-data/id-issue-places."
          },
          "document_additional": {
            "type": "string",
            "description": "Bắt buộc khi năm sinh ≤ 1995. Giấy tờ cũ 8–12 ký tự: NationalID = CMND 9 số; Passport = 1 chữ in hoa + 7 số; MilitaryID = 8 số hoặc 12 ký tự chữ/số."
          },
          "document_additional_type": {
            "type": "string",
            "enum": [
              "NationalID",
              "Passport",
              "MilitaryID"
            ],
            "description": "Bắt buộc khi năm sinh ≤ 1995."
          },
          "permanent_province": {
            "type": "string",
            "description": "Mã tỉnh thường trú, từ GET /v1/partner/reference-data/provinces (chuỗi 32 ký tự, gửi nguyên văn)."
          },
          "permanent_district": {
            "type": "string",
            "description": "Mã quận thuộc đúng tỉnh, từ GET /v1/partner/reference-data/districts?parent_code={mã tỉnh}."
          },
          "permanent_address": {
            "type": "string",
            "description": "≤ 60 ký tự sau khi gộp khoảng trắng; bắt đầu bằng chữ hoặc số; chỉ gồm chữ, số, dấu cách và . , ' ( ) # / - _; không chứa tab, +, &; không kết thúc bằng - / , _ : | \\"
          },
          "current_province": {
            "type": "string",
            "description": "Nơi ở hiện tại — cũng là địa chỉ nhận thẻ CUADDR."
          },
          "current_district": {
            "type": "string",
            "description": "Mã quận thuộc đúng tỉnh, từ /reference-data/districts."
          },
          "current_address": {
            "type": "string",
            "description": "≤ 60 ký tự sau khi gộp khoảng trắng; bắt đầu bằng chữ hoặc số; chỉ gồm chữ, số, dấu cách và . , ' ( ) # / - _; không chứa tab, +, &; không kết thúc bằng - / , _ : | \\"
          },
          "employer_status": {
            "type": "string",
            "enum": [
              "EMPL1",
              "EMPL2",
              "EMPL3",
              "EMPL4"
            ]
          },
          "job_position": {
            "type": "string",
            "description": "Phải nằm trong nhóm của employer_status (xem Danh mục giá trị)."
          },
          "income_amount": {
            "type": "integer",
            "minimum": 1000000,
            "description": "VND/tháng."
          },
          "employer_name": {
            "type": "string",
            "maxLength": 100,
            "description": "Bắt buộc, trừ khi employer_status là EMPL3. Nên chọn từ /reference-data/companies (khớp tên, không phân biệt hoa thường); không có trong danh mục vẫn được."
          },
          "employer_province": {
            "type": "string",
            "description": "Bắt buộc trừ EMPL3. Địa chỉ nhận thẻ COADDR."
          },
          "employer_district": {
            "type": "string",
            "description": "Bắt buộc trừ EMPL3."
          },
          "employer_address": {
            "type": "string",
            "description": "Bắt buộc trừ EMPL3. ≤ 60 ký tự sau khi gộp khoảng trắng; bắt đầu bằng chữ hoặc số; chỉ gồm chữ, số, dấu cách và . , ' ( ) # / - _; không chứa tab, +, &; không kết thúc bằng - / , _ : | \\"
          },
          "consent0": {
            "const": "DONG_Y"
          },
          "consent1": {
            "const": "DONG_Y"
          },
          "consent2": {
            "type": "string",
            "enum": [
              "DONG_Y",
              "KHONG_DONG_Y"
            ]
          },
          "consent3": {
            "type": "string",
            "enum": [
              "DONG_Y",
              "KHONG_DONG_Y"
            ]
          },
          "consent_timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "Thời điểm khách đồng ý, ISO 8601 có offset. Finex tự đổi sang định dạng của VPBank."
          }
        }
      },
      "AdditionalInfoRequest": {
        "type": "object",
        "required": [
          "card_type",
          "card_delivery_address",
          "reference1_fullname",
          "reference1_relationship",
          "reference1_mobile_phone_number",
          "security_question",
          "security_answer"
        ],
        "properties": {
          "card_type": {
            "type": "string",
            "description": "Một mã trong lead.offer.cards (nếu offer không có thẻ: mọi mã CARD_TYPE)."
          },
          "card_delivery_address": {
            "type": "string",
            "enum": [
              "CUADDR",
              "COADDR"
            ],
            "description": "CUADDR nơi ở hiện tại; COADDR nơi làm việc (không dùng với EMPL3)."
          },
          "reference1_fullname": {
            "type": "string",
            "description": "Người tham chiếu. 6–32 ký tự, 2–6 từ, chỉ chữ cái Latin (có dấu tiếng Việt), các từ cách nhau đúng 1 dấu cách, không số/ký tự đặc biệt/tab. Finex lưu IN HOA."
          },
          "reference1_relationship": {
            "type": "string",
            "description": "Mã từ /reference-data/relationships, ví dụ SB (anh/chị/em ruột)."
          },
          "reference1_mobile_phone_number": {
            "type": "string",
            "pattern": "^0(3|5|7|8|9)\\d{8}$",
            "description": "Khác SĐT của khách."
          },
          "security_question": {
            "type": "string",
            "description": "Một trong 6 câu hỏi bảo mật, nguyên văn."
          },
          "security_answer": {
            "type": "string",
            "minLength": 3,
            "maxLength": 32
          },
          "fatca": {
            "type": "string",
            "enum": [
              "Y",
              "N"
            ],
            "default": "N"
          },
          "tin_number": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 16,
            "description": "Bắt buộc khi fatca = Y."
          }
        }
      },
      "CallbackEvent": {
        "type": "object",
        "required": [
          "event_id",
          "event_type",
          "occurred_at",
          "lead"
        ],
        "properties": {
          "event_id": {
            "type": "string",
            "description": "Dùng để nhận ra tin trùng. Tin gửi lại giữ nguyên mã này."
          },
          "event_type": {
            "type": "string",
            "enum": [
              "lead.ekyc_required",
              "lead.contract_ready",
              "lead.approved",
              "lead.issued",
              "lead.cancelled"
            ]
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "lead": {
            "$ref": "#/components/schemas/Lead"
          }
        }
      }
    }
  }
}
