优化结构

This commit is contained in:
Yvan
2026-08-22 15:53:14 +08:00
parent ca52de5db0
commit 491ed21d48
72 changed files with 746 additions and 695 deletions
+22 -22
View File
@@ -3,52 +3,52 @@ package payment
import (
"context"
"fmt"
"kra/internal/biz/system"
bizpayment "kra/internal/biz/payment"
)
// Adapter is the provider boundary used by the payment repository. Provider
// SDK types stay in this package and are normalized to biz.PaymentResult.
// SDK types stay in this package and are normalized to biz/payment results.
type Adapter interface {
Create(context.Context, *system.PaymentRequest, map[string]any) (*system.PaymentResult, error)
Query(context.Context, string, map[string]any) (*system.PaymentResult, error)
Refund(context.Context, *system.PaymentRefundRequest, map[string]any) (*system.PaymentResult, error)
Callback(context.Context, *system.PaymentCallback, map[string]any) (*system.PaymentResult, error)
Create(context.Context, *bizpayment.PaymentRequest, map[string]any) (*bizpayment.PaymentResult, error)
Query(context.Context, string, map[string]any) (*bizpayment.PaymentResult, error)
Refund(context.Context, *bizpayment.PaymentRefundRequest, map[string]any) (*bizpayment.PaymentResult, error)
Callback(context.Context, *bizpayment.PaymentCallback, map[string]any) (*bizpayment.PaymentResult, error)
}
// New constructs the SDK-backed adapter for a configured provider.
func New(provider string) (Adapter, error) {
switch provider {
case system.PaymentAlipay:
case bizpayment.PaymentAlipay:
return &alipayAdapter{}, nil
case system.PaymentAlipayV3:
case bizpayment.PaymentAlipayV3:
return &alipayV3Adapter{}, nil
case system.PaymentWechatV2:
case bizpayment.PaymentWechatV2:
return &wechatV2Adapter{}, nil
case system.PaymentWechatV3:
case bizpayment.PaymentWechatV3:
return &wechatV3Adapter{}, nil
case system.PaymentApple:
case bizpayment.PaymentApple:
return &appleAdapter{}, nil
case system.PaymentDouyin:
case bizpayment.PaymentDouyin:
return &douyinAdapter{}, nil
case system.PaymentQQ:
case bizpayment.PaymentQQ:
return &qqAdapter{}, nil
case system.PaymentAllinPay:
case bizpayment.PaymentAllinPay:
return &allinpayAdapter{}, nil
case system.PaymentLakala:
case bizpayment.PaymentLakala:
return &lakalaAdapter{}, nil
case system.PaymentPayPal:
case bizpayment.PaymentPayPal:
return &paypalAdapter{}, nil
case system.PaymentSaobei:
case bizpayment.PaymentSaobei:
return &saobeiAdapter{}, nil
case system.PaymentChinaums:
case bizpayment.PaymentChinaums:
return newVendorAdapter(provider, vendorChinaums), nil
case system.PaymentSFT:
case bizpayment.PaymentSFT:
return newVendorAdapter(provider, vendorSFT), nil
case system.PaymentSuperPay:
case bizpayment.PaymentSuperPay:
return newVendorAdapter(provider, vendorSupperPay), nil
case system.PaymentWechatGame:
case bizpayment.PaymentWechatGame:
return newVendorAdapter(provider, vendorWechatGame), nil
case system.PaymentDouyinGame:
case bizpayment.PaymentDouyinGame:
return newVendorAdapter(provider, vendorDouyinGame), nil
default:
return nil, fmt.Errorf("支付渠道 %s 没有适配器", provider)