From a859f0306abfe37b13ab67007c08e25f9a99d5e7 Mon Sep 17 00:00:00 2001 From: imeepos Date: Fri, 26 Sep 2025 15:32:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=99=A8=E9=85=8D=E7=BD=AE=E5=92=8C=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增BasePaymentAdapter配置状态管理 - 添加isConfigured属性跟踪配置状态 - 支持适配器配置验证机制 - 优化DouyinPaymentAdapter配置处理 - 配置缺失时警告而非抛异常,允许应用正常启动 - 在创建订单时检查配置状态并抛出友好错误 - 提升系统容错性和用户体验 --- src/payment/adapters/base-payment.adapter.ts | 1 + src/payment/adapters/douyin-payment.adapter.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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)) {