fix: support legacy payment method aliases
This commit is contained in:
@@ -231,6 +231,11 @@ func getInstanceChannelLimits(inst *dbent.PaymentProviderInstance, paymentType P
|
||||
if cl, ok := limits[lookupKey]; ok {
|
||||
return cl
|
||||
}
|
||||
if aliasKey := legacyVisibleMethodAlias(lookupKey); aliasKey != "" {
|
||||
if cl, ok := limits[aliasKey]; ok {
|
||||
return cl
|
||||
}
|
||||
}
|
||||
return ChannelLimits{}
|
||||
}
|
||||
|
||||
@@ -321,14 +326,38 @@ func InstanceSupportsType(supportedTypes string, target PaymentType) bool {
|
||||
if supportedTypes == "" {
|
||||
return true
|
||||
}
|
||||
normalizedTarget := normalizeVisibleMethodSupportType(target)
|
||||
for _, t := range strings.Split(supportedTypes, ",") {
|
||||
if strings.TrimSpace(t) == target {
|
||||
supported := strings.TrimSpace(t)
|
||||
if supported == target || normalizeVisibleMethodSupportType(supported) == normalizedTarget {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func normalizeVisibleMethodSupportType(paymentType PaymentType) PaymentType {
|
||||
switch strings.TrimSpace(paymentType) {
|
||||
case TypeAlipay, TypeAlipayDirect:
|
||||
return TypeAlipay
|
||||
case TypeWxpay, TypeWxpayDirect:
|
||||
return TypeWxpay
|
||||
default:
|
||||
return strings.TrimSpace(paymentType)
|
||||
}
|
||||
}
|
||||
|
||||
func legacyVisibleMethodAlias(paymentType PaymentType) PaymentType {
|
||||
switch normalizeVisibleMethodSupportType(paymentType) {
|
||||
case TypeAlipay:
|
||||
return TypeAlipayDirect
|
||||
case TypeWxpay:
|
||||
return TypeWxpayDirect
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// GetInstanceConfig decrypts and returns the configuration for a provider instance by ID.
|
||||
func (lb *DefaultLoadBalancer) GetInstanceConfig(ctx context.Context, instanceID int64) (map[string]string, error) {
|
||||
inst, err := lb.db.PaymentProviderInstance.Get(ctx, instanceID)
|
||||
|
||||
Reference in New Issue
Block a user