57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
package payment
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"kra/internal/biz/system"
|
|
)
|
|
|
|
// Adapter is the provider boundary used by the payment repository. Provider
|
|
// SDK types stay in this package and are normalized to biz.PaymentResult.
|
|
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)
|
|
}
|
|
|
|
// New constructs the SDK-backed adapter for a configured provider.
|
|
func New(provider string) (Adapter, error) {
|
|
switch provider {
|
|
case system.PaymentAlipay:
|
|
return &alipayAdapter{}, nil
|
|
case system.PaymentAlipayV3:
|
|
return &alipayV3Adapter{}, nil
|
|
case system.PaymentWechatV2:
|
|
return &wechatV2Adapter{}, nil
|
|
case system.PaymentWechatV3:
|
|
return &wechatV3Adapter{}, nil
|
|
case system.PaymentApple:
|
|
return &appleAdapter{}, nil
|
|
case system.PaymentDouyin:
|
|
return &douyinAdapter{}, nil
|
|
case system.PaymentQQ:
|
|
return &qqAdapter{}, nil
|
|
case system.PaymentAllinPay:
|
|
return &allinpayAdapter{}, nil
|
|
case system.PaymentLakala:
|
|
return &lakalaAdapter{}, nil
|
|
case system.PaymentPayPal:
|
|
return &paypalAdapter{}, nil
|
|
case system.PaymentSaobei:
|
|
return &saobeiAdapter{}, nil
|
|
case system.PaymentChinaums:
|
|
return newVendorAdapter(provider, vendorChinaums), nil
|
|
case system.PaymentSFT:
|
|
return newVendorAdapter(provider, vendorSFT), nil
|
|
case system.PaymentSuperPay:
|
|
return newVendorAdapter(provider, vendorSupperPay), nil
|
|
case system.PaymentWechatGame:
|
|
return newVendorAdapter(provider, vendorWechatGame), nil
|
|
case system.PaymentDouyinGame:
|
|
return newVendorAdapter(provider, vendorDouyinGame), nil
|
|
default:
|
|
return nil, fmt.Errorf("支付渠道 %s 没有适配器", provider)
|
|
}
|
|
}
|