Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
6f00efa3
Commit
6f00efa3
authored
Apr 20, 2026
by
IanShaw027
Browse files
fix: support legacy payment method aliases
parent
e1a28848
Changes
2
Show whitespace changes
Inline
Side-by-side
backend/internal/payment/load_balancer.go
View file @
6f00efa3
...
...
@@ -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
)
...
...
backend/internal/payment/load_balancer_test.go
View file @
6f00efa3
...
...
@@ -68,10 +68,16 @@ func TestInstanceSupportsType(t *testing.T) {
expected
:
true
,
},
{
name
:
"
partial match should not succee
d"
,
name
:
"
legacy alipay direct supports canonical visible metho
d"
,
supportedTypes
:
"alipay_direct"
,
target
:
"alipay"
,
expected
:
false
,
expected
:
true
,
},
{
name
:
"legacy wxpay direct supports canonical visible method"
,
supportedTypes
:
"wxpay_direct"
,
target
:
"wxpay"
,
expected
:
true
,
},
{
name
:
"empty supported types means all supported"
,
...
...
@@ -92,6 +98,22 @@ func TestInstanceSupportsType(t *testing.T) {
}
}
func
TestGetInstanceChannelLimitsFallsBackToLegacyDirectAliases
(
t
*
testing
.
T
)
{
t
.
Parallel
()
inst
:=
testInstance
(
1
,
TypeAlipay
,
makeLimitsJSON
(
TypeAlipayDirect
,
ChannelLimits
{
SingleMax
:
66
}))
got
:=
getInstanceChannelLimits
(
inst
,
TypeAlipay
)
if
got
.
SingleMax
!=
66
{
t
.
Fatalf
(
"getInstanceChannelLimits() = %+v, want SingleMax=66"
,
got
)
}
wxInst
:=
testInstance
(
2
,
TypeWxpay
,
makeLimitsJSON
(
TypeWxpayDirect
,
ChannelLimits
{
SingleMin
:
8
}))
wxGot
:=
getInstanceChannelLimits
(
wxInst
,
TypeWxpay
)
if
wxGot
.
SingleMin
!=
8
{
t
.
Fatalf
(
"getInstanceChannelLimits() = %+v, want SingleMin=8"
,
wxGot
)
}
}
// ---------------------------------------------------------------------------
// Helper to build test PaymentProviderInstance values
// ---------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment