@itpay/cli 2.0.2 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +92 -142
  2. package/dist/src/client/backend.js +27 -9
  3. package/dist/src/commands/buy.js +84 -132
  4. package/dist/src/commands/cart.js +274 -169
  5. package/dist/src/commands/catalog.js +63 -38
  6. package/dist/src/commands/checkout.js +117 -78
  7. package/dist/src/commands/docs.js +97 -51
  8. package/dist/src/commands/guidance.js +87 -15
  9. package/dist/src/commands/install.js +50 -87
  10. package/dist/src/commands/next.js +45 -0
  11. package/dist/src/commands/order.js +44 -69
  12. package/dist/src/commands/orders.js +43 -15
  13. package/dist/src/commands/pay.js +51 -22
  14. package/dist/src/commands/readyz.js +8 -4
  15. package/dist/src/commands/refund.js +132 -14
  16. package/dist/src/commands/services.js +719 -148
  17. package/dist/src/main.js +711 -201
  18. package/dist/src/render/output.js +2 -3
  19. package/dist/src/state/cart_session.js +13 -17
  20. package/dist/src/state/client_context.js +4 -2
  21. package/dist/src/state/config.js +3 -5
  22. package/dist/src/state/device_authority.js +1 -1
  23. package/docs/agent/buyer/cart-checkout.json +27 -83
  24. package/docs/agent/buyer/install-and-setup.json +23 -67
  25. package/docs/agent/buyer/orders-refunds.json +31 -53
  26. package/docs/agent/buyer/payment-flow.json +24 -57
  27. package/docs/agent/buyer/quickstart.json +39 -162
  28. package/docs/agent/buyer/render-hosts.json +43 -57
  29. package/docs/cli-reference/agent-types.md +45 -0
  30. package/docs/cli-reference/commands/buy.md +167 -0
  31. package/docs/cli-reference/commands/cart/add.md +86 -0
  32. package/docs/cli-reference/commands/cart/clear.md +53 -0
  33. package/docs/cli-reference/commands/cart/index.md +30 -0
  34. package/docs/cli-reference/commands/cart/next.md +71 -0
  35. package/docs/cli-reference/commands/cart/remove.md +53 -0
  36. package/docs/cli-reference/commands/cart/show.md +65 -0
  37. package/docs/cli-reference/commands/catalog/index.md +26 -0
  38. package/docs/cli-reference/commands/catalog/list.md +45 -0
  39. package/docs/cli-reference/commands/checkout.md +74 -0
  40. package/docs/cli-reference/commands/docs/index.md +28 -0
  41. package/docs/cli-reference/commands/docs/list.md +51 -0
  42. package/docs/cli-reference/commands/docs/search.md +69 -0
  43. package/docs/cli-reference/commands/docs/show.md +68 -0
  44. package/docs/cli-reference/commands/install.md +112 -0
  45. package/docs/cli-reference/commands/next.md +87 -0
  46. package/docs/cli-reference/commands/order.md +92 -0
  47. package/docs/cli-reference/commands/orders.md +83 -0
  48. package/docs/cli-reference/commands/pay.md +103 -0
  49. package/docs/cli-reference/commands/readyz.md +39 -0
  50. package/docs/cli-reference/commands/refund/cancel.md +62 -0
  51. package/docs/cli-reference/commands/refund/create.md +85 -0
  52. package/docs/cli-reference/commands/refund/get.md +60 -0
  53. package/docs/cli-reference/commands/refund/index.md +33 -0
  54. package/docs/cli-reference/commands/refund/list.md +68 -0
  55. package/docs/cli-reference/commands/refund/watch.md +73 -0
  56. package/docs/cli-reference/commands/services/action.md +43 -0
  57. package/docs/cli-reference/commands/services/checkout.md +82 -0
  58. package/docs/cli-reference/commands/services/events.md +73 -0
  59. package/docs/cli-reference/commands/services/get.md +66 -0
  60. package/docs/cli-reference/commands/services/index.md +45 -0
  61. package/docs/cli-reference/commands/services/invoke.md +67 -0
  62. package/docs/cli-reference/commands/services/list.md +61 -0
  63. package/docs/cli-reference/commands/services/next.md +162 -0
  64. package/docs/cli-reference/commands/services/quote.md +59 -0
  65. package/docs/cli-reference/commands/services/read-result.md +98 -0
  66. package/docs/cli-reference/commands/services/start.md +53 -0
  67. package/docs/cli-reference/conventions.md +94 -0
  68. package/docs/cli-reference/index.md +64 -0
  69. package/package.json +1 -1
  70. package/skills/itpay-buyer/SKILL.md +47 -113
@@ -0,0 +1,68 @@
1
+ # `itpay docs show`
2
+
3
+ ## 范围与意义
4
+
5
+ 读取一个指定 Agent 文档 topic。这是 docs 命令族中唯一返回完整文档内容的命令;不会级联读取其他 topic,也不访问 Backend。
6
+
7
+ **上游:** `docs list` 或唯一匹配的 `docs search`。
8
+
9
+ **下游:** 结合当前服务端状态,只执行文档中适用的一步。
10
+
11
+ ## 语法与参数
12
+
13
+ ```bash
14
+ itpay docs show <topic> [--json]
15
+ ```
16
+
17
+ | 参数 | 必填 | 说明 |
18
+ | --- | --- | --- |
19
+ | `topic` | 是 | `docs list/search` 返回的稳定、大小写敏感 topic。 |
20
+ | `--json` | 否 | 把完整 topic 放进标准 envelope;推荐 Agent 使用。 |
21
+
22
+ ## JSON 输出
23
+
24
+ ```json
25
+ {
26
+ "status": "shown",
27
+ "result": {
28
+ "topic": "<topic>",
29
+ "content": {
30
+ "schema_version": "itp.agent_doc.v1",
31
+ "topic": "<topic>",
32
+ "title": "<title>",
33
+ "purpose": "<purpose>"
34
+ }
35
+ },
36
+ "instruction": "只执行文档中与当前服务端状态匹配的步骤;服务端返回的当前 next 优先。",
37
+ "next": null,
38
+ "recovery": []
39
+ }
40
+ ```
41
+
42
+ `content` 示例仅显示必备头部;实际返回该 topic 的完整结构。非 JSON 模式打印 `shown`、完整 topic JSON 和同一条 instruction,不附加其他 topic。
43
+
44
+ ## 异常处理
45
+
46
+ topic 不存在返回 `doc_not_found`:
47
+
48
+ ```json
49
+ {
50
+ "status": "error",
51
+ "error": {
52
+ "code": "doc_not_found",
53
+ "message": "doc topic not found: <topic>"
54
+ },
55
+ "instruction": "使用稳定 topic 名称;不要根据标题猜 topic。",
56
+ "next": null,
57
+ "recovery": [
58
+ { "command": "itpay docs list --json", "reason": "列出全部 topic" },
59
+ { "command": "itpay docs search <topic> --json", "reason": "按关键词重新搜索" }
60
+ ]
61
+ }
62
+ ```
63
+
64
+ 文档文件损坏使用 `docs_unavailable`,与 `docs list` 相同。
65
+
66
+ ## Agent Type / Host
67
+
68
+ 五种正式 Agent Type 使用同一 topic。topic 若包含多种 Host 指导,Agent 只采用与自身 Agent Type 和当前 Host 匹配的部分。
@@ -0,0 +1,112 @@
1
+ # `itpay install`
2
+
3
+ ## 范围与意义
4
+
5
+ 读取当前 CLI 内置的 Agent Type 安装合同。它只说明 npm 安装、默认 API、默认 Host 和下一条验证命令;不修改宿主配置、不登记设备,也不调用 Backend。
6
+
7
+ **上游:** 安装或更新 `@itpay/cli`。
8
+
9
+ **下游:** 使用真实 Agent Type 执行 `readyz`,随后读取 Catalog。
10
+
11
+ ## 语法与参数
12
+
13
+ ```bash
14
+ itpay install [target] [--json]
15
+ ```
16
+
17
+ | 参数 | 必填 | 说明 |
18
+ | --- | --- | --- |
19
+ | `target` | 否 | 五种正式 Agent Type 之一;省略或传 `list` 时列出全部。Host 名称不是合法 target。 |
20
+ | `--json` | 否 | 返回标准命令 envelope;推荐 Agent 使用。 |
21
+
22
+ 正式 target:`codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy`。
23
+
24
+ ## 指定 Agent Type 输出
25
+
26
+ ```json
27
+ {
28
+ "status": "instructions_ready",
29
+ "result": {
30
+ "agent_type": "codex-desktop",
31
+ "default_host": "codex",
32
+ "default_api": "https://app.itpay.ai",
33
+ "install_command": "npm install -g @itpay/cli"
34
+ },
35
+ "instruction": "在 Codex Desktop 中始终传这个 Agent Type;付款时把返回的二维码和链接实际展示到当前对话。",
36
+ "next": {
37
+ "command": "itpay --agent-type codex-desktop readyz --json",
38
+ "reason": "验证 CLI 与默认 ItPay API 的兼容性"
39
+ },
40
+ "recovery": [
41
+ {
42
+ "command": "itpay docs show install-and-setup",
43
+ "reason": "查看环境覆盖和首次使用说明"
44
+ }
45
+ ]
46
+ }
47
+ ```
48
+
49
+ `result` 是客观安装事实;`instruction` 只解释当前 Agent Type 的展示责任;`next` 只有一条可执行验证命令。
50
+
51
+ ## 列表输出
52
+
53
+ 省略 target 或传 `list` 时返回五组 `agent_type/default_host`,不重复每种类型的完整 instruction:
54
+
55
+ ```json
56
+ {
57
+ "status": "install_targets",
58
+ "result": {
59
+ "agent_types": [
60
+ { "agent_type": "codex-desktop", "default_host": "codex" },
61
+ { "agent_type": "codex-cli", "default_host": "terminal" },
62
+ { "agent_type": "claude-code-desktop", "default_host": "claude-code" },
63
+ { "agent_type": "claude-code-cli", "default_host": "terminal" },
64
+ { "agent_type": "workbuddy", "default_host": "plain-chat" }
65
+ ]
66
+ },
67
+ "instruction": "选择当前真实运行环境;同一 Agent 不要临时更换 Agent Type。",
68
+ "next": null,
69
+ "recovery": [
70
+ {
71
+ "command": "itpay docs show install-and-setup",
72
+ "reason": "查看安装与环境说明"
73
+ }
74
+ ]
75
+ }
76
+ ```
77
+
78
+ ## Agent Type / Host
79
+
80
+ | Agent Type | 默认 Host | instruction 重点 |
81
+ | --- | --- | --- |
82
+ | `codex-desktop` | `codex` | 桌面对话必须实际展示二维码和付款链接。 |
83
+ | `codex-cli` | `terminal` | 只在用户可见终端展示付款交接。 |
84
+ | `claude-code-desktop` | `claude-code` | 桌面对话必须实际展示二维码和付款链接。 |
85
+ | `claude-code-cli` | `terminal` | 只在用户可见终端展示付款交接。 |
86
+ | `workbuddy` | `plain-chat` | 当前使用通用会话交接,必须发送链接和可用图片。 |
87
+
88
+ 显式 `--host` 可以在后续 commerce 命令覆盖默认 Host,但不会改变 Agent Type 或设备归属。
89
+
90
+ ## 异常处理
91
+
92
+ 未知 target 返回:
93
+
94
+ ```json
95
+ {
96
+ "status": "error",
97
+ "error": {
98
+ "code": "unsupported_agent_type",
99
+ "message": "unsupported install target: codex"
100
+ },
101
+ "instruction": "target 只接受:codex-desktop, codex-cli, claude-code-desktop, claude-code-cli, workbuddy。",
102
+ "next": null,
103
+ "recovery": [
104
+ {
105
+ "command": "itpay install --json",
106
+ "reason": "列出正式支持的 Agent Type"
107
+ }
108
+ ]
109
+ }
110
+ ```
111
+
112
+ 错误不会写入本地状态。不要把 `codex`、`terminal` 或 `claude-code` 等 Host 名称当成 Agent Type。
@@ -0,0 +1,87 @@
1
+ # `itpay next`
2
+
3
+ ## 范围与意义
4
+
5
+ 从本机保存的 canonical Cart、Checkout 或 Service Execution 句柄恢复一个首选动作。它是中断后的总入口,不替代具体资源的 `next/get`,也不读取或复制 Backend DTO。
6
+
7
+ **上游:** 任意创建过 cart、checkout 或 execution 的 CLI 流程。
8
+ **下游:** 返回的单一恢复命令。
9
+
10
+ 句柄优先级固定为:
11
+
12
+ ```text
13
+ Service Execution -> Checkout -> Cart -> Catalog
14
+ ```
15
+
16
+ 一条 Service Execution 流程通常同时留下 Cart 和 Checkout 句柄;优先恢复最具体的 execution 可避免从旧 Cart 重建资源。
17
+
18
+ ## 语法与参数
19
+
20
+ ```bash
21
+ itpay next [--json]
22
+ ```
23
+
24
+ | 参数 | 必填 | 说明 |
25
+ |---|---:|---|
26
+ | `--json` | 否 | 返回标准 JSON。 |
27
+
28
+ 该命令只读本地 `0600` handle cache,不访问 Backend、不创建资源,也不要求 Buyer session。返回的下一条资源命令负责读取服务端权威状态。
29
+
30
+ ## 标准输出
31
+
32
+ ```json
33
+ {
34
+ "status": "resume_available",
35
+ "result": { "resource_type": "service_execution", "resource_id": "<service_execution_id>" },
36
+ "instruction": "继续已有资源,不要创建重复订单或 Checkout。",
37
+ "next": { "command": "itpay services next <service_execution_id> --json", "reason": "读取服务端最新状态" },
38
+ "recovery": []
39
+ }
40
+ ```
41
+
42
+ Checkout 句柄返回:
43
+
44
+ ```json
45
+ {
46
+ "status": "resume_available",
47
+ "result": { "resource_type": "checkout", "resource_id": "<checkout_id>" },
48
+ "instruction": "继续已有资源,不要创建重复订单或 Checkout。",
49
+ "next": {
50
+ "command": "itpay checkout --id <checkout_id> --token <display_token> --json",
51
+ "reason": "恢复同一 Checkout"
52
+ },
53
+ "recovery": []
54
+ }
55
+ ```
56
+
57
+ 只存在 Cart 句柄时,`resource_type` 为 `cart`,下一步是 `itpay cart next --json`。
58
+
59
+ 没有本地句柄时:
60
+
61
+ ```json
62
+ {
63
+ "status": "nothing_to_resume",
64
+ "result": {},
65
+ "instruction": "本地没有可恢复句柄;先读取已发布目录,不要猜测 service_id。",
66
+ "next": { "command": "itpay catalog list --json", "reason": "选择已发布服务" },
67
+ "recovery": []
68
+ }
69
+ ```
70
+
71
+ 本地状态文件损坏或不可读时不静默猜测资源:
72
+
73
+ ```json
74
+ {
75
+ "status": "local_state_invalid",
76
+ "result": {},
77
+ "instruction": "本地恢复句柄无法读取;不要猜测资源 ID,改从当前设备可见的服务执行恢复。",
78
+ "next": { "command": "itpay services list --json", "reason": "从服务端恢复当前设备可见的执行" },
79
+ "recovery": []
80
+ }
81
+ ```
82
+
83
+ 若下一条资源命令发现服务端句柄已经失效,遵循该命令的结构化 recovery;不要修改本地文件或猜 ID。
84
+
85
+ ## Agent Type / Host
86
+
87
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种 Agent Type 的状态、instruction 和下一步完全相同。本命令不产生二维码或 Host handoff。
@@ -0,0 +1,92 @@
1
+ # `itpay order`
2
+
3
+ ## 范围与意义
4
+
5
+ 读取一笔当前 Buyer 或已绑定 Agent 可见的订单摘要、交付模式和退款访问锁。它不会返回受保护交付内容、Vault ID、内部 delivery artifact 或 Checkout token。
6
+
7
+ **上游:** Checkout 完成、订单列表、邮件或 Service Execution 返回的 `order_id`。
8
+ **下游:** `services next`、退款状态查询,或等待同一订单继续推进。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay order <order_id> [--host <host>] [--json]
14
+ ```
15
+
16
+ | 参数 | 必填 | 说明 |
17
+ | --- | --- | --- |
18
+ | `order_id` | 是 | 订单 ID。 |
19
+ | `--host <host>` | 否 | 兼容已有调用并校验 Host 名称;不改变订单事实或输出结构。 |
20
+ | `--json` | 否 | 输出稳定 JSON 信封;未指定时输出相同事实的简洁文本。 |
21
+
22
+ CLI 使用 Agent Device Authority。设备完成首次付款绑定后,已登记在同一 Buyer account 的 Agent Type 可读取该账号订单;未绑定设备不能借此获得 Buyer 权限。
23
+
24
+ ## 标准输出
25
+
26
+ ```json
27
+ {
28
+ "status": "delivered",
29
+ "result": {
30
+ "order_id": "<order_id>",
31
+ "order_code": "<IP-code>",
32
+ "amount": "<amount> <currency>",
33
+ "delivery_mode": "vault_artifact",
34
+ "access_locked": false,
35
+ "service_execution_id": "<service_execution_id>"
36
+ },
37
+ "instruction": "根据 delivery_mode 使用对应读取入口;不要从订单摘要猜测受保护内容。",
38
+ "next": {
39
+ "command": "itpay services next <service_execution_id> --json",
40
+ "reason": "读取交付状态"
41
+ },
42
+ "recovery": []
43
+ }
44
+ ```
45
+
46
+ `delivery_mode` 当前为 `agent_visible_result` 或 `vault_artifact`,由 Delivery Owner 的 binding 返回,不从商品名或服务 ID 推断。文本输出依次显示同一组字段、instruction 和 next。
47
+
48
+ 订单尚未交付时可以暂不包含 `delivery_mode` 和 `service_execution_id`,并只建议稍后重查同一订单。
49
+
50
+ ## 退款访问锁
51
+
52
+ 退款锁生效时,退款状态优先于交付入口:
53
+
54
+ ```json
55
+ {
56
+ "status": "delivered",
57
+ "result": {
58
+ "order_id": "<order_id>",
59
+ "order_code": "<IP-code>",
60
+ "amount": "<amount> <currency>",
61
+ "delivery_mode": "vault_artifact",
62
+ "access_locked": true,
63
+ "service_execution_id": "<service_execution_id>",
64
+ "refund": {
65
+ "refund_request_id": "<refund_request_id>",
66
+ "status": "accepted"
67
+ }
68
+ },
69
+ "instruction": "退款访问锁已生效;不要 reveal、创建 grant 或读取交付结果。",
70
+ "next": {
71
+ "command": "itpay refund get <refund_request_id> --json",
72
+ "reason": "读取退款的服务器状态"
73
+ },
74
+ "recovery": []
75
+ }
76
+ ```
77
+
78
+ 退款为 `succeeded` 等终态时 `next` 为 `null`;CLI 不恢复旧 grant,也不自行解除锁。
79
+
80
+ ## 异常处理
81
+
82
+ 不存在和不属于当前账号的订单都返回不透明 `not_found`。错误 instruction 要求核对当前账号/Agent 绑定,唯一恢复入口是:
83
+
84
+ ```text
85
+ itpay services list --json
86
+ ```
87
+
88
+ 不得通过 403/404 差异探测其他账号订单,也不得新建订单掩盖错误 ID。
89
+
90
+ ## Agent Type / Host
91
+
92
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 返回完全相同的订单事实、instruction 和 next。`order` 是状态读取命令,不构造二维码、Markdown handoff 或 Host renderer 数据。
@@ -0,0 +1,83 @@
1
+ # `itpay orders`
2
+
3
+ ## 范围与意义
4
+
5
+ 列出当前 account-scoped Buyer session 可见的订单摘要,用于恢复订单,不返回交付 payload。
6
+
7
+ **上游:** Buyer 登录并取得 account-scoped session。
8
+ **下游:** `order <id>`。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay orders [--limit <n>] [--status <status>] [--json]
14
+ ```
15
+
16
+ | 参数 | 默认 | 说明 |
17
+ |---|---:|---|
18
+ | `--limit` | `20` | 最大订单数。 |
19
+ | `--status` | 全部 | 可选:`pending_payment`、`paid`、`delivery_pending`、`delivered`、`failed`、`partially_refunded`、`refunded`、`cancelled`。 |
20
+ | `--json` | 否 | 标准 JSON。 |
21
+
22
+ `--limit` 必须是 `1..100` 的整数。命令固定使用最新优先排序,不暴露修改排序的参数。
23
+
24
+ ## 标准输出
25
+
26
+ ```json
27
+ {
28
+ "status": "listed",
29
+ "result": {
30
+ "orders": [
31
+ {
32
+ "order_id": "<id>",
33
+ "order_code": "<IP-code>",
34
+ "status": "<status>",
35
+ "amount": "<amount> <currency>",
36
+ "created_at": "<RFC3339>"
37
+ }
38
+ ]
39
+ },
40
+ "instruction": "选择目标订单后读取详情;不要假设列表第一笔就是当前任务。",
41
+ "next": { "command": "itpay order <order_id> --json", "reason": "读取所选订单" },
42
+ "recovery": []
43
+ }
44
+ ```
45
+
46
+ 订单列表不得包含 `checkout_id`、订单 items、交付 artifact、Vault ID 或交付 payload。无匹配订单时返回:
47
+
48
+ ```json
49
+ {
50
+ "status": "no_orders",
51
+ "result": { "orders": [] },
52
+ "instruction": "当前账号没有符合条件的订单;不要猜测订单 ID。",
53
+ "next": null,
54
+ "recovery": [
55
+ { "command": "itpay services list --json", "reason": "恢复当前 Agent 设备可见的执行" }
56
+ ]
57
+ }
58
+ ```
59
+
60
+ ## 异常处理
61
+
62
+ 结果按最新到最旧排列。缺少 Buyer session 时返回:
63
+
64
+ ```json
65
+ {
66
+ "status": "error",
67
+ "error": {
68
+ "code": "session_required",
69
+ "message": "account-scoped Buyer session is required"
70
+ },
71
+ "instruction": "订单历史只对网页登录账号开放;不要伪造 Buyer token。Agent 可改为恢复当前设备绑定的 Service Execution。",
72
+ "next": null,
73
+ "recovery": [
74
+ { "command": "itpay services list --json", "reason": "恢复当前 Agent 设备可见的执行" }
75
+ ]
76
+ }
77
+ ```
78
+
79
+ 无效 `--limit` 和 `--status` 必须在发起 HTTP 请求前返回 `limit_invalid` 或 `order_status_invalid`。Order-scoped session 返回服务端的 `account_scope_required`;CLI 不降级鉴权,也不要求 Agent 手工构造 Buyer token。
80
+
81
+ ## Agent Type / Host
82
+
83
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 行为相同;只允许展示格式差异。
@@ -0,0 +1,103 @@
1
+ # `itpay pay`
2
+
3
+ ## 范围与意义
4
+
5
+ 为一个已存在的 Checkout 显式创建或刷新 Payment Intent。它只用于 Checkout 页面无法完成渠道动作时的受控集成恢复,不是普通 Buyer 流程。
6
+
7
+ 本命令不能创建 Cart、Checkout、订单或付款证明,也不能把 Payment Intent 的渠道状态当作订单已付款。
8
+
9
+ **直接上游:** `buy`、`services checkout` 或 `checkout` 返回的同一组 `checkout_id` 与 display token。
10
+
11
+ **直接下游:** `checkout` 读取同一 Checkout 的权威付款、订单和履约状态。
12
+
13
+ ## 语法与参数
14
+
15
+ ```bash
16
+ itpay pay \
17
+ --checkout <checkout_id> \
18
+ --method <alipay|wechatpay> \
19
+ [--token <display_token>] \
20
+ [--refresh] \
21
+ [--host <host>] [--target <target>] [--json]
22
+ ```
23
+
24
+ | 参数 | 必填 | 规则 |
25
+ |---|---:|---|
26
+ | `--checkout` | 是 | 已存在的 Checkout ID。 |
27
+ | `--method` | 是 | 只接受 `alipay` 或 `wechatpay`;非法值不得回退为默认渠道。 |
28
+ | `--token` | 条件必填 | 必须属于同一 Checkout。省略时只可恢复本机为该 Checkout 保存的 token。 |
29
+ | `--refresh` | 否 | 为同一个非终态 Payment Intent 刷新渠道动作,不创建替代 Checkout。 |
30
+ | `--host` | 否 | 默认由 `--agent-type` 推导,只影响 instruction。 |
31
+ | `--target` | 条件必填 | 只有要求目标会话的 IM Host 需要。 |
32
+ | `--json` | 否 | 输出紧凑机器合同。 |
33
+
34
+ API 安全合同要求后端验证 display token 是该 Checkout 当前有效的 `checkout_entry` token。CLI 提交 token 不是安全边界;只有后端验证通过才允许创建或刷新 Payment Intent。
35
+
36
+ ## 标准输出
37
+
38
+ ### 渠道动作可用
39
+
40
+ ```json
41
+ {
42
+ "status": "payment_action_ready",
43
+ "result": {
44
+ "checkout_id": "<checkout_id>",
45
+ "payment_intent_id": "<payment_intent_id>",
46
+ "payment": "waiting_user_payment",
47
+ "amount": "<amount> <currency>"
48
+ },
49
+ "handoff": {
50
+ "qr_image_url": "<optional_provider_qr>",
51
+ "mobile_wallet_url": "<optional_wallet_action>"
52
+ },
53
+ "instruction": "<host_specific_escape_hatch_instruction>",
54
+ "next": {
55
+ "command": "itpay checkout --id <checkout_id> --token <display_token> --json",
56
+ "reason": "读取同一 Checkout 的权威付款状态"
57
+ },
58
+ "recovery": []
59
+ }
60
+ ```
61
+
62
+ 只返回 Agent 执行当前步骤所需的四个事实和安全渠道动作。不返回 Provider order ID、Payment Attempt、原始 Provider 响应、Checkout DTO 或重复 guidance。
63
+
64
+ ### 没有可展示动作
65
+
66
+ `requires_action` 但响应没有二维码或钱包链接时返回 `payment_action_pending`,不生成虚假 handoff;下一步仍读取同一 Checkout。
67
+
68
+ ### 已确认或终态
69
+
70
+ - `verified`、`partially_refunded` 返回 `payment_verified`,不再展示付款动作。
71
+ - `failed`、`expired`、`refunded` 返回 `payment_unavailable`,不创建替代 Checkout。
72
+ - 两者都只引导 `checkout --id ... --token ... --json` 读取服务端事实。
73
+
74
+ ## 重试与刷新
75
+
76
+ - 数据库以 `(checkout_id, payment_method_type)` 作为 Payment Intent 业务唯一键。
77
+ - 相同 Checkout 与 method 顺序重跑返回同一个非终态 Intent,不依赖客户端自报幂等键。
78
+ - `--refresh` 只更新该 Intent 的渠道动作;不能创建第二个 Intent 或 Checkout。
79
+ - 响应丢失时重跑同一命令,不换 token 或 method。
80
+
81
+ ## 异常处理
82
+
83
+ | 错误码 | Agent 处理 |
84
+ |---|---|
85
+ | `payment_method_invalid` | 改用 `alipay` 或 `wechatpay`;本次没有 HTTP 请求。 |
86
+ | `checkout_token_required` | 从 `itpay next --json` 恢复同一 Checkout;禁止拼接其他 token。 |
87
+ | `target_required` | 为当前 IM Host 补充真实 target。 |
88
+ | `not_found` / token invalid | 视为同一个不透明资源错误,不探测 Checkout 是否属于他人。 |
89
+ | `invalid_state` | 回到 `checkout` 读取当前终态,不创建替代资源。 |
90
+ | `provider_payment_failed` | 保留同一 Checkout,稍后恢复;不声称已付款。 |
91
+ | `payment_intent_failed` | 执行 `itpay next --json` 恢复现有句柄。 |
92
+
93
+ ## Agent Type / Host
94
+
95
+ | Agent Type | 默认 Host | Instruction |
96
+ |---|---|---|
97
+ | `codex-desktop` | `codex` | 把安全 handoff 实际发到当前 Codex 对话,然后查询 Checkout。 |
98
+ | `codex-cli` | `terminal` | 只在用户可见终端展示渠道动作。 |
99
+ | `claude-code-desktop` | `claude-code` | 把安全 handoff 发到当前桌面对话。 |
100
+ | `claude-code-cli` | `terminal` | 只在用户可见终端展示渠道动作。 |
101
+ | `workbuddy` | `plain-chat` | 把二维码或钱包链接发送到当前会话。 |
102
+
103
+ Host 只改变 instruction;Payment Intent ID、金额、状态、重试语义和权限必须一致。
@@ -0,0 +1,39 @@
1
+ # `itpay readyz`
2
+
3
+ ## 范围与意义
4
+
5
+ 检查当前配置的 ItPay API 是否可用。它只做环境诊断,不登记设备、不创建业务资源。
6
+
7
+ **上游:** CLI 安装和 Backend URL 配置。
8
+ **下游:** `catalog list` 或失败后的网络/配置修复。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay readyz [--json]
14
+ ```
15
+
16
+ | 参数 | 必填 | 说明 |
17
+ |---|---:|---|
18
+ | `--json` | 否 | 返回标准 JSON。 |
19
+
20
+ ## 标准输出
21
+
22
+ ```json
23
+ {
24
+ "status": "ready",
25
+ "result": { "backend": "available" },
26
+ "instruction": "ItPay 可用,可以读取服务目录。",
27
+ "next": { "command": "itpay catalog list", "reason": "发现可用服务" },
28
+ "recovery": []
29
+ }
30
+ ```
31
+
32
+ ## 异常处理
33
+
34
+ 连接失败时返回 `backend_unavailable`,要求核对 `ITPAY_BACKEND_URL` 后重试同一命令,不得继续下单。
35
+
36
+ ## Agent Type / Host
37
+
38
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 行为相同;本命令不渲染 Host 内容。
39
+
@@ -0,0 +1,62 @@
1
+ # `itpay refund cancel`
2
+
3
+ ## 范围与意义
4
+
5
+ 在 Refund Owner 允许时取消 active refund。取消成功后释放访问锁,但不复活旧 Agent grant。
6
+
7
+ **上游:** `refund get` 显示 `can_cancel=true`。
8
+ **下游:** `order` 或重新进行用户授权。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay refund cancel <refund_request_id> [--reason <reason>] [--json]
14
+ ```
15
+
16
+ `--reason` 默认 `buyer_cancelled`。
17
+
18
+ | 参数 | 必填 | 含义 |
19
+ | --- | --- | --- |
20
+ | `<refund_request_id>` | 是 | `refund create/get/watch` 返回的退款请求 ID |
21
+ | `--reason <reason>` | 否 | 取消原因;默认 `buyer_cancelled` |
22
+ | `--json` | 否 | 输出单个标准 JSON envelope |
23
+
24
+ 该命令使用当前设备的签名 Agent Device session。Refund Owner 会校验退款是否属于该设备已绑定的订单,并决定当前状态是否仍可取消;CLI 不自行释放访问锁。
25
+
26
+ ## 标准输出
27
+
28
+ ```json
29
+ {
30
+ "status": "cancelled",
31
+ "result": { "refund_request_id": "<id>", "order_id": "<order_id>", "access_locked": false },
32
+ "instruction": "退款已取消;如需交付,重新进入订单并取得新的授权。",
33
+ "next": { "command": "itpay order <order_id> --json", "reason": "确认订单访问状态" },
34
+ "recovery": []
35
+ }
36
+ ```
37
+
38
+ 不可取消时输出到 `stderr` 并以非零状态退出:
39
+
40
+ ```json
41
+ {
42
+ "status": "error",
43
+ "error": {
44
+ "code": "refund_cancellation_too_late",
45
+ "message": "refund cancellation is too late"
46
+ },
47
+ "instruction": "取消未生效;以 Refund Owner 当前状态为准,不要重复退款或自行解除交付锁。",
48
+ "next": null,
49
+ "recovery": [
50
+ {
51
+ "command": "itpay refund get <refund_request_id> --json",
52
+ "reason": "读取当前权威状态"
53
+ }
54
+ ]
55
+ }
56
+ ```
57
+
58
+ 出现 `not_found` 时同样只恢复到同一退款的 `refund get`,不借错误差异探测其他账号。取消成功只恢复重新申请交付授权的资格;旧 grant 永远不会复活。
59
+
60
+ ## Agent Type / Host
61
+
62
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种 Agent Type 的业务字段、instruction 和 recovery 相同;该命令没有二维码或宿主渲染差异。