Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion web/src/features/wallet/hooks/use-payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
26 changes: 26 additions & 0 deletions web/src/lib/stripe-checkout.ts
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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
}