@tbox.cn/app-module-ai-payment 0.1.2 → 0.1.3
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.
- package/README.md +1 -1
- package/dist/{chunk-ERHTVWF5.js → chunk-3NXYT4XA.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/package.json +1 -1
- package/src/server/config.ts +2 -1
- package/tbox.module.json +1 -1
- package/tests/ai-payment.test.ts +13 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ createPaymentOrder 只准备待支付卡与已有买家身份,不发起真实
|
|
|
10
10
|
|
|
11
11
|
## 服务端配置
|
|
12
12
|
|
|
13
|
-
统一读取应用根目录下 config/kya.json 的非空字符串 kyaid;文件不可读取、JSON 无效或字段无效时使用默认 agentId `2026000116664809`,不区分环境。买家身份不区分环境:优先使用已有非匿名身份中的有效 `2088` 数字 ID,否则兜底为测试账号 `2088052281674865`。AI_PAY_AGENT_PID 为收款商家 PID
|
|
13
|
+
统一读取应用根目录下 config/kya.json 的非空字符串 kyaid;文件不可读取、JSON 无效或字段无效时使用默认 agentId `2026000116664809`,不区分环境。买家身份不区分环境:优先使用已有非匿名身份中的有效 `2088` 数字 ID,否则兜底为测试账号 `2088052281674865`。AI_PAY_AGENT_PID 为收款商家 PID,优先使用环境变量的非空值,未配置或为空白时使用体验商家 `2088051636299393`,与卡片已有的买家身份分开。真实场景请在平台环境变量中配置 AI_PAY_AGENT_PID,默认 PID 仅供体验。
|
|
14
14
|
|
|
15
15
|
配置在工具执行期读取,从当前工作目录沿 .tbox/app.json 标记定位生成应用根目录(兼容 apps/server 启动)。商家 PID 缺失时 Web 仍可模拟,端内支付明确拒绝。
|
|
16
16
|
|
|
@@ -59,7 +59,7 @@ async function loadPaymentConfig(options = {}) {
|
|
|
59
59
|
if (typeof id === "string" && id.trim()) agentId = id.trim();
|
|
60
60
|
} catch {
|
|
61
61
|
}
|
|
62
|
-
const agentPid = env.AI_PAY_AGENT_PID?.trim();
|
|
62
|
+
const agentPid = env.AI_PAY_AGENT_PID?.trim() || "2088051636299393";
|
|
63
63
|
return { ...agentPid ? { bizContext: JSON.stringify({ cashierScene: "agentPay", agentPid, agentId }) } : {} };
|
|
64
64
|
}
|
|
65
65
|
|
package/dist/index.js
CHANGED
package/dist/server/index.js
CHANGED
package/package.json
CHANGED
package/src/server/config.ts
CHANGED
|
@@ -21,6 +21,7 @@ export async function loadPaymentConfig(options: { env?: NodeJS.ProcessEnv; appD
|
|
|
21
21
|
const id = (config as { kyaid?: unknown } | null)?.kyaid;
|
|
22
22
|
if (typeof id === 'string' && id.trim()) agentId = id.trim();
|
|
23
23
|
} catch { /* 配置不可读取时使用默认智能体标识 */ }
|
|
24
|
-
|
|
24
|
+
// TODO:真实场景下请在平台环境变量中配置 AI_PAY_AGENT_PID,当前 PID 只做体验使用。
|
|
25
|
+
const agentPid = env.AI_PAY_AGENT_PID?.trim() || '2088051636299393';
|
|
25
26
|
return { ...(agentPid ? { bizContext: JSON.stringify({ cashierScene: 'agentPay', agentPid, agentId }) } : {}) };
|
|
26
27
|
}
|
package/tbox.module.json
CHANGED
package/tests/ai-payment.test.ts
CHANGED
|
@@ -42,6 +42,19 @@ describe('体验商品准备', () => {
|
|
|
42
42
|
}
|
|
43
43
|
} finally { await rm(appDir, { recursive: true }); }
|
|
44
44
|
});
|
|
45
|
+
it('商家 PID 优先环境变量,缺失或空白时使用体验商家', async () => {
|
|
46
|
+
const appDir = await mkdtemp(join(tmpdir(), 'payment-merchant-'));
|
|
47
|
+
try {
|
|
48
|
+
for (const value of [undefined, '', ' ', ' 2088000000000001 ']) {
|
|
49
|
+
const out = await loadPaymentConfig({ appDir, env: { AI_PAY_AGENT_PID: value } });
|
|
50
|
+
expect(JSON.parse(out.bizContext!)).toEqual({
|
|
51
|
+
cashierScene: 'agentPay',
|
|
52
|
+
agentPid: value?.trim() || '2088051636299393',
|
|
53
|
+
agentId: '2026000116664809',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
} finally { await rm(appDir, { recursive: true }); }
|
|
57
|
+
});
|
|
45
58
|
it('文件缺失、JSON 损坏或字段无效时使用默认 ID', async () => {
|
|
46
59
|
const appDir = await mkdtemp(join(tmpdir(), 'payment-fallback-'));
|
|
47
60
|
try {
|