From 0aee295c279097e02c61f4414dfc8438dd912ba3 Mon Sep 17 00:00:00 2001 From: Fenghuang Date: Tue, 5 May 2026 21:30:12 +0900 Subject: [PATCH] fix(topup): use theme-aware return URLs for epay and stripe 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. --- controller/topup.go | 6 +++++- controller/topup_stripe.go | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/controller/topup.go b/controller/topup.go index a6445b40d68..c20307acd5e 100644 --- a/controller/topup.go +++ b/controller/topup.go @@ -207,7 +207,11 @@ func RequestEpay(c *gin.Context) { } callBackAddress := service.GetCallbackAddress() - returnUrl, _ := url.Parse(system_setting.ServerAddress + "/console/log") + returnPath := "/console/log" + if common.GetTheme() == "default" { + returnPath = "/usage-logs" + } + returnUrl, _ := url.Parse(system_setting.ServerAddress + returnPath) notifyUrl, _ := url.Parse(callBackAddress + "/api/user/epay/notify") tradeNo := fmt.Sprintf("%s%d", common.GetRandomString(6), time.Now().Unix()) tradeNo = fmt.Sprintf("USR%dNO%s", id, tradeNo) diff --git a/controller/topup_stripe.go b/controller/topup_stripe.go index ceee8ecdd66..631932b52a7 100644 --- a/controller/topup_stripe.go +++ b/controller/topup_stripe.go @@ -346,12 +346,18 @@ func genStripeLink(referenceId string, customerId string, email string, amount i stripe.Key = setting.StripeApiSecret - // Use custom URLs if provided, otherwise use defaults + // Use custom URLs if provided, otherwise use defaults based on the active frontend theme + successPath := "/console/log" + cancelPath := "/console/topup" + if common.GetTheme() == "default" { + successPath = "/usage-logs" + cancelPath = "/wallet" + } if successURL == "" { - successURL = system_setting.ServerAddress + "/console/log" + successURL = system_setting.ServerAddress + successPath } if cancelURL == "" { - cancelURL = system_setting.ServerAddress + "/console/topup" + cancelURL = system_setting.ServerAddress + cancelPath } params := &stripe.CheckoutSessionParams{