fix confirmed deployment risks
This commit is contained in:
@@ -80,7 +80,7 @@ func (h *PaymentWebhookHandler) handleNotify(c *gin.Context, providerKey string)
|
||||
provider, err := h.paymentService.GetWebhookProvider(c.Request.Context(), providerKey, outTradeNo)
|
||||
if err != nil {
|
||||
slog.Warn("[Payment Webhook] provider not found", "provider", providerKey, "outTradeNo", outTradeNo, "error", err)
|
||||
writeSuccessResponse(c, providerKey)
|
||||
writeUnavailableResponse(c, providerKey)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -137,12 +137,22 @@ type wxpaySuccessResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type wxpayFailureResponse struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// WeChat Pay webhook success response constants.
|
||||
const (
|
||||
wxpaySuccessCode = "SUCCESS"
|
||||
wxpaySuccessMessage = "成功"
|
||||
)
|
||||
|
||||
const (
|
||||
wxpayFailureCode = "FAIL"
|
||||
unavailableMessage = "provider unavailable"
|
||||
)
|
||||
|
||||
// writeSuccessResponse sends the provider-specific success response.
|
||||
// WeChat Pay requires JSON {"code":"SUCCESS","message":"成功"};
|
||||
// Stripe expects an empty 200; others accept plain text "success".
|
||||
@@ -156,3 +166,14 @@ func writeSuccessResponse(c *gin.Context, providerKey string) {
|
||||
c.String(http.StatusOK, "success")
|
||||
}
|
||||
}
|
||||
|
||||
func writeUnavailableResponse(c *gin.Context, providerKey string) {
|
||||
switch providerKey {
|
||||
case payment.TypeWxpay:
|
||||
c.JSON(http.StatusServiceUnavailable, wxpayFailureResponse{Code: wxpayFailureCode, Message: unavailableMessage})
|
||||
case payment.TypeStripe:
|
||||
c.String(http.StatusServiceUnavailable, "")
|
||||
default:
|
||||
c.String(http.StatusServiceUnavailable, unavailableMessage)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user