新增支付流程 LuffaPayFlow

This commit is contained in:
chen wei bo
2025-09-28 14:16:37 +08:00
parent 66ba9dbc67
commit 303003b550
6 changed files with 78 additions and 12 deletions
@@ -9,29 +9,30 @@ import PaymentPoller from "./PaymentPoller";
import { PaymentFlow } from "./PaymentFlow";
import { CashInrFlow } from "./CashInrFlow";
import { WebUsdFlow } from "./WebUsdFlow";
import { LuffaPayFlow } from "./LuffaPayFlow";
import proto from 'db://assets/Scripts/proto/proto.pb.js';
import { DataManager, DataId } from "db://assets/Scripts/chat18x/data/DataManager";
import { OrderData } from "db://assets/Scripts/chat18x/data/OrderData";
import Utils from "../../Main/Common/Utils";
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
import { PaymentMethod } from './types';
export class PaymentService {
private static _I: PaymentService | null = null;
static get I() { return this._I ?? (this._I = new PaymentService()); }
/** 策略表 */
private flowMap: Record<number, PaymentFlow> = {};
private flowMap: Map<PaymentMethod, PaymentFlow>;
private constructor() {
this.flowMap = {};
let num1 = proto.cs.EnmPayType.EPT_Cash_INR;
this.flowMap[num1] = new CashInrFlow(this.waitAppResumeIfNeeded.bind(this));
let num2 = proto.cs.EnmPayType.EPT_WEB3_USD;
this.flowMap[num2] = new WebUsdFlow(5000);
this.flowMap = new Map<PaymentMethod, PaymentFlow>();
this.flowMap.set(PaymentMethod.CashPay, new CashInrFlow(this.waitAppResumeIfNeeded.bind(this)));
this.flowMap.set(PaymentMethod.Web3, new WebUsdFlow(5000));
this.flowMap.set(PaymentMethod.Luffa, new LuffaPayFlow(5000));
}
/** 发起支付:创建订单→打开URL→回到App后开始轮询 */
async startPayment(req: proto.cs.ICSCreateOrderReq, open: OpenStrategy = "system"): Promise<proto.cs.ICSQueryOrderRes> {
async startPayment(payMethod: PaymentMethod, req: proto.cs.ICSCreateOrderReq, open: OpenStrategy = "system"): Promise<proto.cs.ICSQueryOrderRes> {
// 下单
logger.log("创建订单的请求数据:", req);
const create = await PaymentApi.I.createOrder(req);
@@ -49,7 +50,7 @@ export class PaymentService {
Utils.sendInnerMsg(InnerMsgCode.PayOrderCreateSucc, { orderId: orderId, payType: req.payType,goodId:req.goodId });
// 分发流程
const flow = this.flowMap[req.payType];
const flow = this.flowMap.get(payMethod);
return flow?.run(orderId, payUrl, open) ?? null;
}