@tbox.cn/app-module-ai-payment 0.1.1 → 0.1.2
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/dist/client/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import "../ai-payment-PNOA2J6W.css";
|
|
|
3
3
|
|
|
4
4
|
// src/client/cards/payment-order/index.tsx
|
|
5
5
|
import { useEffect, useRef, useState } from "react";
|
|
6
|
-
import { callJsapi, isInAlipayShell, mapPaymentResultCode, markSelfRendering, sendCardAction } from "@tbox.cn/app-agent-sdk-client";
|
|
6
|
+
import { callJsapi, createClientLogger, isInAlipayShell, mapPaymentResultCode, markSelfRendering, sendCardAction } from "@tbox.cn/app-agent-sdk-client";
|
|
7
7
|
|
|
8
8
|
// src/client/payment.ts
|
|
9
9
|
import { callCapability } from "@tbox.cn/app-agent-sdk-client";
|
|
@@ -23,6 +23,7 @@ async function createPaymentOrder(buyerId) {
|
|
|
23
23
|
|
|
24
24
|
// src/client/cards/payment-order/index.tsx
|
|
25
25
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
26
|
+
var logger = createClientLogger("AI-PAYMENT");
|
|
26
27
|
function PaymentOrderCard(props) {
|
|
27
28
|
const { data, cardId, isHistory, actionTokens } = props;
|
|
28
29
|
const [pending, setPending] = useState(false);
|
|
@@ -62,7 +63,7 @@ function PaymentOrderCard(props) {
|
|
|
62
63
|
tradeNo.current = order.tradeNo;
|
|
63
64
|
}
|
|
64
65
|
const result = await callJsapi("tradePay", { tradeNO: tradeNo.current, bizContext: data.bizContext });
|
|
65
|
-
|
|
66
|
+
logger.info("tradePay result:", result);
|
|
66
67
|
const status = mapPaymentResultCode(result?.resultCode);
|
|
67
68
|
if (status === "failure") {
|
|
68
69
|
sendCardAction(cardId, { type: "toast", content: "\u652F\u4ED8\u7ED3\u679C\u672A\u786E\u8BA4\uFF0C\u8BF7\u52FF\u91CD\u590D\u4E0B\u5355", tone: "error" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { callJsapi, isInAlipayShell, mapPaymentResultCode, markSelfRendering, sendCardAction } from '@tbox.cn/app-agent-sdk-client';
|
|
2
|
+
import { callJsapi, createClientLogger, isInAlipayShell, mapPaymentResultCode, markSelfRendering, sendCardAction } from '@tbox.cn/app-agent-sdk-client';
|
|
3
3
|
import { createPaymentOrder } from '../../payment';
|
|
4
|
+
|
|
5
|
+
const logger = createClientLogger('AI-PAYMENT');
|
|
4
6
|
import type { PaymentOrderCardData } from '../../../server/contracts';
|
|
5
7
|
|
|
6
8
|
export function PaymentOrderCard(props: { data: PaymentOrderCardData; cardId: string; isHistory: boolean; actionTokens?: Record<string, string> }) {
|
|
@@ -39,7 +41,7 @@ export function PaymentOrderCard(props: { data: PaymentOrderCardData; cardId: st
|
|
|
39
41
|
tradeNo.current = order.tradeNo;
|
|
40
42
|
}
|
|
41
43
|
const result = await callJsapi<{ resultCode?: string }>('tradePay', { tradeNO: tradeNo.current, bizContext: data.bizContext });
|
|
42
|
-
|
|
44
|
+
logger.info('tradePay result:', result);
|
|
43
45
|
const status = mapPaymentResultCode(result?.resultCode);
|
|
44
46
|
if (status === 'failure') {
|
|
45
47
|
sendCardAction(cardId, { type: 'toast', content: '支付结果未确认,请勿重复下单', tone: 'error' });
|
package/tbox.module.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import React, { act } from 'react';
|
|
3
3
|
import { createRoot } from 'react-dom/client';
|
|
4
4
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
-
vi.mock('@tbox.cn/app-agent-sdk-client', () => ({ callCapability: vi.fn(), callJsapi: vi.fn(), isInAlipayShell: vi.fn(), mapPaymentResultCode: (code: string) => code === '9000' ? 'success' : code === '6001' ? 'cancel' : 'failure', markSelfRendering: (c: unknown) => c, sendCardAction: vi.fn() }));
|
|
5
|
+
vi.mock('@tbox.cn/app-agent-sdk-client', () => ({ callCapability: vi.fn(), callJsapi: vi.fn(), createClientLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }), isInAlipayShell: vi.fn(), mapPaymentResultCode: (code: string) => code === '9000' ? 'success' : code === '6001' ? 'cancel' : 'failure', markSelfRendering: (c: unknown) => c, sendCardAction: vi.fn() }));
|
|
6
6
|
import { callCapability, callJsapi, isInAlipayShell, sendCardAction } from '@tbox.cn/app-agent-sdk-client';
|
|
7
7
|
import { PaymentOrderCard } from '../src/client/cards/payment-order';
|
|
8
8
|
(globalThis as Record<string, unknown>).IS_REACT_ACT_ENVIRONMENT = true;
|