Files
gitlab-instance-0a899031_pa…/app/payment/factory.py
2026-03-08 01:24:59 -06:00

40 lines
1018 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
支付渠道工厂
根据配置返回对应的支付 Provider
"""
from ..config import (
PAYMENT_PROVIDER,
XORPAY_AID,
XORPAY_SECRET,
XORPAY_CASHIER_URL,
ZPAY_PID,
ZPAY_KEY,
)
from .base import PaymentProvider
from .xorpay import XorPayProvider
from .zpay import ZPayProvider
_provider_instance: PaymentProvider | None = None
def get_payment_provider() -> PaymentProvider:
"""获取当前配置的支付渠道实例(单例)"""
global _provider_instance
if _provider_instance is not None:
return _provider_instance
if PAYMENT_PROVIDER == "zpay":
_provider_instance = ZPayProvider(pid=ZPAY_PID, key=ZPAY_KEY)
else:
_provider_instance = XorPayProvider(
aid=XORPAY_AID,
secret=XORPAY_SECRET,
cashier_url=XORPAY_CASHIER_URL,
)
return _provider_instance
def reset_provider():
"""重置 Provider用于测试或切换渠道"""
global _provider_instance
_provider_instance = None