feat: integrate Stripe for embedded checkout; update billing API to return client_secret and adjust checkout flow in components

This commit is contained in:
Usman Baig
2026-02-20 03:41:35 +01:00
parent 6d277b126e
commit 0bbbb8a1af
9 changed files with 291 additions and 29 deletions

View File

@@ -16,7 +16,6 @@ import {
type Organization,
type OrganizationMember,
} from '@/lib/api/organization'
import { createCheckoutSession } from '@/lib/api/billing'
import { createSite, type Site } from '@/lib/api/sites'
import { setSessionAction } from '@/app/actions/auth'
import { useAuth } from '@/lib/auth/context'
@@ -218,18 +217,14 @@ function WelcomeContent() {
try {
trackWelcomePlanContinue()
const intent = JSON.parse(raw)
const { url } = await createCheckoutSession({
const params = new URLSearchParams({
plan_id: intent.planId,
interval: intent.interval || 'month',
limit: intent.limit ?? 100000,
limit: String(intent.limit ?? 100000),
})
localStorage.removeItem('pulse_pending_checkout')
if (url) {
setRedirectingCheckout(true)
window.location.href = url
return
}
throw new Error('No checkout URL returned')
setRedirectingCheckout(true)
router.push(`/checkout?${params.toString()}`)
} catch (err: unknown) {
setPlanError(getAuthErrorMessage(err) || (err as Error)?.message || 'Failed to start checkout')
localStorage.removeItem('pulse_pending_checkout')