终端
终端由 Kuvex 在发货时按序列号分配至商户账号,无需调用接口绑定。各型号的外设配置见硬件。
终端列表
GET /v1/terminals返回当前账号下的全部终端及实时状态。
| 项目 | 要求 |
|---|---|
| 鉴权 | 服务端密钥 |
响应:200 OK,{ "object": "list", "data": [终端] },字段见终端字段。
查询终端
GET /v1/terminals/{id}返回单台终端,比列表多返回 machine(终端所在设备信息)。
| 项目 | 要求 |
|---|---|
| 鉴权 | 服务端密钥、浏览器令牌、主机令牌 |
响应:200 OK
{
"id": "KV100023",
"object": "terminal",
"label": "Front counter",
"status": "online",
"payment_ready": true,
"execution": { "state": "idle", "owner_payment_id": null },
"battery_pct": 86,
"runtime_version": "0.1.294.261120",
"run_profile": "standalone",
"livemode": true,
"last_seen_at": "2026-11-30T18:20:11Z",
"cash_drawer": { "status": "unknown", "request_id": null, "last_result": null }
}错误码
| HTTP | 错误码 | 说明 | 可重试 |
|---|---|---|---|
| 404 | terminal_not_found | 终端不存在或不属于当前账号 | 否 |
终端离线时无法收款,创建收款返回 409 terminal_offline。终端断线在数秒内即可被检测到。
打印
POST /v1/terminals/{id}/print以结构化数据提交打印内容,由终端按所连打印机排版输出。不接受 ESC/POS 等打印机指令。
| 项目 | 要求 |
|---|---|
| 鉴权 | 服务端密钥、浏览器令牌 |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
receipt | Object | 是 | 打印内容,字段见下表 |
payment_id | String | 否 | 关联的收款 ID。传入后,终端从本地交易记录补充卡信息与实付金额 |
receipt 字段:
| 字段 | 类型 | 说明 |
|---|---|---|
kind | String | 单据类型。不传为销售小票;order 订单、kitchen 厨房单、call_number 叫号单、refund 退款单 |
header / title / footer | String | 页头、标题、页脚 |
store_name / store_address1 / store_address2 / store_phone | String | 门店信息 |
order_number / channel_label / order_time | String | 订单信息 |
lines | Array | 商品行,最多 100 行。每行:name(String,≤ 200 字符)、qty(int)、amount_cents(int)、detail(String,可选) |
subtotal_cents / tax_cents / tip_cents / total_cents | int | 小计、税、小费、合计,单位:分 |
tax_rate_label | String | 税率说明,如 "8.875%" |
qr_data / qr_hint | String | 二维码内容及下方说明文字 |
卡信息与实付金额以终端交易记录为准,receipt 中的同类字段会被忽略。
请求示例
curl https://api.kuvex.com/v1/terminals/KV100023/print \
-H "Authorization: Bearer $KUVEX_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"payment_id": "pay_3kTq9xV2mB7nL4pR8sWz",
"receipt": {
"header": "DEMO CAFE",
"lines": [{ "name": "Latte", "qty": 2, "amount_cents": 900 }],
"subtotal_cents": 900,
"tax_cents": 80,
"total_cents": 980,
"footer": "Thank you"
}
}'响应:202 Accepted
{ "id": "prt_6bK3wN9qT2xM5pV8sL1r", "object": "print_job", "terminal_id": "KV100023", "status": "dispatched" }dispatched 表示任务已下发终端,不代表已打印。打印结果事件:print.succeeded、print.failed、print.delivery_unknown,见打印事件。无打印机的终端跳过任务,不发送事件。
交易成功后,终端自动打印签购单,无需调用本接口。本接口用于商户自定义单据。
错误码
| HTTP | 错误码 | 说明 | 可重试 |
|---|---|---|---|
| 409 | terminal_offline | 终端离线 | 是 |
扫码
POST /v1/terminals/{id}/scan启动终端扫码,等待读取一个条码或二维码,最长 30 秒。接口同步返回,调用方 HTTP 超时应大于 30 秒。
| 项目 | 要求 |
|---|---|
| 鉴权 | 服务端密钥、浏览器令牌 |
响应:200 OK
{ "id": "scn_9pT4kW2nX7qM1vL5sR8b", "object": "scan", "status": "completed", "data": "0123456789012" }| 字段 | 类型 | 说明 |
|---|---|---|
status | String | completed:已读取;timeout:30 秒内未读取到 |
data | String | 码内容;timeout 时为 null |
timeout 不属于错误。单次调用读取一个码。
错误码
| HTTP | 错误码 | 说明 | 可重试 |
|---|---|---|---|
| 409 | terminal_offline | 终端离线 | 是 |
打开钱箱
POST /v1/terminals/{id}/cash-drawer/open通过终端所配置小票打印机的钱箱接口(RJ11)发送开箱脉冲。
| 项目 | 要求 |
|---|---|
| 鉴权 | 服务端密钥、浏览器令牌 |
响应:202 Accepted
{ "request_id": "drw_1mK8qT3wN6xV9pL2sR5b", "terminal_id": "KV100023", "status": "pending" }执行结果通过查询终端的 cash_drawer 字段获取,需校验 cash_drawer.last_result.request_id 与本次 request_id 一致。
cash_drawer.status | 说明 |
|---|---|
pending | 终端尚未回报 |
dispatched | 开箱脉冲已发送至打印机 |
failed | 发送失败,原因见 last_result.reason(通常为未配置打印机或打印机不可达) |
ESC/POS 协议无钱箱状态回执,dispatched 不代表钱箱已实际打开,不应作为现金对账依据。钱箱操作无 Webhook 事件。
切换运行模式(仅测试环境)
POST /v1/terminals/{id}/run-profile将测试终端在独立模式与副机模式之间切换,用于在沙箱中调试副机模式。变更立即下发,终端离线时在下次连接时生效。
| 项目 | 要求 |
|---|---|
| 鉴权 | 仅服务端密钥 |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
profile | String | 是 | host_call_secondary:副机模式;standalone:独立模式 |
响应:200 OK
{ "object": "terminal_run_profile", "terminal_id": "KV100023", "profile": "host_call_secondary", "version": 7 }错误码
| HTTP | 错误码 | 说明 | 可重试 |
|---|---|---|---|
| 400 | run_profile_invalid | profile 取值非法 | 否 |
| 403 | run_profile_managed_by_kuvex | 正式终端的运行模式由 Kuvex 配置 | 否 |
认领终端(已停用)
POST /v1/terminals/claim固定返回 410 claim_code_retired。认领码已停用,终端由 Kuvex 按序列号分配;如终端缺失,请提供序列号联系 Kuvex。
终端字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | String | 终端 ID,KV 前缀 |
label | String | 终端名称 |
kind | String | 终端类型,沙箱虚拟终端为 virtual |
model | String | 设备型号 |
status | String | online 在线、busy 交易中、attention 需人工处理、offline 离线 |
payment_ready | boolean | 终端在线、支付模块就绪且空闲时为 true |
execution | Object | 执行状态:state(idle / running / attention)、owner_payment_id(正在处理的收款 ID,用于应用重启后恢复进行中的交易) |
battery_pct | int | 电量百分比,无电池型号为 null |
runtime_version | String | Kuvex Runtime 版本,如 0.1.294.261120,第三段为 Runtime 版本号 |
run_profile | String | standalone 独立模式;host_call_secondary 副机模式 |
cash_drawer | Object | 最近一次钱箱操作:status、request_id、last_result |
machine | Object | 设备信息,仅查询终端返回 |
livemode | boolean | true 正式终端,false 测试终端 |
last_seen_at | String | 最后在线时间,ISO 8601(UTC) |