feat: 更新支付模块 (Stripe/PayPal/PingPong) 和 uni-app 配置
This commit is contained in:
@@ -35,14 +35,29 @@ GATEWAY_MAP: Dict[str, PaymentGateway] = {}
|
||||
def init_gateways():
|
||||
if settings.PAY_API_KEY:
|
||||
GATEWAY_MAP["unified"] = UnifiedPayService()
|
||||
if settings.STRIPE_SECRET_KEY:
|
||||
from app.services.stripe_pay import StripePaymentService
|
||||
GATEWAY_MAP["stripe"] = StripePaymentService()
|
||||
if settings.PAYPAL_CLIENT_ID and settings.PAYPAL_CLIENT_SECRET:
|
||||
from app.services.paypal_pay import PayPalPaymentService
|
||||
GATEWAY_MAP["paypal"] = PayPalPaymentService()
|
||||
if settings.PINGPONG_CLIENT_ID and settings.PINGPONG_ACC_ID and settings.PINGPONG_SECRET_KEY:
|
||||
from app.services.pingpong_pay import PingPongCheckoutService
|
||||
GATEWAY_MAP["pingpong"] = PingPongCheckoutService()
|
||||
|
||||
|
||||
def get_gateway(pay_type: str) -> PaymentGateway:
|
||||
gw = GATEWAY_MAP.get("unified")
|
||||
if pay_type in ("card", "stripe", "alipay_stripe", "wechat_stripe"):
|
||||
gw = GATEWAY_MAP.get("stripe") or gw
|
||||
if pay_type in ("paypal",):
|
||||
gw = GATEWAY_MAP.get("paypal") or gw
|
||||
if pay_type in ("pingpong",):
|
||||
gw = GATEWAY_MAP.get("pingpong") or gw
|
||||
if not gw:
|
||||
raise ValueError("支付网关未配置,请设置 PAY_API_KEY")
|
||||
raise ValueError("支付网关未配置,请设置 PAY_API_KEY / STRIPE_SECRET_KEY / PAYPAL_CLIENT_ID / PINGPONG 配置")
|
||||
if not gw.supports(pay_type):
|
||||
raise ValueError(f"支付方式 {pay_type} 不被支持(仅支持 alipay/wechat)")
|
||||
raise ValueError(f"支付方式 {pay_type} 不被支持")
|
||||
return gw
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user