'use client' /** * Return page after Embedded Checkout. * Stripe redirects here with ?session_id={CHECKOUT_SESSION_ID}. * Fetches session status and redirects to dashboard on success. */ import { Suspense, useEffect, useState } from 'react' import { useRouter, useSearchParams } from 'next/navigation' import { getCheckoutSessionStatus } from '@/lib/api/billing' import { LoadingOverlay } from '@ciphera-net/ui' import Link from 'next/link' function CheckoutReturnContent() { const router = useRouter() const searchParams = useSearchParams() const sessionId = searchParams.get('session_id') const [status, setStatus] = useState<'loading' | 'complete' | 'open' | 'error'>('loading') const [errorMessage, setErrorMessage] = useState('') useEffect(() => { if (!sessionId) { setStatus('error') setErrorMessage('Missing session ID') return } let cancelled = false async function check() { try { const data = await getCheckoutSessionStatus(sessionId!) if (cancelled) return if (data.status === 'complete') { setStatus('complete') router.replace('/') return } if (data.status === 'open') { setStatus('open') setErrorMessage('Payment was not completed. You can try again.') return } setStatus('error') setErrorMessage('Unexpected session status. Please contact support if you were charged.') } catch (err) { if (cancelled) return setStatus('error') setErrorMessage((err as Error)?.message || 'Failed to verify payment') } } check() return () => { cancelled = true } }, [sessionId, router]) if (status === 'loading') { return } if (status === 'complete') { return } return (

{status === 'open' ? 'Payment not completed' : 'Something went wrong'}

{errorMessage}

Back to pricing Go to dashboard
) } export default function CheckoutReturnPage() { return ( }> ) }