Recipes
Next.js and Stripe Checkout
A SaaS on Next.js with Stripe subscriptions: capture the partner, tag the Stripe customer and let Intrio credit every invoice.
This recipe needs no Intrio API key, so it works on every plan. Stripe reports each paid invoice; you only make sure the customer carries the partner.
1. Load the script#
import Script from "next/script";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script src="https://intrio.co/sdk.js" data-key={process.env.NEXT_PUBLIC_INTRIO_KEY} strategy="afterInteractive" />
</body>
</html>
);
}2. Read the partner on the server#
The pp_attr cookie is sent with requests to your own domain, so a server action or route handler can read it.
import { cookies } from "next/headers";
export async function partnerFromCookie() {
const raw = (await cookies()).get("pp_attr")?.value;
if (!raw) return { ref: "", click: "" };
try {
const a = JSON.parse(decodeURIComponent(raw)) as { ref?: string; click?: string | null };
return { ref: a.ref ?? "", click: a.click ?? "" };
} catch {
return { ref: "", click: "" };
}
}3. Tag the customer when starting Checkout#
"use server";
import Stripe from "stripe";
import { redirect } from "next/navigation";
import { partnerFromCookie } from "@/lib/intrio";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function startCheckout(userId: string, email: string, priceId: string) {
const { ref, click } = await partnerFromCookie();
const customer = await stripe.customers.create({
email,
metadata: { app_user_id: userId, pp_programme: "app", pp_ref: ref, pp_click: click },
});
const session = await stripe.checkout.sessions.create({
mode: "subscription",
customer: customer.id,
line_items: [{ price: priceId, quantity: 1 }],
success_url: "https://example.com/welcome",
cancel_url: "https://example.com/pricing",
});
redirect(session.url!);
}Creating the customer yourself (rather than letting Checkout create it) means the metadata is there before the first invoice is paid. Letting Checkout create the customer also works: pass client_reference_id from intrio.clientReferenceId() and Intrio credits the first invoice from checkout.session.completed and tags the new customer for the rest.
4. Connect Stripe in Intrio#
Open Integrations and connect the same Stripe account. From now on each paid invoice is recorded for the tagged customer and refunds are reversed. Optionally, on Growth and above, report the sign-up itself with trackLead so partners see the sign-up before the first payment.
Last updated 20 November 2026. Building with an AI assistant? Point it at /docs/llms-full.txt.