优化结构
This commit is contained in:
@@ -29,6 +29,10 @@ func NewPaymentRepo(data Provider, config integrationbiz.PaymentConfigReader, fa
|
||||
}
|
||||
|
||||
func (r *paymentRepo) values(ctx context.Context, provider string) (map[string]any, error) {
|
||||
return r.readValues(ctx, provider, true)
|
||||
}
|
||||
|
||||
func (r *paymentRepo) readValues(ctx context.Context, provider string, requireEnabled bool) (map[string]any, error) {
|
||||
if r == nil || r.config == nil {
|
||||
return nil, errors.New("支付配置仓储未接入")
|
||||
}
|
||||
@@ -39,7 +43,10 @@ func (r *paymentRepo) values(ctx context.Context, provider string) (map[string]a
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if config == nil || !config.Enabled {
|
||||
if config == nil {
|
||||
return nil, errors.New("支付配置为空")
|
||||
}
|
||||
if requireEnabled && !config.Enabled {
|
||||
return nil, fmt.Errorf("支付渠道 %s 未启用", provider)
|
||||
}
|
||||
values := map[string]any{}
|
||||
@@ -284,24 +291,7 @@ func recordPaymentTestError(ctx context.Context, data Provider, provider, tradeN
|
||||
}
|
||||
|
||||
func (r *paymentRepo) testRow(ctx context.Context, provider string) (map[string]any, error) {
|
||||
if r == nil || r.config == nil {
|
||||
return nil, errors.New("支付配置仓储未接入")
|
||||
}
|
||||
config, err := r.config.ReadPaymentConfig(ctx, provider)
|
||||
if err != nil {
|
||||
if errors.Is(err, integrationbiz.ErrPaymentConfigNotFound) {
|
||||
return nil, bizpayment.ErrPaymentProviderNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if config == nil {
|
||||
return nil, errors.New("支付配置为空")
|
||||
}
|
||||
values := map[string]any{}
|
||||
if err := json.Unmarshal(config.Values, &values); err != nil || values == nil {
|
||||
return nil, errors.New("支付配置格式错误")
|
||||
}
|
||||
return values, nil
|
||||
return r.readValues(ctx, provider, false)
|
||||
}
|
||||
|
||||
func paymentTestRequest(provider string, values map[string]any) *bizpayment.PaymentRequest {
|
||||
|
||||
Reference in New Issue
Block a user