支付协议修改

This commit is contained in:
chen wei bo
2025-09-18 18:28:28 +08:00
parent 3325b28769
commit b6b702d0dd
8 changed files with 213 additions and 24 deletions
@@ -0,0 +1,45 @@
/**
* web3 USD 支付流程
*
*/
import PaymentPoller from "./PaymentPoller";
import type { PaymentFlow } from "./PaymentFlow";
import type proto from "db://assets/Scripts/proto/proto.pb.js";
import { type OpenStrategy } from "./PaymentOpener";
import { DataManager, DataId } from "db://assets/Scripts/chat18x/data/DataManager";
import { OrderData } from "db://assets/Scripts/chat18x/data/OrderData";
export class WebUsdFlow implements PaymentFlow {
constructor(private delayMs: number = 5000) {}
async run(orderId: string, _payUrl: string, _open: OpenStrategy): Promise<proto.cs.ICSQueryOrderRes | null> {
// 延时
await this.delay(this.delayMs);
// 开始轮询
const data = await this.pollOrder(orderId);
// 刷新订单数据
const orderData = DataManager.I.getDataById<OrderData>(DataId.Order);
orderData.applyQueryOrder(orderId, data);
// 返回结果
return data;
}
async resume(orderId: string, _payUrl: string): Promise<proto.cs.ICSQueryOrderRes | null> {
// 直接轮询(也可以选择先 delay 一下再 poll,看业务需求)
return this.pollOrder(orderId);
}
private async pollOrder(orderId: string) {
const poller = new PaymentPoller();
return poller.poll(orderId, {
maxDurationMs: 2 * 60 * 1000,
startIntervalMs: 2000,
maxIntervalMs: 10000,
jitter: true,
}, (d) => console.log());
}
private delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
}