From 49ac3553572725479eab7c8ad2a9905227510bbc Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Tue, 3 Feb 2026 00:23:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20normalize=20epay=20error?= =?UTF-8?q?=20handling=20and=20webhook=20retries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Standardize SubscriptionRequestEpay error responses via ApiErrorMsg for a consistent schema. Return "fail" on non-success trade statuses in the epay webhook to preserve retry behavior. --- controller/subscription_payment_epay.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/controller/subscription_payment_epay.go b/controller/subscription_payment_epay.go index 41483af76..8b613dcd4 100644 --- a/controller/subscription_payment_epay.go +++ b/controller/subscription_payment_epay.go @@ -77,7 +77,7 @@ func SubscriptionRequestEpay(c *gin.Context) { client := GetEpayClient() if client == nil { - c.JSON(http.StatusOK, gin.H{"message": "error", "data": "当前管理员未配置支付信息"}) + common.ApiErrorMsg(c, "当前管理员未配置支付信息") return } @@ -91,7 +91,7 @@ func SubscriptionRequestEpay(c *gin.Context) { ReturnUrl: returnUrl, }) if err != nil { - c.JSON(http.StatusOK, gin.H{"message": "error", "data": "拉起支付失败"}) + common.ApiErrorMsg(c, "拉起支付失败") return } @@ -105,7 +105,7 @@ func SubscriptionRequestEpay(c *gin.Context) { Status: common.TopUpStatusPending, } if err := order.Insert(); err != nil { - c.JSON(http.StatusOK, gin.H{"message": "error", "data": "创建订单失败"}) + common.ApiErrorMsg(c, "创建订单失败") return } c.JSON(http.StatusOK, gin.H{"message": "success", "data": params, "url": uri}) @@ -128,14 +128,17 @@ func SubscriptionEpayNotify(c *gin.Context) { return } - if verifyInfo.TradeStatus == epay.StatusTradeSuccess { - LockOrder(verifyInfo.ServiceTradeNo) - defer UnlockOrder(verifyInfo.ServiceTradeNo) + if verifyInfo.TradeStatus != epay.StatusTradeSuccess { + _, _ = c.Writer.Write([]byte("fail")) + return + } - if err := model.CompleteSubscriptionOrder(verifyInfo.ServiceTradeNo, common.GetJsonString(verifyInfo)); err != nil { - _, _ = c.Writer.Write([]byte("fail")) - return - } + LockOrder(verifyInfo.ServiceTradeNo) + defer UnlockOrder(verifyInfo.ServiceTradeNo) + + if err := model.CompleteSubscriptionOrder(verifyInfo.ServiceTradeNo, common.GetJsonString(verifyInfo)); err != nil { + _, _ = c.Writer.Write([]byte("fail")) + return } _, _ = c.Writer.Write([]byte("success"))