feat(代理自充): AUG26-017 代理自充收款方式与线下预存款审批字段
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m52s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m52s
- 受控配置新增代理在线自充允许范围(仅微信/仅支付宝/同时支持),读侧与创建侧取允许范围与可用商户池交集,两侧失败关闭 - 新增允许范围查询与修改端点,读限代理与平台账号、写限超级管理员,复用受控配置写服务留痕 - tb_agent_recharge_record 新增交易流水号、线下收款方式三列快照与其他凭证列(成对迁移 000213) - 线下申请校验启用的收款方式字典项与必填交易流水号,交易流水号独立于在线渠道交易号、不参与去重 - 扩展 offline_recharge_approval 场景可映射字段白名单与字典引用保护 - 新增付款凭证识别能力与交易流水号预填接口,识别不落库、日志不记录载荷
This commit is contained in:
58
internal/application/agentrecharge/online_payment_policy.go
Normal file
58
internal/application/agentrecharge/online_payment_policy.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package agentrecharge
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
apperrors "github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
)
|
||||
|
||||
// OnlinePaymentMethodConfigReader 提供代理在线自充允许范围的严格读取能力。
|
||||
type OnlinePaymentMethodConfigReader interface {
|
||||
GetStrict(ctx context.Context, key string) (string, error)
|
||||
}
|
||||
|
||||
// OnlinePaymentMethodPolicy 将受控配置值映射为对外可见的线上支付方式集合。
|
||||
type OnlinePaymentMethodPolicy struct {
|
||||
reader OnlinePaymentMethodConfigReader
|
||||
}
|
||||
|
||||
// NewOnlinePaymentMethodPolicy 创建代理在线自充允许范围策略。
|
||||
func NewOnlinePaymentMethodPolicy(reader OnlinePaymentMethodConfigReader) *OnlinePaymentMethodPolicy {
|
||||
return &OnlinePaymentMethodPolicy{reader: reader}
|
||||
}
|
||||
|
||||
// AllowedMethods 严格读取允许范围;配置缺失使用注册默认值,非法值失败关闭。
|
||||
func (p *OnlinePaymentMethodPolicy) AllowedMethods(ctx context.Context) ([]string, error) {
|
||||
if p == nil || p.reader == nil {
|
||||
return nil, apperrors.New(apperrors.CodeServiceUnavailable, "代理在线充值允许范围未配置")
|
||||
}
|
||||
value, err := p.reader.GetStrict(ctx, constants.SystemConfigAgentSelfRechargeAllowedMethods)
|
||||
if err != nil {
|
||||
return nil, apperrors.Wrap(apperrors.CodeNoPaymentConfig, err, "读取代理在线充值允许范围失败")
|
||||
}
|
||||
switch value {
|
||||
case constants.AgentSelfRechargeAllowedWechatOnly:
|
||||
return []string{constants.RechargeMethodWechat}, nil
|
||||
case constants.AgentSelfRechargeAllowedAlipayOnly:
|
||||
return []string{constants.RechargeMethodAlipay}, nil
|
||||
case constants.AgentSelfRechargeAllowedBoth:
|
||||
return []string{constants.RechargeMethodWechat, constants.RechargeMethodAlipay}, nil
|
||||
default:
|
||||
return nil, apperrors.New(apperrors.CodeNoPaymentConfig, "代理在线充值允许范围值非法")
|
||||
}
|
||||
}
|
||||
|
||||
// IsAllowed 判断业务支付方式是否在当前受控允许范围内。
|
||||
func (p *OnlinePaymentMethodPolicy) IsAllowed(ctx context.Context, method string) error {
|
||||
methods, err := p.AllowedMethods(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, allowed := range methods {
|
||||
if allowed == method {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return apperrors.New(apperrors.CodeNoPaymentConfig, "当前支付方式不在代理在线充值允许范围内")
|
||||
}
|
||||
Reference in New Issue
Block a user