Skip to content

fix: redirect subscription payment return to user-accessible page - #3052

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/redirect-payment-url
Feb 28, 2026
Merged

fix: redirect subscription payment return to user-accessible page#3052
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/redirect-payment-url

Conversation

@seefs001

@seefs001 seefs001 commented Feb 28, 2026

Copy link
Copy Markdown
Collaborator

fix #3048

Summary by CodeRabbit

  • Bug Fixes
    • Updated subscription payment processing redirect paths to ensure proper console navigation for success, error, and pending payment states.

@coderabbitai

coderabbitai Bot commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The pull request updates redirect URLs in the subscription Epay payment handler from /console/subscription to /console/topup. This addresses a permission issue where regular users received "unauthorized access" errors after successful payments, redirecting them to an admin-restricted page instead of a user-accessible callback page.

Changes

Cohort / File(s) Summary
Epay Subscription Payment Redirects
controller/subscription_payment_epay.go
Updated all redirect paths in payment flow handlers (error, success, and pending states) from /console/subscription to /console/topup to resolve permission restrictions for regular users on the callback page.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A hop, a skip, a payment flow,
Through Epay's path, the payments go,
From subscription's locked, restricted door,
To topup's welcoming, open shore! 💳✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: redirect subscription payment return to user-accessible page' directly matches the core fix in the changeset: redirecting payment callbacks to /console/topup instead of /console/subscription.
Linked Issues check ✅ Passed The PR changes all redirects from /console/subscription to /console/topup, directly addressing issue #3048's requirement for users to be redirected to an accessible page after payment.
Out of Scope Changes check ✅ Passed All changes in controller/subscription_payment_epay.go are focused on redirecting payment callbacks from the restricted /console/subscription to /console/topup, with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75fa039 and 24b4271.

📒 Files selected for processing (1)
  • controller/subscription_payment_epay.go

@Calcium-Ion
Calcium-Ion merged commit 1723126 into QuantumNous:main Feb 28, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…t-url

fix: redirect subscription payment return to user-accessible page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

订阅支付后,易支付回调页面提示无权限

2 participants