webadmin系统设置
This commit is contained in:
@@ -4,10 +4,8 @@ import type { IPayProvider, PayOrderResult } from './pay.interface';
|
||||
|
||||
@Injectable()
|
||||
export class PayMockProvider implements IPayProvider {
|
||||
private readonly config = loadAppConfig();
|
||||
|
||||
async payOrder(_orderId: bigint, _openId?: string): Promise<PayOrderResult> {
|
||||
if (!this.config.mockPay) {
|
||||
if (!loadAppConfig().mockPay) {
|
||||
throw new Error('Real WeChat pay requires PayWechatProvider');
|
||||
}
|
||||
return { mode: 'mock', externalNo: `MOCK-${Date.now()}` };
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { loadAppConfig } from '@dukang/shared-types';
|
||||
import type { IPayProvider, PayOrderResult } from './pay.interface';
|
||||
import { PayMockProvider } from './pay.mock.provider';
|
||||
import { PayWechatProvider } from './pay.wechat.provider';
|
||||
|
||||
/** 按当前 process.env 动态选择 Mock / 微信 JSAPI 支付 */
|
||||
@Injectable()
|
||||
export class PayRouterProvider implements IPayProvider {
|
||||
constructor(
|
||||
private readonly mock: PayMockProvider,
|
||||
private readonly wechat: PayWechatProvider,
|
||||
) {}
|
||||
|
||||
private resolve(): IPayProvider {
|
||||
return loadAppConfig().mockPay ? this.mock : this.wechat;
|
||||
}
|
||||
|
||||
payOrder(orderId: bigint, openId?: string): Promise<PayOrderResult> {
|
||||
return this.resolve().payOrder(orderId, openId);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import type { IPayProvider, PayOrderResult } from './pay.interface';
|
||||
@Injectable()
|
||||
export class PayWechatProvider implements IPayProvider {
|
||||
private readonly logger = new Logger(PayWechatProvider.name);
|
||||
private readonly config = loadAppConfig();
|
||||
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
@@ -16,11 +15,11 @@ export class PayWechatProvider implements IPayProvider {
|
||||
) {}
|
||||
|
||||
async payOrder(orderId: bigint, openId?: string): Promise<PayOrderResult> {
|
||||
if (this.config.mockPay) {
|
||||
if (loadAppConfig().mockPay) {
|
||||
return { mode: 'mock', externalNo: `MOCK-${Date.now()}` };
|
||||
}
|
||||
if (!this.wechat.isPayEnabled()) {
|
||||
throw new Error('微信支付未配置:请设置 WECHAT_PAY_ENABLED=true 与 WX_MCH_ID 等商户参数');
|
||||
throw new Error('微信支付未配置:请关闭 MOCK_PAY 并配置 WX_MCH_ID 等商户参数');
|
||||
}
|
||||
if (!openId) {
|
||||
throw new Error('微信支付需要用户 openId,请先完成微信授权登录');
|
||||
|
||||
Reference in New Issue
Block a user