In cookie mode, read _tb_vid and _tb_sid on your server and put them on the Stripe Checkout Session. For a subscription, also put them on subscription_data.metadata. This excerpt assumes your existing Stripe client, validated price and redirect URLs.
// Add this to your existing server-side Stripe checkout.
// Keep your authentication, validated price and redirect URLs.
import { cookies } from "next/headers";
const jar = await cookies();
const visitor = jar.get("_tb_vid")?.value;
const session = jar.get("_tb_sid")?.value;
const ids = {
...(visitor && { twelvebit_visitor_id: visitor }),
...(session && { twelvebit_session_id: session }),
};
const checkout = await stripe.checkout.sessions.create({
mode: "subscription",
line_items: [{ price: validatedPriceId, quantity: 1 }],
success_url: successUrl,
cancel_url: cancelUrl,
metadata: { ...ids, plan: "pro" },
subscription_data: { metadata: { ...ids, plan: "pro" } },
});For a one-time payment, use mode: payment and payment_intent_data.metadata instead of subscription_data. Receive payment revenue through the connected provider; do not send the same payment again through the payments API. The full Stripe guide explains the integration.
