Skip to content

fix(topup): use theme-aware return URLs for epay and stripe#4620

Open
pholex wants to merge 1 commit intoQuantumNous:mainfrom
pholex:fix/return-url-theme-aware
Open

fix(topup): use theme-aware return URLs for epay and stripe#4620
pholex wants to merge 1 commit intoQuantumNous:mainfrom
pholex:fix/return-url-theme-aware

Conversation

@pholex
Copy link
Copy Markdown

@pholex pholex commented May 5, 2026

Problem

The default frontend (v1) introduced in v1.0.0-rc.1 reorganized routes to drop the /console/ prefix:

Page classic default (v1)
Usage logs /console/log /usage-logs
Topup/wallet /console/topup /wallet

But payment-related controllers (controller/topup.go, controller/topup_stripe.go) still hardcode the classic paths for return / success / cancel URLs. This causes a 404 in the v1 UI after the user completes payment, since the v1 router does not recognize /console/log or /console/topup.

Reproduction (with default frontend active):

  1. Configure epay or Stripe in admin
  2. Buy a top-up via the user-facing topup page
  3. Complete payment in the provider's flow
  4. Land back on the new-api domain → 404

Fix

Select the appropriate path at request time based on common.GetTheme(). Classic paths remain the fallback so existing classic deployments are unaffected.

returnPath := "/console/log"
if common.GetTheme() == "default" {
    returnPath = "/usage-logs"
}

common.GetTheme() reads an atomic value updated when the admin toggles the frontend in 设置 → 其他设置 → 切换到新版前端, so the change takes effect immediately without restarting.

Affected URLs

Caller Field classic default
controller/topup.go epay return /console/log /usage-logs
controller/topup_stripe.go stripe success /console/log /usage-logs
controller/topup_stripe.go stripe cancel /console/topup /wallet

Tested

  • Deployed to a sandbox environment with theme.frontend=default.
  • Completed an epay→Alipay-sandbox top-up; browser correctly lands on /usage-logs (HTTP 200) showing the new top-up record. Async notify and quota credit work end-to-end.
  • Compiles cleanly with go build ./controller/.

Compatibility

  • Classic frontend deployments: no behavior change (path unchanged).
  • Default (v1) frontend deployments: 404 → working page.
  • Existing custom success_url / cancel_url overrides on Stripe still take precedence; the conditional only affects the empty-URL fallback.

The default frontend (v1) reorganized routes to drop the `/console/`
prefix, so paths like `/console/log` and `/console/topup` no longer
exist there. Payment return/cancel URLs were still hardcoded to the
classic paths, causing 404s when users return to new-api after
completing payment on the v1 UI.

This selects the appropriate path at request time based on
`common.GetTheme()`:
- epay return_url:    /usage-logs (default) | /console/log (classic)
- stripe success URL: /usage-logs (default) | /console/log (classic)
- stripe cancel URL:  /wallet (default) | /console/topup (classic)

The classic paths remain the fallback, so existing classic
deployments are unaffected. Theme switching takes effect immediately
since GetTheme() reads an atomic value updated when the admin flips
the frontend setting.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dbc562c7-e096-4720-a195-df8a1b01547e

📥 Commits

Reviewing files that changed from the base of the PR and between dac55f0 and 0aee295.

📒 Files selected for processing (2)
  • controller/topup.go
  • controller/topup_stripe.go

Walkthrough

The PR adds theme-aware logic to payment return URLs. RequestEpay and genStripeLink now select redirect paths based on common.GetTheme(), using /usage-logs for "default" theme and /console/log or /console/topup otherwise, replacing hardcoded paths.

Changes

Theme-Based Payment Redirect URLs

Layer / File(s) Summary
Core Logic
controller/topup.go, controller/topup_stripe.go
RequestEpay and genStripeLink conditionally select return/redirect paths: /usage-logs and /wallet for "default" theme, /console/log and /console/topup otherwise.
Integration
controller/topup.go, controller/topup_stripe.go
Paths are combined with system_setting.ServerAddress to construct final return/redirect URLs only when custom URLs are not provided.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • QuantumNous/new-api#2745: Both PRs modify redirect URL handling for payments — they change default/returned success/cancel ReturnUrl logic in controller/topup_stripe.go (and related topup controller).
  • QuantumNous/new-api#2124: Both PRs modify top-up redirect URLs and specifically change defaults in controller/topup_stripe.go (Stripe success/cancel targets).
  • QuantumNous/new-api#1807: Both PRs modify the Stripe redirect target in genStripeLink (changing/choosing between "/log" and "/console/log").

Suggested reviewers

  • seefs001

Poem

🐰 A theme-aware hop through payment flows so bright,
Default paths dance left, alternate paths dance right,
E-pay and Stripe now sing in sync with theme,
No hardcoded URLs to spoil the dream!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: making return URLs theme-aware in topup controllers for both epay and stripe integrations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

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.

1 participant