优化支付日志和配置删除提示
This commit is contained in:
@@ -2,9 +2,11 @@ package payment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
"log"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (r *Repository) HandleLeshuaNotify(ctx context.Context, params map[string]string, rawPayload string, contentType string) (*NotifyResult, error) {
|
||||
@@ -31,7 +33,15 @@ func (r *Repository) HandleNotify(ctx context.Context, provider string, params m
|
||||
|
||||
if amount := parseCent(params["amount"]); amount > 0 && amount != payment.AmountCent {
|
||||
if err := r.recordNotifyDiagnostic(ctx, payment.ID, params, rawPayload, contentType, verify, "amount_mismatch"); err != nil {
|
||||
log.Printf("[payment] %s notify diagnostic save failed third_order_id=%s err=%v", runtimeConfig.Provider, params["third_order_id"], err)
|
||||
r.log().Warn("payment notify diagnostic save failed", paymentLogFields(ctx, appendFields(
|
||||
paymentOrderFields(payment),
|
||||
runtimeConfigFields(runtimeConfig),
|
||||
[]zap.Field{
|
||||
zap.String("diagnostic_status", "amount_mismatch"),
|
||||
zap.Error(err),
|
||||
},
|
||||
)...,
|
||||
)...)
|
||||
}
|
||||
return nil, ErrPaymentVerifyFailed
|
||||
}
|
||||
@@ -106,22 +116,37 @@ func (r *Repository) verifyNotify(ctx context.Context, payment *model.PaymentOrd
|
||||
}
|
||||
verify, err := runtimeConfig.Channel.VerifyNotify(params, rawPayload, contentType, authorization)
|
||||
if err != nil || !verify.OK {
|
||||
log.Printf(
|
||||
"[payment] %s notify verify failed payment_id=%d third_order_id=%s got=%s expected=%s keys=%v base_string=%s",
|
||||
runtimeConfig.Provider,
|
||||
payment.ID,
|
||||
params["third_order_id"],
|
||||
verify.Got,
|
||||
firstNonEmpty(verify.Expected["notify_key"], verify.Expected["notify_cert"], verify.Expected["error"]),
|
||||
verify.ParamKeys,
|
||||
firstNonEmpty(verify.BaseString["notify_key"], verify.BaseString["notify_cert"]),
|
||||
)
|
||||
r.log().Warn("payment notify verify failed", paymentLogFields(ctx, appendFields(
|
||||
paymentOrderFields(payment),
|
||||
runtimeConfigFields(runtimeConfig),
|
||||
[]zap.Field{
|
||||
zap.String("sign_got", verify.Got),
|
||||
zap.String("sign_expected", firstNonEmpty(verify.Expected["notify_key"], verify.Expected["notify_cert"], verify.Expected["error"])),
|
||||
zap.Strings("param_keys", verify.ParamKeys),
|
||||
zap.String("sign_base_string", firstNonEmpty(verify.BaseString["notify_key"], verify.BaseString["notify_cert"])),
|
||||
zap.Error(err),
|
||||
},
|
||||
)...,
|
||||
)...)
|
||||
if err := r.recordNotifyDiagnostic(ctx, payment.ID, params, rawPayload, contentType, verify, "verify_failed"); err != nil {
|
||||
log.Printf("[payment] %s notify diagnostic save failed payment_id=%d err=%v", runtimeConfig.Provider, payment.ID, err)
|
||||
r.log().Warn("payment notify diagnostic save failed", paymentLogFields(ctx, appendFields(
|
||||
paymentOrderFields(payment),
|
||||
runtimeConfigFields(runtimeConfig),
|
||||
[]zap.Field{
|
||||
zap.String("diagnostic_status", "verify_failed"),
|
||||
zap.Error(err),
|
||||
},
|
||||
)...,
|
||||
)...)
|
||||
}
|
||||
return verify, ErrPaymentVerifyFailed
|
||||
}
|
||||
log.Printf("[payment] %s notify verified payment_id=%d third_order_id=%s matched_key=%s", runtimeConfig.Provider, payment.ID, params["third_order_id"], verify.MatchedKey)
|
||||
r.log().Info("payment notify verified", paymentLogFields(ctx, appendFields(
|
||||
paymentOrderFields(payment),
|
||||
runtimeConfigFields(runtimeConfig),
|
||||
[]zap.Field{zap.String("matched_key", verify.MatchedKey)},
|
||||
)...,
|
||||
)...)
|
||||
return verify, nil
|
||||
}
|
||||
func (r *Repository) recordNotifyDiagnostic(ctx context.Context, paymentID uint64, params map[string]string, rawPayload string, contentType string, verify channelVerifyNotifyResult, status string) error {
|
||||
|
||||
Reference in New Issue
Block a user