🔧 fix: normalize epay error handling and webhook retries

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.
This commit is contained in:
t0ng7u
2026-02-03 00:23:51 +08:00
parent 6b694c9c94
commit 49ac355357

View File

@@ -77,7 +77,7 @@ func SubscriptionRequestEpay(c *gin.Context) {
client := GetEpayClient() client := GetEpayClient()
if client == nil { if client == nil {
c.JSON(http.StatusOK, gin.H{"message": "error", "data": "当前管理员未配置支付信息"}) common.ApiErrorMsg(c, "当前管理员未配置支付信息")
return return
} }
@@ -91,7 +91,7 @@ func SubscriptionRequestEpay(c *gin.Context) {
ReturnUrl: returnUrl, ReturnUrl: returnUrl,
}) })
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{"message": "error", "data": "拉起支付失败"}) common.ApiErrorMsg(c, "拉起支付失败")
return return
} }
@@ -105,7 +105,7 @@ func SubscriptionRequestEpay(c *gin.Context) {
Status: common.TopUpStatusPending, Status: common.TopUpStatusPending,
} }
if err := order.Insert(); err != nil { if err := order.Insert(); err != nil {
c.JSON(http.StatusOK, gin.H{"message": "error", "data": "创建订单失败"}) common.ApiErrorMsg(c, "创建订单失败")
return return
} }
c.JSON(http.StatusOK, gin.H{"message": "success", "data": params, "url": uri}) c.JSON(http.StatusOK, gin.H{"message": "success", "data": params, "url": uri})
@@ -128,14 +128,17 @@ func SubscriptionEpayNotify(c *gin.Context) {
return return
} }
if verifyInfo.TradeStatus == epay.StatusTradeSuccess { if verifyInfo.TradeStatus != epay.StatusTradeSuccess {
LockOrder(verifyInfo.ServiceTradeNo) _, _ = c.Writer.Write([]byte("fail"))
defer UnlockOrder(verifyInfo.ServiceTradeNo) return
}
if err := model.CompleteSubscriptionOrder(verifyInfo.ServiceTradeNo, common.GetJsonString(verifyInfo)); err != nil { LockOrder(verifyInfo.ServiceTradeNo)
_, _ = c.Writer.Write([]byte("fail")) defer UnlockOrder(verifyInfo.ServiceTradeNo)
return
} if err := model.CompleteSubscriptionOrder(verifyInfo.ServiceTradeNo, common.GetJsonString(verifyInfo)); err != nil {
_, _ = c.Writer.Write([]byte("fail"))
return
} }
_, _ = c.Writer.Write([]byte("success")) _, _ = c.Writer.Write([]byte("success"))