'use client' import { useState, type ReactNode } from 'react' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { useToast } from '@/components/ui/use-toast' import type { BillingPlan } from '@/lib/stripe/client' const PRICE: Record = { monthly: { amount: '199 kr', suffix: '/ mån', sub: 'Faktureras månadsvis.', cta: 'Aktivera abonnemang – 199 kr/mån', }, yearly: { amount: '166 kr', suffix: '/ mån', sub: '1 999 kr/år — du betalar för 10 månader.', cta: 'Aktivera årsabonnemang – 1 999 kr/år', }, } /** * Interactive billing CTA. Paying companies get the Stripe Customer Portal * (manage/cancel); everyone else gets a reactive plan picker + Checkout. Both * POST to a route that returns a hosted Stripe URL we redirect to. */ export function BillingActions({ isPaying, configured }: { isPaying: boolean; configured: boolean }) { const { toast } = useToast() const [loading, setLoading] = useState(false) const [plan, setPlan] = useState('yearly') async function go(endpoint: string, payload?: Record) { setLoading(true) try { const res = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload ?? {}), }) const data = (await res.json().catch(() => ({}))) as { url?: string; error?: string } if (!res.ok || !data.url) throw new Error(data.error || 'Något gick fel') window.location.href = data.url } catch (e) { toast({ title: 'Kunde inte öppna betalningen', description: e instanceof Error ? e.message : undefined, variant: 'destructive', }) setLoading(false) } } if (isPaying) { return ( ) } if (!configured) { return ( ) } const segment = (p: BillingPlan, label: ReactNode) => ( ) return (
{PRICE[plan].amount} {PRICE[plan].suffix}

{PRICE[plan].sub}

{segment('monthly', 'Månadsvis')} {segment( 'yearly', <> Årsvis Spara 2 mån , )}

Säker betalning via Stripe · Avsluta när du vill

) }