diff --git a/web/src/features/subscriptions/components/dialogs/subscription-purchase-dialog.tsx b/web/src/features/subscriptions/components/dialogs/subscription-purchase-dialog.tsx index 1c127c1d32e3..05d4949d6724 100644 --- a/web/src/features/subscriptions/components/dialogs/subscription-purchase-dialog.tsx +++ b/web/src/features/subscriptions/components/dialogs/subscription-purchase-dialog.tsx @@ -36,6 +36,7 @@ import { import { Separator } from '@/components/ui/separator' import { useSystemConfig } from '@/hooks/use-system-config' import { formatQuota } from '@/lib/format' +import { redirectToStripeCheckout } from '@/lib/stripe-checkout' import { DEFAULT_CURRENCY_CONFIG } from '@/stores/system-config-store' import { @@ -119,9 +120,8 @@ export function SubscriptionPurchaseDialog(props: Props) { try { const res = await paySubscriptionStripe({ plan_id: plan.id }) if (res.message === 'success' && res.data?.pay_link) { - window.open(res.data.pay_link, '_blank') - toast.success(t('Payment page opened')) - props.onOpenChange(false) + toast.success(t('Redirecting to payment page...')) + redirectToStripeCheckout(res.data.pay_link) } else { toast.error( res.message && res.message !== 'success' diff --git a/web/src/features/wallet/hooks/use-payment.ts b/web/src/features/wallet/hooks/use-payment.ts index eb228a94f489..42fab77c28fa 100644 --- a/web/src/features/wallet/hooks/use-payment.ts +++ b/web/src/features/wallet/hooks/use-payment.ts @@ -20,6 +20,8 @@ import i18next from 'i18next' import { useState, useCallback } from 'react' import { toast } from 'sonner' +import { redirectToStripeCheckout } from '@/lib/stripe-checkout' + import { calculateAmount, calculateStripeAmount, @@ -131,8 +133,8 @@ export function usePayment() { // Handle Stripe payment if (isStripe && response.data?.pay_link) { - window.open(response.data.pay_link as string, '_blank') toast.success(i18next.t('Redirecting to payment page...')) + redirectToStripeCheckout(response.data.pay_link as string) return true } diff --git a/web/src/lib/stripe-checkout.ts b/web/src/lib/stripe-checkout.ts new file mode 100644 index 000000000000..8afc142673bf --- /dev/null +++ b/web/src/lib/stripe-checkout.ts @@ -0,0 +1,26 @@ +/* +Copyright (C) 2023-2026 QuantumNous + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + +For commercial licensing, please contact support@quantumnous.com +*/ +/** + * Continue an asynchronously-created Stripe Checkout in the active tab. + * Browsers can block a new tab once the initiating user gesture has crossed + * an await boundary. + */ +export function redirectToStripeCheckout(checkoutUrl: string): void { + window.location.href = checkoutUrl +}