fix: redirect subscription payment return to user-accessible page - #3052
Conversation
WalkthroughThe pull request updates redirect URLs in the subscription Epay payment handler from Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
controller/subscription_payment_epay.go (1)
169-215: Consider extracting a small redirect helper to avoid repeated URL literals.This is optional, but it reduces copy/paste drift if the route changes again.
♻️ Optional refactor
func SubscriptionEpayReturn(c *gin.Context) { var params map[string]string + redirectPayStatus := func(status string) { + c.Redirect(http.StatusFound, fmt.Sprintf("%s/console/topup?pay=%s", system_setting.ServerAddress, status)) + } if c.Request.Method == "POST" { // POST 请求:从 POST body 解析参数 if err := c.Request.ParseForm(); err != nil { - c.Redirect(http.StatusFound, system_setting.ServerAddress+"/console/topup?pay=fail") + redirectPayStatus("fail") return } @@ if len(params) == 0 { - c.Redirect(http.StatusFound, system_setting.ServerAddress+"/console/topup?pay=fail") + redirectPayStatus("fail") return } @@ client := GetEpayClient() if client == nil { - c.Redirect(http.StatusFound, system_setting.ServerAddress+"/console/topup?pay=fail") + redirectPayStatus("fail") return } verifyInfo, err := client.Verify(params) if err != nil || !verifyInfo.VerifyStatus { - c.Redirect(http.StatusFound, system_setting.ServerAddress+"/console/topup?pay=fail") + redirectPayStatus("fail") return } @@ defer UnlockOrder(verifyInfo.ServiceTradeNo) if err := model.CompleteSubscriptionOrder(verifyInfo.ServiceTradeNo, common.GetJsonString(verifyInfo)); err != nil { - c.Redirect(http.StatusFound, system_setting.ServerAddress+"/console/topup?pay=fail") + redirectPayStatus("fail") return } - c.Redirect(http.StatusFound, system_setting.ServerAddress+"/console/topup?pay=success") + redirectPayStatus("success") return } - c.Redirect(http.StatusFound, system_setting.ServerAddress+"/console/topup?pay=pending") + redirectPayStatus("pending") }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@controller/subscription_payment_epay.go` around lines 169 - 215, Extract a small helper inside SubscriptionEpayReturn (or as a local private function) to centralize redirects to the topup page so the repeated URL literal is not duplicated: add a function like redirectToTopup := func(status string) { c.Redirect(http.StatusFound, system_setting.ServerAddress+"/console/topup?pay="+status); return } and replace every c.Redirect(http.StatusFound, system_setting.ServerAddress+"/console/topup?pay=...") call with redirectToTopup("fail"|"success"|"pending"), keeping the existing control flow (including LockOrder/UnlockOrder and defer semantics) unchanged and using the same symbols SubscriptionEpayReturn, system_setting.ServerAddress, LockOrder, UnlockOrder, and model.CompleteSubscriptionOrder to locate the spots to update.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@controller/subscription_payment_epay.go`:
- Around line 169-215: Extract a small helper inside SubscriptionEpayReturn (or
as a local private function) to centralize redirects to the topup page so the
repeated URL literal is not duplicated: add a function like redirectToTopup :=
func(status string) { c.Redirect(http.StatusFound,
system_setting.ServerAddress+"/console/topup?pay="+status); return } and replace
every c.Redirect(http.StatusFound,
system_setting.ServerAddress+"/console/topup?pay=...") call with
redirectToTopup("fail"|"success"|"pending"), keeping the existing control flow
(including LockOrder/UnlockOrder and defer semantics) unchanged and using the
same symbols SubscriptionEpayReturn, system_setting.ServerAddress, LockOrder,
UnlockOrder, and model.CompleteSubscriptionOrder to locate the spots to update.
…t-url fix: redirect subscription payment return to user-accessible page
fix #3048
Summary by CodeRabbit