mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-30 16:23:31 +00:00
Merge pull request #7012 from ouchihao/codex/issue-6982-easypay-upstream-type-dots
fix(payment): allow periods in EasyPay upstream types
This commit is contained in:
@@ -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`},
|
||||
|
||||
Reference in New Issue
Block a user