fix(payment): allow periods in EasyPay upstream types

This commit is contained in:
chihao.ou
2026-09-11 14:51:34 +08:00
parent 9c30951e4a
commit c3b3072a6f
7 changed files with 37 additions and 15 deletions
@@ -202,7 +202,7 @@ func TestEasyPayCustomMethodsUseConfiguredUpstreamType(t *testing.T) {
"notifyUrl": "https://example.com/notify",
"returnUrl": "https://example.com/return",
"paymentMode": paymentModePopup,
"customMethods": `[{"type":"ldc","upstreamType":"epay","displayName":"LDC"},{"type":"usdt_trc20","upstreamType":"usdt","displayName":"USDT-TRC20"}]`,
"customMethods": `[{"type":"ldc","upstreamType":"epay","displayName":"LDC"},{"type":"usdt_trc20","upstreamType":"usdt.trc20","displayName":"USDT-TRC20"}]`,
})
if err != nil {
t.Fatalf("NewEasyPay: %v", err)
@@ -221,8 +221,8 @@ func TestEasyPayCustomMethodsUseConfiguredUpstreamType(t *testing.T) {
if err != nil {
t.Fatalf("parse pay url: %v", err)
}
if got := payURL.Query().Get("type"); got != "usdt" {
t.Fatalf("pay url type = %q, want usdt (%s)", got, resp.PayURL)
if got := payURL.Query().Get("type"); got != "usdt.trc20" {
t.Fatalf("pay url type = %q, want usdt.trc20 (%s)", got, resp.PayURL)
}
}
@@ -224,6 +224,7 @@ func validateProviderRequest(providerKey, name, supportedTypes string) error {
}
var easyPayCustomMethodCodePattern = regexp.MustCompile(`^[a-z0-9_-]+$`)
var easyPayUpstreamMethodCodePattern = regexp.MustCompile(`^[a-z0-9_.-]+$`)
type easyPayCustomMethodConfig struct {
Type string `json:"type"`
@@ -253,8 +254,8 @@ func validateEasyPayCustomMethods(config map[string]string, supportedTypes strin
if !easyPayCustomMethodCodePattern.MatchString(method.Type) {
return infraerrors.BadRequest("VALIDATION_ERROR", "customMethods type may only contain lowercase letters, digits, underscores, and hyphens")
}
if !easyPayCustomMethodCodePattern.MatchString(method.UpstreamType) {
return infraerrors.BadRequest("VALIDATION_ERROR", "customMethods upstreamType may only contain lowercase letters, digits, underscores, and hyphens")
if !easyPayUpstreamMethodCodePattern.MatchString(method.UpstreamType) {
return infraerrors.BadRequest("VALIDATION_ERROR", "customMethods upstreamType may only contain lowercase letters, digits, periods, underscores, and hyphens")
}
if easyPayCustomMethodTypeConflictsWithBuiltin(method.Type) {
return infraerrors.BadRequest("VALIDATION_ERROR", "customMethods type cannot start with alipay or wxpay")
@@ -128,6 +128,23 @@ func TestValidateEasyPayCustomMethods(t *testing.T) {
config: map[string]string{"customMethods": `[{"type":"ldc","upstreamType":"epay","displayName":"LDC"}]`},
supportedTypes: "alipay,wxpay,ldc",
},
{
name: "upstream type allows periods",
config: map[string]string{"customMethods": `[{"type":"usdt_trc20","upstreamType":"usdt.trc20"}]`},
supportedTypes: "alipay,wxpay,usdt_trc20",
},
{
name: "custom type still rejects periods",
config: map[string]string{"customMethods": `[{"type":"usdt.trc20","upstreamType":"usdt.trc20"}]`},
supportedTypes: "alipay,wxpay,usdt.trc20",
wantErr: "customMethods type may only contain lowercase letters",
},
{
name: "upstream type still rejects slashes",
config: map[string]string{"customMethods": `[{"type":"usdt_trc20","upstreamType":"usdt/trc20"}]`},
supportedTypes: "alipay,wxpay,usdt_trc20",
wantErr: "customMethods upstreamType may only contain lowercase letters",
},
{
name: "malformed custom methods json",
config: map[string]string{"customMethods": `not-json`},