支付协议

This commit is contained in:
chen wei bo
2025-08-26 16:41:44 +08:00
parent 1c010f3f7c
commit b1537ea43a
3 changed files with 24 additions and 49 deletions
@@ -4,8 +4,7 @@
*/
import { PaymentApi } from "./PaymentApi";
import type { QueryOrderData } from "./types";
import { ApiCode } from "../network/client/types";
import proto from 'db://assets/Scripts/proto/proto.pb.js';
export interface PollOptions {
maxDurationMs: number; // 轮询总时长(例如 2分钟)
@@ -21,16 +20,17 @@ export class PaymentPoller {
cancel() { this.cancelled = true; }
// 轮询订单
async poll(orderId: string, opt: PollOptions, onTick?: (d: QueryOrderData) => void): Promise<QueryOrderData | null> {
async poll(orderId: string, opt: PollOptions, onTick?: (d: proto.cs.ICSQueryOrderRes) => void): Promise<proto.cs.ICSQueryOrderRes | null> {
const t0 = Date.now();
let interval = opt.startIntervalMs;
while (!this.cancelled) {
// 查询
const r = await PaymentApi.I.queryOrder(orderId);
if (r.code === ApiCode.OK && r.data) {
let reqData = {orderId: orderId};
const r = await PaymentApi.I.queryOrder(reqData);
if (r.code === proto.cs.EnmRetCode.SUCCESS && r.data) {
// 回调
onTick?.(r.data);
if (["SUCCESS", "FAILED", "CANCELED", "EXPIRED"].indexOf(r.data.status) !== -1) {
if ([-1, 0].indexOf(r.data.status) !== -1) {
return r.data;
}
}