优化结构
This commit is contained in:
@@ -3,4 +3,4 @@ package biz
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSet is biz providers.
|
||||
var ProviderSet = wire.NewSet(NewUserUsecase, NewAuthenticationUsecase, NewSystemConfigUsecase, NewAuthorityUsecase, NewAPIUsecase, NewPermissionUsecase, NewAccessControlUsecase, NewMenuUsecase, NewDepartmentUsecase, NewPositionUsecase, NewDictionaryUsecase, NewParameterUsecase, NewTokenUsecase, NewSecurityUsecase, NewVersionUsecase, NewExportUsecase, NewAuditUsecase, NewAuditRecorderUsecase, NewLogViewerUsecase, NewTaskUsecaseWithRegistry, NewTaskApplicationUsecase, NewMediaUsecase, NewAnnouncementUsecase, NewEmailUsecase, NewPaymentUsecase)
|
||||
var ProviderSet = wire.NewSet(NewUserUsecase, NewAuthenticationUsecase, NewSystemConfigUsecase, NewAuthorityUsecase, NewAPIUsecase, NewPermissionUsecase, NewAccessControlUsecase, NewMenuUsecase, NewDepartmentUsecase, NewPositionUsecase, NewDictionaryUsecase, NewParameterUsecase, NewTokenUsecase, NewSecurityUsecase, NewVersionUsecase, NewExportUsecase, NewAuditUsecase, NewAuditRecorderUsecase, NewLogViewerUsecase, NewTaskUsecaseWithRegistry, NewTaskApplicationUsecase, NewMediaUsecase, NewAnnouncementUsecase, NewEmailUsecase, NewPaymentUsecase, NewIntegrationConfigUsecase)
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const IntegrationKindPayment = "payment"
|
||||
|
||||
type IntegrationConfig struct {
|
||||
Kind string
|
||||
Provider string
|
||||
Enabled bool
|
||||
Values json.RawMessage
|
||||
}
|
||||
|
||||
type IntegrationConfigField struct {
|
||||
Key string `json:"key"`
|
||||
Label string `json:"label"`
|
||||
Type string `json:"type"`
|
||||
Required bool `json:"required"`
|
||||
Secret bool `json:"secret"`
|
||||
Placeholder string `json:"placeholder,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Options []IntegrationConfigOption `json:"options,omitempty"`
|
||||
}
|
||||
|
||||
type IntegrationConfigOption struct {
|
||||
Label string `json:"label"`
|
||||
Value any `json:"value"`
|
||||
}
|
||||
|
||||
type IntegrationConfigDefinition struct {
|
||||
Kind string `json:"kind"`
|
||||
Provider string `json:"provider"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Fields []IntegrationConfigField `json:"fields"`
|
||||
Defaults map[string]any `json:"defaults"`
|
||||
}
|
||||
|
||||
type IntegrationConfigRepo interface {
|
||||
ListIntegrationConfigs(context.Context, string) ([]*IntegrationConfig, error)
|
||||
FindIntegrationConfig(context.Context, string, string) (*IntegrationConfig, error)
|
||||
SaveIntegrationConfig(context.Context, *IntegrationConfig) error
|
||||
DeleteIntegrationConfig(context.Context, string, string) error
|
||||
}
|
||||
|
||||
type IntegrationConfigUsecase struct{ repo IntegrationConfigRepo }
|
||||
|
||||
func NewIntegrationConfigUsecase(repo IntegrationConfigRepo) *IntegrationConfigUsecase {
|
||||
return &IntegrationConfigUsecase{repo: repo}
|
||||
}
|
||||
|
||||
func (uc *IntegrationConfigUsecase) List(ctx context.Context, kind string) ([]*IntegrationConfig, error) {
|
||||
kind = normalizeIntegrationPart(kind)
|
||||
if kind == "" {
|
||||
return nil, errors.New("集成配置 kind 不能为空")
|
||||
}
|
||||
return uc.repo.ListIntegrationConfigs(ctx, kind)
|
||||
}
|
||||
|
||||
func (uc *IntegrationConfigUsecase) Find(ctx context.Context, kind, provider string) (*IntegrationConfig, error) {
|
||||
kind, provider = normalizeIntegrationPart(kind), normalizeIntegrationPart(provider)
|
||||
if kind == "" || provider == "" {
|
||||
return nil, errors.New("集成配置 kind 和 provider 不能为空")
|
||||
}
|
||||
return uc.repo.FindIntegrationConfig(ctx, kind, provider)
|
||||
}
|
||||
|
||||
func (uc *IntegrationConfigUsecase) Save(ctx context.Context, config *IntegrationConfig) error {
|
||||
if config == nil {
|
||||
return errors.New("集成配置请求为空")
|
||||
}
|
||||
config.Kind = normalizeIntegrationPart(config.Kind)
|
||||
config.Provider = normalizeIntegrationPart(config.Provider)
|
||||
if config.Kind == "" || config.Provider == "" || len(config.Kind) > 32 || len(config.Provider) > 64 {
|
||||
return errors.New("集成配置 kind 或 provider 无效")
|
||||
}
|
||||
if !json.Valid(config.Values) {
|
||||
return errors.New("集成配置必须是合法 JSON")
|
||||
}
|
||||
values := map[string]any{}
|
||||
if err := json.Unmarshal(config.Values, &values); err != nil {
|
||||
return errors.New("集成配置必须是 JSON 对象")
|
||||
}
|
||||
if definition, ok := IntegrationDefinition(config.Kind, config.Provider); ok {
|
||||
values = mergeIntegrationDefaults(definition.Defaults, values)
|
||||
if config.Enabled {
|
||||
if err := ValidateIntegrationConfig(config.Kind, config.Provider, values); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
config.Values, _ = json.Marshal(values)
|
||||
}
|
||||
return uc.repo.SaveIntegrationConfig(ctx, config)
|
||||
}
|
||||
|
||||
func (uc *IntegrationConfigUsecase) Delete(ctx context.Context, kind, provider string) error {
|
||||
kind, provider = normalizeIntegrationPart(kind), normalizeIntegrationPart(provider)
|
||||
if kind == "" || provider == "" {
|
||||
return errors.New("集成配置 kind 和 provider 不能为空")
|
||||
}
|
||||
return uc.repo.DeleteIntegrationConfig(ctx, kind, provider)
|
||||
}
|
||||
|
||||
func normalizeIntegrationPart(value string) string {
|
||||
return strings.ToLower(strings.TrimSpace(value))
|
||||
}
|
||||
|
||||
func IntegrationDefinitions(kind string) []IntegrationConfigDefinition {
|
||||
kind = normalizeIntegrationPart(kind)
|
||||
definitions := integrationDefinitions[kind]
|
||||
out := append([]IntegrationConfigDefinition(nil), definitions...)
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Provider < out[j].Provider })
|
||||
return out
|
||||
}
|
||||
|
||||
func IntegrationDefinition(kind, provider string) (IntegrationConfigDefinition, bool) {
|
||||
for _, definition := range integrationDefinitions[normalizeIntegrationPart(kind)] {
|
||||
if definition.Provider == normalizeIntegrationPart(provider) {
|
||||
return definition, true
|
||||
}
|
||||
}
|
||||
return IntegrationConfigDefinition{}, false
|
||||
}
|
||||
|
||||
func DefaultIntegrationConfig(kind, provider string) map[string]any {
|
||||
definition, ok := IntegrationDefinition(kind, provider)
|
||||
if !ok {
|
||||
return map[string]any{}
|
||||
}
|
||||
return mergeIntegrationDefaults(definition.Defaults, nil)
|
||||
}
|
||||
|
||||
func mergeIntegrationDefaults(defaults, values map[string]any) map[string]any {
|
||||
out := make(map[string]any, len(defaults)+len(values))
|
||||
for key, value := range defaults {
|
||||
out[key] = value
|
||||
}
|
||||
for key, value := range values {
|
||||
out[key] = value
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func ValidateIntegrationConfig(kind, provider string, values map[string]any) error {
|
||||
if normalizeIntegrationPart(kind) != IntegrationKindPayment {
|
||||
return nil
|
||||
}
|
||||
return validatePaymentIntegrationConfig(normalizeIntegrationPart(provider), values)
|
||||
}
|
||||
|
||||
func validatePaymentIntegrationConfig(provider string, values map[string]any) error {
|
||||
definition, ok := IntegrationDefinition(IntegrationKindPayment, provider)
|
||||
if !ok {
|
||||
return errors.New("不支持的支付渠道")
|
||||
}
|
||||
for _, field := range definition.Fields {
|
||||
if field.Required && integrationText(values, field.Key) == "" {
|
||||
return fmt.Errorf("%s 缺少配置字段 %s", provider, field.Key)
|
||||
}
|
||||
}
|
||||
switch provider {
|
||||
case PaymentAlipayV3:
|
||||
for _, group := range []struct {
|
||||
label string
|
||||
keys []string
|
||||
}{
|
||||
{"private_key", []string{"private_key", "private_key_content", "private_key_path"}},
|
||||
{"app_cert", []string{"app_cert", "app_cert_content", "app_cert_path", "app_public_cert", "app_public_cert_content", "app_public_cert_path"}},
|
||||
{"root_cert", []string{"root_cert", "root_cert_content", "root_cert_path", "alipay_root_cert", "alipay_root_cert_content", "alipay_root_cert_path"}},
|
||||
{"public_cert", []string{"public_cert", "public_cert_content", "public_cert_path", "alipay_public_cert", "alipay_public_cert_content", "alipay_public_cert_path"}},
|
||||
} {
|
||||
if integrationFirst(values, group.keys...) == "" {
|
||||
return fmt.Errorf("%s 缺少配置字段 %s", provider, group.label)
|
||||
}
|
||||
}
|
||||
case 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 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 PaymentDouyin:
|
||||
if integrationFirst(values, "platform_serial_no", "platform_cert_serial") == "" {
|
||||
return fmt.Errorf("%s 缺少配置字段 platform_serial_no", provider)
|
||||
}
|
||||
case PaymentQQ:
|
||||
if integrationFirst(values, "mch_id", "merchant_id") == "" {
|
||||
return fmt.Errorf("%s 缺少配置字段 mch_id", provider)
|
||||
}
|
||||
if !hasQQIntegrationCertificate(values) {
|
||||
return fmt.Errorf("%s 退款要求配置 cert_file + key_file、pkcs12_file 或对应的 *_content", provider)
|
||||
}
|
||||
signType := strings.ToUpper(integrationText(values, "sign_type"))
|
||||
if signType != "" && signType != "MD5" && signType != "HMAC-SHA256" {
|
||||
return fmt.Errorf("%s sign_type 必须是 MD5 或 HMAC-SHA256", provider)
|
||||
}
|
||||
case 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 PaymentChinaums, PaymentSFT, PaymentSuperPay, PaymentWechatGame, PaymentDouyinGame:
|
||||
if integrationFirst(values, "app_key", "merchant_key", "signing_secret", "token") == "" {
|
||||
return fmt.Errorf("%s 缺少签名密钥", provider)
|
||||
}
|
||||
if !validIntegrationScale(integrationInt64(values, "query_amount_scale", 0)) {
|
||||
return fmt.Errorf("%s query_amount_scale 必须是正的 10 的幂", provider)
|
||||
}
|
||||
}
|
||||
if environment := strings.ToLower(integrationText(values, "environment")); environment != "" {
|
||||
allowedSandbox := provider != PaymentQQ && provider != PaymentDouyin && provider != PaymentLakala
|
||||
if environment != "production" && environment != "prod" && (!allowedSandbox || environment != "sandbox") {
|
||||
return fmt.Errorf("%s environment 配置无效", provider)
|
||||
}
|
||||
}
|
||||
return validateIntegrationCallbackAck(values)
|
||||
}
|
||||
|
||||
func integrationText(values map[string]any, key string) string {
|
||||
value, exists := values[key]
|
||||
if !exists || value == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(fmt.Sprint(value))
|
||||
}
|
||||
|
||||
func integrationFirst(values map[string]any, keys ...string) string {
|
||||
for _, key := range keys {
|
||||
if value := integrationText(values, key); value != "" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func integrationInt64(values map[string]any, key string, fallback int64) int64 {
|
||||
value := integrationText(values, key)
|
||||
if value == "" {
|
||||
return fallback
|
||||
}
|
||||
parsed, err := strconv.ParseInt(value, 10, 64)
|
||||
if err != nil {
|
||||
return fallback
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
func hasQQIntegrationCertificate(values map[string]any) bool {
|
||||
if integrationFirst(values, "pkcs12_file", "p12_file", "pkcs12_content") != "" {
|
||||
return true
|
||||
}
|
||||
if integrationFirst(values, "cert_file", "cert_path") != "" && integrationFirst(values, "key_file", "key_path") != "" {
|
||||
return true
|
||||
}
|
||||
return integrationFirst(values, "cert_content") != "" && integrationFirst(values, "key_content") != ""
|
||||
}
|
||||
|
||||
func validIntegrationScale(scale int64) bool {
|
||||
if scale <= 0 {
|
||||
return false
|
||||
}
|
||||
for scale%10 == 0 {
|
||||
scale /= 10
|
||||
}
|
||||
return scale == 1
|
||||
}
|
||||
|
||||
func validateIntegrationCallbackAck(values map[string]any) error {
|
||||
for _, prefix := range []string{"callback_success_", "callback_failure_"} {
|
||||
if value := integrationText(values, prefix+"status"); value != "" {
|
||||
status, err := strconv.Atoi(value)
|
||||
if err != nil || status < 200 || status > 599 {
|
||||
return fmt.Errorf("%sstatus 必须是 200-599", prefix)
|
||||
}
|
||||
}
|
||||
if contentType := integrationText(values, prefix+"content_type"); strings.ContainsAny(contentType, "\r\n") || len(contentType) > 200 {
|
||||
return fmt.Errorf("%scontent_type 非法", prefix)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package biz
|
||||
|
||||
func integrationField(key, label string, required, secret bool, fieldType string) IntegrationConfigField {
|
||||
if fieldType == "" {
|
||||
fieldType = "text"
|
||||
}
|
||||
return IntegrationConfigField{Key: key, Label: label, Required: required, Secret: secret, Type: fieldType}
|
||||
}
|
||||
|
||||
func integrationSelect(key, label string, required bool, values ...string) IntegrationConfigField {
|
||||
options := make([]IntegrationConfigOption, 0, len(values))
|
||||
for _, value := range values {
|
||||
options = append(options, IntegrationConfigOption{Label: value, Value: value})
|
||||
}
|
||||
return IntegrationConfigField{Key: key, Label: label, Required: required, Type: "select", Options: options}
|
||||
}
|
||||
|
||||
func paymentDefinition(provider, name, description string, defaults map[string]any, fields ...IntegrationConfigField) IntegrationConfigDefinition {
|
||||
common := []IntegrationConfigField{
|
||||
integrationField("notify_url", "支付回调地址", false, false, "url"),
|
||||
integrationField("return_url", "同步跳转地址", false, false, "url"),
|
||||
}
|
||||
fields = append(fields, common...)
|
||||
for _, field := range fields {
|
||||
if _, exists := defaults[field.Key]; exists {
|
||||
continue
|
||||
}
|
||||
switch field.Type {
|
||||
case "number":
|
||||
defaults[field.Key] = 0
|
||||
case "switch":
|
||||
defaults[field.Key] = false
|
||||
default:
|
||||
defaults[field.Key] = ""
|
||||
}
|
||||
}
|
||||
return IntegrationConfigDefinition{Kind: IntegrationKindPayment, Provider: provider, Name: name, Description: description, Defaults: defaults, Fields: fields}
|
||||
}
|
||||
|
||||
var genericPaymentFields = []IntegrationConfigField{
|
||||
integrationField("protocol_version", "协议版本", true, false, "text"),
|
||||
integrationField("app_id", "应用 ID", true, false, "text"),
|
||||
integrationField("merchant_id", "商户 ID", true, false, "text"),
|
||||
integrationField("create_url", "下单接口", true, false, "url"),
|
||||
integrationField("query_url", "查单接口", true, false, "url"),
|
||||
integrationField("refund_url", "退款接口", true, false, "url"),
|
||||
integrationField("app_key", "签名密钥", true, true, "password"),
|
||||
integrationField("query_status_field", "查单状态字段", true, false, "text"),
|
||||
integrationField("query_success_values", "查单成功值", true, false, "text"),
|
||||
integrationField("query_trade_no_field", "商户单号字段", true, false, "text"),
|
||||
integrationField("query_provider_trade_no_field", "平台单号字段", true, false, "text"),
|
||||
integrationField("query_amount_field", "金额字段", true, false, "text"),
|
||||
integrationField("query_currency_field", "币种字段", true, false, "text"),
|
||||
integrationField("query_amount_scale", "金额倍率", true, false, "number"),
|
||||
integrationField("callback_status_field", "回调状态字段", true, false, "text"),
|
||||
integrationField("callback_success_values", "回调成功值", true, false, "text"),
|
||||
integrationField("callback_trade_no_field", "回调商户单号字段", true, false, "text"),
|
||||
integrationField("callback_provider_trade_no_field", "回调平台单号字段", true, false, "text"),
|
||||
}
|
||||
|
||||
var genericPaymentDefaults = map[string]any{
|
||||
"protocol_version": "v1", "app_id": "", "merchant_id": "", "create_url": "", "query_url": "", "refund_url": "", "app_key": "",
|
||||
"query_status_field": "", "query_success_values": "", "query_trade_no_field": "",
|
||||
"query_provider_trade_no_field": "", "query_amount_field": "", "query_currency_field": "", "query_amount_scale": 1,
|
||||
"callback_status_field": "", "callback_success_values": "", "callback_trade_no_field": "",
|
||||
"callback_provider_trade_no_field": "", "notify_url": "", "return_url": "",
|
||||
}
|
||||
|
||||
func genericPaymentDefinition(provider, name, description string) IntegrationConfigDefinition {
|
||||
defaults := mergeIntegrationDefaults(genericPaymentDefaults, nil)
|
||||
fields := append([]IntegrationConfigField(nil), genericPaymentFields...)
|
||||
return paymentDefinition(provider, name, description, defaults, fields...)
|
||||
}
|
||||
|
||||
var integrationDefinitions = map[string][]IntegrationConfigDefinition{
|
||||
IntegrationKindPayment: {
|
||||
paymentDefinition(PaymentAlipay, "支付宝", "支付宝 OpenAPI RSA2 支付", map[string]any{"app_id": "", "private_key": "", "public_key": "", "environment": "production", "sign_type": "RSA2", "gateway_url": "https://openapi.alipay.com/gateway.do", "method": "alipay.trade.create"},
|
||||
integrationField("app_id", "应用 ID", true, false, "text"), integrationField("private_key", "应用私钥", true, true, "textarea"), integrationField("public_key", "支付宝公钥", true, true, "textarea"),
|
||||
integrationSelect("environment", "环境", false, "production", "sandbox"), integrationSelect("sign_type", "签名算法", false, "RSA2", "RSA"), integrationField("gateway_url", "网关地址", false, false, "url"),
|
||||
integrationSelect("method", "默认支付方式", false, "alipay.trade.create", "alipay.trade.pay", "alipay.trade.precreate", "alipay.trade.app.pay", "alipay.trade.page.pay", "alipay.trade.wap.pay")),
|
||||
paymentDefinition(PaymentAlipayV3, "支付宝 V3", "支付宝证书模式 V3 接口", map[string]any{"app_id": "", "private_key": "", "app_cert": "", "root_cert": "", "public_cert": "", "environment": "production", "api_base_url": "https://openapi.alipay.com", "gateway_url": "https://openapi.alipay.com/gateway.do", "method": "alipay.trade.create"},
|
||||
integrationField("app_id", "应用 ID", true, false, "text"), integrationField("private_key", "应用私钥", false, true, "textarea"), integrationField("app_cert", "应用公钥证书", false, true, "textarea"), integrationField("root_cert", "支付宝根证书", false, true, "textarea"), integrationField("public_cert", "支付宝公钥证书", false, true, "textarea"),
|
||||
integrationSelect("environment", "环境", false, "production", "sandbox"), integrationField("api_base_url", "API 地址", false, false, "url"), integrationField("gateway_url", "网关地址", false, false, "url"), integrationSelect("method", "默认支付方式", false, "alipay.trade.create", "alipay.trade.pay", "alipay.trade.precreate", "alipay.trade.app.pay", "alipay.trade.page.pay", "alipay.trade.wap.pay")),
|
||||
paymentDefinition(PaymentWechatV2, "微信支付 V2", "微信支付 V2,含退款双向证书", map[string]any{"app_id": "", "merchant_id": "", "mch_key": "", "sign_type": "MD5", "trade_type": "NATIVE", "client_cert": "", "client_key": ""},
|
||||
integrationField("app_id", "应用 ID", true, false, "text"), integrationField("merchant_id", "商户号", true, false, "text"), integrationField("mch_key", "API 密钥", true, true, "password"), integrationSelect("sign_type", "签名算法", false, "MD5", "HMAC-SHA256"), integrationSelect("trade_type", "默认交易类型", false, "JSAPI", "APP", "NATIVE", "MWEB", "MICROPAY"), integrationField("client_cert", "商户证书", false, true, "textarea"), integrationField("client_key", "证书私钥", false, true, "textarea")),
|
||||
paymentDefinition(PaymentWechatV3, "微信支付 V3", "微信支付 API v3", map[string]any{"app_id": "", "merchant_id": "", "serial_no": "", "private_key": "", "api_v3_key": "", "platform_cert": "", "platform_serial_no": "", "trade_type": "jsapi"},
|
||||
integrationField("app_id", "应用 ID", true, false, "text"), integrationField("merchant_id", "商户号", true, false, "text"), integrationField("serial_no", "商户证书序列号", true, false, "text"), integrationField("private_key", "商户私钥", true, true, "textarea"), integrationField("api_v3_key", "API v3 密钥", true, true, "password"), integrationField("platform_cert", "平台证书", true, true, "textarea"), integrationField("platform_serial_no", "平台证书序列号", false, false, "text"), integrationSelect("trade_type", "默认交易类型", false, "jsapi", "app", "native", "h5", "codepay")),
|
||||
paymentDefinition(PaymentApple, "Apple IAP", "Apple App Store Server API", map[string]any{"issuer_id": "", "key_id": "", "bundle_id": "", "private_key": "", "price_divisor": 10, "environment": "production"},
|
||||
integrationField("issuer_id", "Issuer ID", true, false, "text"), integrationField("key_id", "Key ID", true, false, "text"), integrationField("bundle_id", "Bundle ID", true, false, "text"), integrationField("private_key", "P8 私钥", true, true, "textarea"), integrationField("price_divisor", "价格除数", false, false, "number"), integrationSelect("environment", "环境", false, "production", "sandbox")),
|
||||
paymentDefinition(PaymentDouyin, "抖音支付", "抖音开放平台支付", map[string]any{"app_id": "", "merchant_id": "", "serial_no": "", "api_key": "", "private_key": "", "platform_cert": "", "platform_serial_no": "", "trade_type": "jsapi", "environment": "production"},
|
||||
integrationField("app_id", "应用 ID", true, false, "text"), integrationField("merchant_id", "商户号", true, false, "text"), integrationField("serial_no", "商户证书序列号", true, false, "text"), integrationField("api_key", "API 密钥", true, true, "password"), integrationField("private_key", "商户私钥", true, true, "textarea"), integrationField("platform_cert", "平台证书", true, true, "textarea"), integrationField("platform_serial_no", "平台证书序列号", false, false, "text"), integrationSelect("trade_type", "默认交易类型", false, "app", "jsapi", "h5", "native"), integrationSelect("environment", "环境", false, "production")),
|
||||
paymentDefinition(PaymentQQ, "QQ 钱包", "QQ 钱包支付", map[string]any{"mch_id": "", "api_key": "", "sign_type": "MD5", "trade_type": "NATIVE", "cert_file": "", "key_file": "", "environment": "production"},
|
||||
integrationField("mch_id", "商户号", true, false, "text"), integrationField("api_key", "API 密钥", true, true, "password"), integrationSelect("sign_type", "签名算法", false, "MD5", "HMAC-SHA256"), integrationSelect("trade_type", "默认交易类型", false, "JSAPI", "NATIVE", "APP", "MICROPAY"), integrationField("cert_file", "退款证书路径", false, false, "text"), integrationField("key_file", "退款私钥路径", false, true, "text"), integrationSelect("environment", "环境", false, "production")),
|
||||
paymentDefinition(PaymentAllinPay, "通联支付", "通联收银宝支付", map[string]any{"cus_id": "", "app_id": "", "private_key": "", "public_key": "", "org_id": "", "pay_type": "W02", "query_order_type": "reqsn", "currency": "CNY", "environment": "production"},
|
||||
integrationField("cus_id", "商户号", true, false, "text"), integrationField("app_id", "应用 ID", true, false, "text"), integrationField("private_key", "商户私钥", true, true, "textarea"), integrationField("public_key", "平台公钥", true, true, "textarea"), integrationField("org_id", "机构号", false, false, "text"), integrationField("pay_type", "支付类型", false, false, "text"), integrationSelect("query_order_type", "查单标识", false, "reqsn", "trxid"), integrationField("currency", "币种", false, false, "text"), integrationSelect("environment", "环境", false, "production", "sandbox")),
|
||||
paymentDefinition(PaymentLakala, "拉卡拉", "拉卡拉聚合支付", map[string]any{"partner_code": "", "credential_code": "", "channel": "Wechat", "method": "jsapi", "currency": "CNY", "environment": "production"},
|
||||
integrationField("partner_code", "合作方编号", true, false, "text"), integrationField("credential_code", "凭证码", true, true, "password"), integrationSelect("channel", "支付渠道", false, "Wechat", "Alipay", "UnionPay"), integrationSelect("method", "默认支付方式", false, "jsapi", "h5", "mini", "native", "qrcode", "native_jsapi", "sdk", "web", "retail", "retail_qrcode"), integrationField("currency", "币种", false, false, "text"), integrationSelect("environment", "环境", false, "production")),
|
||||
paymentDefinition(PaymentPayPal, "PayPal", "PayPal Checkout", map[string]any{"client_id": "", "client_secret": "", "webhook_id": "", "environment": "sandbox", "return_url": "", "cancel_url": "", "auto_capture": true},
|
||||
integrationField("client_id", "Client ID", true, false, "text"), integrationField("client_secret", "Client Secret", true, true, "password"), integrationField("webhook_id", "Webhook ID", true, false, "text"), integrationSelect("environment", "环境", false, "sandbox", "production"), integrationField("cancel_url", "取消跳转地址", false, false, "url"), integrationField("auto_capture", "自动捕获", false, false, "switch")),
|
||||
paymentDefinition(PaymentSaobei, "扫呗", "扫呗聚合支付", map[string]any{"inst_no": "", "key": "", "merchant_no": "", "terminal_id": "", "access_token": "", "pay_type": "010", "currency": "CNY", "environment": "production"},
|
||||
integrationField("inst_no", "机构号", true, false, "text"), integrationField("key", "机构密钥", true, true, "password"), integrationField("merchant_no", "商户号", true, false, "text"), integrationField("terminal_id", "终端号", true, false, "text"), integrationField("access_token", "访问令牌", true, true, "password"), integrationField("pay_type", "支付类型", false, false, "text"), integrationField("currency", "币种", false, false, "text"), integrationSelect("environment", "环境", false, "production", "sandbox")),
|
||||
genericPaymentDefinition(PaymentChinaums, "银联商务", "按商户协议配置的银联商务适配器"),
|
||||
genericPaymentDefinition(PaymentSFT, "商福通", "按商户协议配置的商福通适配器"),
|
||||
genericPaymentDefinition(PaymentSuperPay, "Supper Pay", "按商户协议配置的 Supper Pay 适配器"),
|
||||
genericPaymentDefinition(PaymentWechatGame, "微信小游戏支付", "微信小游戏虚拟支付配置驱动适配器"),
|
||||
genericPaymentDefinition(PaymentDouyinGame, "抖音小游戏支付", "抖音小游戏支付配置驱动适配器"),
|
||||
},
|
||||
}
|
||||
@@ -56,12 +56,6 @@ func PaymentRejected(err error) error {
|
||||
return fmt.Errorf("%w: %v", ErrPaymentOperationRejected, err)
|
||||
}
|
||||
|
||||
type PaymentConfig struct {
|
||||
Provider string
|
||||
Enabled bool
|
||||
Values json.RawMessage
|
||||
}
|
||||
|
||||
type PaymentRequest struct {
|
||||
Provider string `json:"provider"`
|
||||
TradeNo string `json:"tradeNo"`
|
||||
@@ -207,8 +201,6 @@ type PaymentCallback struct {
|
||||
}
|
||||
|
||||
type PaymentRepo interface {
|
||||
ListConfigs(context.Context) ([]*PaymentConfig, error)
|
||||
SaveConfig(context.Context, *PaymentConfig) error
|
||||
Create(context.Context, *PaymentRequest) (*PaymentResult, error)
|
||||
Query(context.Context, string, string) (*PaymentResult, error)
|
||||
Refund(context.Context, *PaymentRefundRequest) (*PaymentResult, error)
|
||||
@@ -308,14 +300,6 @@ func (uc *PaymentUsecase) RegisterBusinessModule(module PaymentBusinessModule) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *PaymentUsecase) Configs(ctx context.Context) ([]*PaymentConfig, error) {
|
||||
return uc.repo.ListConfigs(ctx)
|
||||
}
|
||||
|
||||
func (uc *PaymentUsecase) SaveConfig(ctx context.Context, config *PaymentConfig) error {
|
||||
return uc.repo.SaveConfig(ctx, config)
|
||||
}
|
||||
|
||||
func (uc *PaymentUsecase) Order(ctx context.Context, provider, tradeNo string) (*PaymentOrder, error) {
|
||||
if uc.orders == nil {
|
||||
return nil, errors.New("支付订单仓储未接入")
|
||||
|
||||
@@ -22,8 +22,6 @@ type paymentRepoStub struct {
|
||||
callbackErr error
|
||||
}
|
||||
|
||||
func (r *paymentRepoStub) ListConfigs(context.Context) ([]*PaymentConfig, error) { return nil, nil }
|
||||
func (r *paymentRepoStub) SaveConfig(context.Context, *PaymentConfig) error { return nil }
|
||||
func (r *paymentRepoStub) Create(_ context.Context, req *PaymentRequest) (*PaymentResult, error) {
|
||||
copyReq := *req
|
||||
r.createdReq = ©Req
|
||||
|
||||
Reference in New Issue
Block a user