From b5c399257f814ea8ced4a388de2fbdb4541d714e Mon Sep 17 00:00:00 2001 From: "dmitry.galkin" Date: Mon, 25 May 2026 18:36:12 +0400 Subject: [PATCH] checkout: omit customerEmail when user has guest-style email Stripe rejects emails like 'guest-1779719735974' with 400 email_invalid. Falling back to no email lets Stripe collect it on the checkout page itself, which is the standard flow for unauthenticated upgrades. --- app/(chat)/api/billing/checkout/route.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/(chat)/api/billing/checkout/route.ts b/app/(chat)/api/billing/checkout/route.ts index f518240..8cb3c46 100644 --- a/app/(chat)/api/billing/checkout/route.ts +++ b/app/(chat)/api/billing/checkout/route.ts @@ -26,10 +26,14 @@ export async function POST(request: Request) { const baseUrl = process.env.NEXT_PUBLIC_BASE_URL ?? new URL(request.url).origin; + const rawEmail = session.user.email ?? ""; + const looksLikeEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(rawEmail); + const customerEmail = looksLikeEmail ? rawEmail : undefined; + try { const result = await createCheckoutSession({ userId: session.user.id, - customerEmail: session.user.email ?? undefined, + customerEmail, appSlug, baseUrl, });