feat(payment): 接入扫呗普通支付2.0
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"hfb_jysh/backend/internal/integrations/payment/saobei"
|
||||
"hfb_jysh/backend/internal/model"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -22,7 +23,11 @@ func (r *Repository) HandleNotify(ctx context.Context, provider string, params m
|
||||
return r.HandleRefundNotify(ctx, provider, params, rawPayload, contentType, authorization)
|
||||
}
|
||||
|
||||
payment, err := r.findPaymentForNotify(ctx, params)
|
||||
lookupParams := params
|
||||
if provider == "saobei" {
|
||||
lookupParams = saobei.CanonicalizePayload(params)
|
||||
}
|
||||
payment, err := r.findPaymentForNotify(ctx, lookupParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -35,7 +40,19 @@ func (r *Repository) HandleNotify(ctx context.Context, provider string, params m
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if amount := parseCent(params["amount"]); amount > 0 && amount != payment.AmountCent {
|
||||
processingParams := params
|
||||
if provider == "saobei" {
|
||||
processingParams = saobei.CanonicalizePayload(params)
|
||||
}
|
||||
if runtimeConfig.Provider == "saobei" {
|
||||
if merchantNo := processingParams["merchant_no"]; merchantNo == "" || merchantNo != payment.MerchantID {
|
||||
return nil, ErrPaymentVerifyFailed
|
||||
}
|
||||
if amount := parseCent(processingParams["amount"]); amount <= 0 || amount != payment.AmountCent {
|
||||
return nil, ErrPaymentVerifyFailed
|
||||
}
|
||||
}
|
||||
if amount := parseCent(processingParams["amount"]); amount > 0 && amount != payment.AmountCent {
|
||||
if err := r.recordNotifyDiagnostic(ctx, payment.ID, params, rawPayload, contentType, verify, "amount_mismatch"); err != nil {
|
||||
r.log().Warn("支付回调诊断保存失败", paymentLogFields(ctx, appendFields(
|
||||
paymentOrderFields(payment),
|
||||
@@ -49,9 +66,9 @@ func (r *Repository) HandleNotify(ctx context.Context, provider string, params m
|
||||
}
|
||||
return nil, ErrPaymentVerifyFailed
|
||||
}
|
||||
raw := withNotifyDiagnostic(params, rawPayload, contentType, verify, "verified")
|
||||
channelStatus := normalizeNotifyPaymentStatus(runtimeConfig.Provider, params["status"])
|
||||
if err := r.applyChannelStatus(ctx, payment, channelStatus, params["pay_time"], raw, channelSourceNotify); err != nil {
|
||||
raw := withNotifyDiagnostic(processingParams, rawPayload, contentType, verify, "verified")
|
||||
channelStatus := normalizeNotifyPaymentStatus(runtimeConfig.Provider, processingParams["status"])
|
||||
if err := r.applyChannelStatus(ctx, payment, channelStatus, processingParams["pay_time"], raw, channelSourceNotify); err != nil {
|
||||
// 入口处的 WARN 只有渠道参数,定位不到是哪个订单哪笔支付单,这里补齐上下文。
|
||||
r.log().Warn("支付回调入账失败", paymentLogFields(ctx, appendFields(
|
||||
paymentOrderFields(payment),
|
||||
@@ -182,10 +199,11 @@ func redactNotifyParams(params map[string]string) map[string]string {
|
||||
allowed := map[string]bool{
|
||||
"service": true, "merchant_id": true, "third_order_id": true,
|
||||
"provider_order_id": true, "leshua_order_id": true, "schc_order_id": true,
|
||||
"terminal_trace": true, "out_trade_no": true,
|
||||
"merchant_refund_id": true, "provider_refund_id": true,
|
||||
"leshua_refund_id": true, "schc_refund_id": true,
|
||||
"status": true, "amount": true, "refund_amount": true,
|
||||
"pay_time": true, "refund_time": true,
|
||||
"status": true, "amount": true, "total_fee": true, "refund_amount": true,
|
||||
"pay_time": true, "end_time": true, "refund_time": true,
|
||||
"code": true, "resp_code": true, "result_code": true, "error_code": true,
|
||||
}
|
||||
redacted := make(map[string]string, len(allowed))
|
||||
|
||||
Reference in New Issue
Block a user