Stripe PaymentIntent API

Pass attribu.tech cookies as metadata when creating PaymentIntents for custom checkout flows built with Stripe Elements.

← Revenue attribution

Make sure you've connected Stripe in your attribu.tech dashboard first. You need a restricted API key linked before payments can be attributed.

Next.js example

Read the attribu_visitor_id and attribu_session_id cookies on the server and pass them as metadata when creating the PaymentIntent:

// app/api/payment/route.ts
import { cookies } from "next/headers";
import Stripe from "stripe";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function POST(req: Request) {
  const { amount } = await req.json();
  const cookieStore = await cookies();

  const paymentIntent = await stripe.paymentIntents.create({
    amount,
    currency: "usd",
    metadata: {
      attribu_visitor_id: cookieStore.get("attribu_visitor_id")?.value || "",
      attribu_session_id: cookieStore.get("attribu_session_id")?.value || "",
    },
  });

  return Response.json({ clientSecret: paymentIntent.client_secret });
}
The metadata field on the PaymentIntent carries through to the resulting charge. attribu.tech reads it from the charge.succeeded webhook.

How it works

Once connected, attribu.tech automatically attributes revenue to the traffic source that brought the visitor. No webhook setup needed on your end -- attribu.tech handles that when you connect your Stripe key.

When to use

  • Custom checkout flows -- when you build your own payment form with Stripe Elements
  • Mobile SDKs -- when you create PaymentIntents server-side for mobile apps
  • Server-side charges -- any flow where you create a PaymentIntent directly

If you use Stripe Checkout (the hosted payment page), see the Checkout Session guide instead. If you use Stripe Payment Links, see the Payment Links guide.

Copied