feat(payment): 增加支付配置测试支付与全链路报文
This commit is contained in:
@@ -57,6 +57,7 @@ type channelQueryPaymentResponse struct {
|
||||
PayWay string
|
||||
PayTime string
|
||||
Raw map[string]string
|
||||
RawRequest map[string]string
|
||||
}
|
||||
|
||||
type channelQueryPaymentRequest struct {
|
||||
@@ -167,6 +168,7 @@ func (c leshuaChannel) QueryPayment(ctx context.Context, req channelQueryPayment
|
||||
PayWay: resp.PayWay,
|
||||
PayTime: resp.PayTime,
|
||||
Raw: resp.Raw,
|
||||
RawRequest: resp.RawRequest,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -287,6 +289,7 @@ func (c lakalaChannel) QueryPayment(ctx context.Context, req channelQueryPayment
|
||||
PayWay: resp.PayWay,
|
||||
PayTime: resp.PayTime,
|
||||
Raw: resp.Raw,
|
||||
RawRequest: resp.RawRequest,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -415,6 +418,7 @@ func (c shunchengChannel) QueryPayment(ctx context.Context, req channelQueryPaym
|
||||
PayWay: resp.PayWay,
|
||||
PayTime: resp.PayTime,
|
||||
Raw: resp.Raw,
|
||||
RawRequest: resp.RawRequest,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -535,6 +539,7 @@ func (c saobeiChannel) QueryPayment(ctx context.Context, req channelQueryPayment
|
||||
Amount: resp.Amount,
|
||||
PayTime: resp.PayTime,
|
||||
Raw: resp.Raw,
|
||||
RawRequest: resp.RawRequest,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -599,9 +604,18 @@ func (c saobeiChannel) VerifyNotify(params map[string]string, rawPayload string,
|
||||
}
|
||||
|
||||
func buildChannelClient(dto *paymentconfig.ConfigDTO) (channelClient, error) {
|
||||
return buildChannelClientWithBreaker(dto, true)
|
||||
}
|
||||
|
||||
// buildConfigTestChannelClient 为后台支付配置测试构建独立通道客户端,不进入生产支付熔断器。
|
||||
func buildConfigTestChannelClient(dto *paymentconfig.ConfigDTO) (channelClient, error) {
|
||||
return buildChannelClientWithBreaker(dto, false)
|
||||
}
|
||||
|
||||
func buildChannelClientWithBreaker(dto *paymentconfig.ConfigDTO, useBreaker bool) (channelClient, error) {
|
||||
switch strings.ToLower(strings.TrimSpace(dto.Provider)) {
|
||||
case "leshua":
|
||||
return withChannelBreaker("leshua", newLeshuaChannel(leshua.Config{
|
||||
return channelClientWithOptionalBreaker(useBreaker, "leshua", newLeshuaChannel(leshua.Config{
|
||||
GatewayURL: dto.GatewayURL,
|
||||
MerchantID: dto.MerchantID,
|
||||
SignKey: dto.SignKey,
|
||||
@@ -613,7 +627,7 @@ func buildChannelClient(dto *paymentconfig.ConfigDTO) (channelClient, error) {
|
||||
SignType: firstNonEmpty(dto.SignType, "MD5"),
|
||||
})), nil
|
||||
case "lakala":
|
||||
return withChannelBreaker("lakala", newLakalaChannel(lakala.Config{
|
||||
return channelClientWithOptionalBreaker(useBreaker, "lakala", newLakalaChannel(lakala.Config{
|
||||
GatewayURL: dto.GatewayURL,
|
||||
AppID: extraString(dto.ExtraConfig, "app_id"),
|
||||
SerialNo: extraString(dto.ExtraConfig, "serial_no"),
|
||||
@@ -630,7 +644,7 @@ func buildChannelClient(dto *paymentconfig.ConfigDTO) (channelClient, error) {
|
||||
OrderExpireMinutes: extraInt(dto.ExtraConfig, "order_expire_minutes"),
|
||||
})), nil
|
||||
case "shuncheng":
|
||||
return withChannelBreaker("shuncheng", newShunchengChannel(shuncheng.Config{
|
||||
return channelClientWithOptionalBreaker(useBreaker, "shuncheng", newShunchengChannel(shuncheng.Config{
|
||||
GatewayURL: dto.GatewayURL,
|
||||
MerchantID: dto.MerchantID,
|
||||
SecretID: extraString(dto.ExtraConfig, "secret_id"),
|
||||
@@ -646,7 +660,7 @@ func buildChannelClient(dto *paymentconfig.ConfigDTO) (channelClient, error) {
|
||||
TokenMargin: time.Duration(extraInt(dto.ExtraConfig, "token_refresh_margin_seconds")) * time.Second,
|
||||
})), nil
|
||||
case "saobei":
|
||||
return withChannelBreaker("saobei", newSaobeiChannel(saobei.Config{
|
||||
return channelClientWithOptionalBreaker(useBreaker, "saobei", newSaobeiChannel(saobei.Config{
|
||||
GatewayURL: dto.GatewayURL,
|
||||
MerchantID: dto.MerchantID,
|
||||
TerminalID: extraString(dto.ExtraConfig, "terminal_id"),
|
||||
@@ -734,3 +748,10 @@ func extraInt(config map[string]any, key string) int {
|
||||
n, _ := strconv.Atoi(value)
|
||||
return n
|
||||
}
|
||||
|
||||
func channelClientWithOptionalBreaker(useBreaker bool, name string, next channelClient) channelClient {
|
||||
if !useBreaker {
|
||||
return next
|
||||
}
|
||||
return withChannelBreaker(name, next)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user