Plan picker
The plans with their prices and a checkout button each. Checkout starts in a server action or API route that holds the Stripe key, and the client opens the URL it returns. Web and native call usePlanPicker from @/hooks/use-billing.

Add the components
terminal npx shadcn add button cardInstall the glue
Install the block with
npx better-supabase add billing. The glue items are copied into your app, so edit them as you need.terminal npx shadcn add @better-supabase/use-billingWrite the component
React and shadcn
View in the exampleplan-picker.tsx "use client"; import type { Money } from "better-supabase/commerce"; import { DbException } from "better-supabase"; import { formatMoney } from "better-supabase/commerce"; import { useErrorMessage } from "better-supabase/react"; import { useExtracted, useLocale } from "next-intl"; import type { PlanCatalog } from "@/hooks/use-billing"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { usePlanPicker } from "@/hooks/use-billing"; import { toast } from "@/lib/toast"; import type { PlanOption } from "../billing-queries"; import { loadPlanCatalog, startCheckout } from "../billing-actions"; async function getCatalog(): Promise<PlanCatalog<PlanOption>> { const result = await loadPlanCatalog({}); if (!result.ok) { throw new DbException(result.error); } return result.data; } /** * The plans with a checkout button each. The server renders the catalog; * `choose` runs the `startCheckout` server action, which talks to Stripe, and * sends the browser to the Checkout URL it returns. */ export function PlanPicker({ initial, canManage, }: { initial: PlanCatalog<PlanOption>; canManage: boolean; }) { const t = useExtracted("billing"); const locale = useLocale(); const errorMessage = useErrorMessage(); const { plans, current, pending, choose } = usePlanPicker({ load: getCatalog, initial, checkout: (plan) => startCheckout({ plan }), open: (url) => { window.location.assign(url); }, }); const price = (value: Money) => value.amount === 0n ? t("Free") : t("{price} per month", { price: formatMoney(value, locale) }); const featureLabel = ({ key, value }: PlanOption["features"][number]) => { switch (key) { case "seats": { return t("{seats} seats", { seats: String(value) }); } case "exports": { return t("CSV exports"); } case "audit": { return t("Audit log"); } case "sso": { return t("Single sign-on"); } default: { return key; } } }; return ( <div className="grid gap-4 md:grid-cols-3"> {(plans ?? initial.plans).map((plan) => { const active = plan.key === current; return ( <Card key={plan.key} size="sm" data-testid="plan"> <CardHeader> <CardTitle>{plan.name}</CardTitle> <CardDescription>{price(plan.price)}</CardDescription> </CardHeader> <CardContent> <ul className="space-y-1 text-sm text-muted-foreground"> {plan.features.map((feature) => ( <li key={feature.key}>{featureLabel(feature)}</li> ))} </ul> </CardContent> <CardFooter> <Button className="w-full" variant={active ? "secondary" : "default"} data-testid={active ? "active-plan" : undefined} disabled={active || !canManage || pending !== undefined} onClick={() => { void choose(plan.key).then((started) => { if (!started.ok) { toast.error(errorMessage(started.error)); } return started; }); }} > {active ? t("Current plan") : pending === plan.key ? t("Opening checkout") : t("Switch")} </Button> </CardFooter> </Card> ); })} </div> ); }