diff --git a/src/payment/adapters/base-payment.adapter.ts b/src/payment/adapters/base-payment.adapter.ts index 493ea4e..b714714 100644 --- a/src/payment/adapters/base-payment.adapter.ts +++ b/src/payment/adapters/base-payment.adapter.ts @@ -38,6 +38,7 @@ import { @Injectable() export abstract class BasePaymentAdapter implements IPaymentAdapter { protected readonly logger = new Logger(this.constructor.name); + protected isConfigured: boolean = false; abstract platform: PlatformType; abstract paymentMethod: PaymentMethod; diff --git a/src/payment/adapters/douyin-payment.adapter.ts b/src/payment/adapters/douyin-payment.adapter.ts index 7487400..874fe86 100644 --- a/src/payment/adapters/douyin-payment.adapter.ts +++ b/src/payment/adapters/douyin-payment.adapter.ts @@ -100,9 +100,13 @@ export class DouyinPaymentAdapter extends BasePaymentAdapter { !this.privateKey ) { const message = '抖音支付配置不完整,相关功能将不可用。请配置环境变量: DOUYIN_MINIPROGRAM_APPID, DOUYIN_MINIPROGRAM_SECRET, DOUYIN_MERCHANT_ID, DOUYIN_PRIVATE_KEY'; - this.logger.error(message); - throw new ConfigurationException(message, 'DOUYIN_PAYMENT_CONFIG'); + this.logger.warn(message); + // 不抛出异常,允许应用正常启动,但标记为未配置状态 + this.isConfigured = false; + return; } + + this.isConfigured = true; } /** @@ -114,6 +118,10 @@ export class DouyinPaymentAdapter extends BasePaymentAdapter { async createPaymentOrder( orderData: CreatePaymentOrderData, ): Promise { + if (!this.isConfigured) { + throw new PaymentException('抖音支付未正确配置', undefined, 'PAYMENT_NOT_CONFIGURED'); + } + try { // 1. 参数验证 if (!this.validateAmount(orderData.amount)) {