优化结构
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
paymentutil "kra/pkg/paymentkit"
|
||||
bizpayment "kra/internal/biz/payment"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -316,7 +316,7 @@ func validatePaymentIntegrationConfig(provider string, values map[string]any) er
|
||||
}
|
||||
}
|
||||
switch provider {
|
||||
case paymentutil.ProviderAlipayV3:
|
||||
case bizpayment.PaymentAlipayV3:
|
||||
for _, group := range []struct {
|
||||
label string
|
||||
keys []string
|
||||
@@ -330,21 +330,21 @@ func validatePaymentIntegrationConfig(provider string, values map[string]any) er
|
||||
return fmt.Errorf("%s 缺少配置字段 %s", provider, group.label)
|
||||
}
|
||||
}
|
||||
case paymentutil.ProviderWechatV2:
|
||||
case bizpayment.PaymentWechatV2:
|
||||
if integrationFirst(values, "client_cert", "cert_pem", "apiclient_cert") == "" || integrationFirst(values, "client_key", "key_pem", "apiclient_key") == "" {
|
||||
return fmt.Errorf("%s 退款要求同时配置 client_cert 和 client_key", provider)
|
||||
}
|
||||
case paymentutil.ProviderApple:
|
||||
case bizpayment.PaymentApple:
|
||||
if integrationInt64(values, "price_divisor", 0) <= 0 {
|
||||
if _, exists := values["price_divisors"].(map[string]any); !exists {
|
||||
return fmt.Errorf("%s 缺少配置字段 price_divisor 或 price_divisors", provider)
|
||||
}
|
||||
}
|
||||
case paymentutil.ProviderDouyin:
|
||||
case bizpayment.PaymentDouyin:
|
||||
if integrationFirst(values, "platform_serial_no", "platform_cert_serial") == "" {
|
||||
return fmt.Errorf("%s 缺少配置字段 platform_serial_no", provider)
|
||||
}
|
||||
case paymentutil.ProviderQQ:
|
||||
case bizpayment.PaymentQQ:
|
||||
if integrationFirst(values, "mch_id", "merchant_id") == "" {
|
||||
return fmt.Errorf("%s 缺少配置字段 mch_id", provider)
|
||||
}
|
||||
@@ -355,12 +355,12 @@ func validatePaymentIntegrationConfig(provider string, values map[string]any) er
|
||||
if signType != "" && signType != "MD5" && signType != "HMAC-SHA256" {
|
||||
return fmt.Errorf("%s sign_type 必须是 MD5 或 HMAC-SHA256", provider)
|
||||
}
|
||||
case paymentutil.ProviderAllinPay:
|
||||
case bizpayment.PaymentAllinPay:
|
||||
orderType := strings.ToLower(integrationFirst(values, "query_order_type", "order_type"))
|
||||
if orderType != "" && orderType != "reqsn" && orderType != "trxid" {
|
||||
return fmt.Errorf("%s query_order_type 必须是 reqsn 或 trxid", provider)
|
||||
}
|
||||
case paymentutil.ProviderChinaums, paymentutil.ProviderSFT, paymentutil.ProviderSuperPay, paymentutil.ProviderWechatGame, paymentutil.ProviderDouyinGame:
|
||||
case bizpayment.PaymentChinaums, bizpayment.PaymentSFT, bizpayment.PaymentSuperPay, bizpayment.PaymentWechatGame, bizpayment.PaymentDouyinGame:
|
||||
if integrationFirst(values, "app_key", "merchant_key", "signing_secret", "token") == "" {
|
||||
return fmt.Errorf("%s 缺少签名密钥", provider)
|
||||
}
|
||||
@@ -369,7 +369,7 @@ func validatePaymentIntegrationConfig(provider string, values map[string]any) er
|
||||
}
|
||||
}
|
||||
if environment := strings.ToLower(integrationText(values, "environment")); environment != "" {
|
||||
allowedSandbox := provider != paymentutil.ProviderQQ && provider != paymentutil.ProviderDouyin && provider != paymentutil.ProviderLakala
|
||||
allowedSandbox := provider != bizpayment.PaymentQQ && provider != bizpayment.PaymentDouyin && provider != bizpayment.PaymentLakala
|
||||
if environment != "production" && environment != "prod" && (!allowedSandbox || environment != "sandbox") {
|
||||
return fmt.Errorf("%s environment 配置无效", provider)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user