Source: https://datafa.st/docs/stripe-checkout-api
Markdown source: https://datafa.st/docs/stripe-checkout-api.md
Description: Set up revenue attribution with Stripe Checkout API. Pass DataFast cookies as metadata for accurate marketing channel attribution.

# Attribute revenue with Stripe Checkout API

← [Revenue attribution guide](/docs/revenue-attribution-guide)

# Attribute revenue with Stripe Checkout API

> Make sure you've [connected your Stripe account](/docs/connect-payment-provider) first.

Pass `metadata` with `datafast_visitor_id` and `datafast_session_id` (cookies from DataFast) when creating a checkout session:

```javascript
// app/api/create-checkout/route.js
import { cookies } from 'next/headers';

export async function POST() {
  const cookieStore = cookies();
  // If you're using Next.js 15+, use this instead:
  // const cookieStore = await cookies();
  
  const session = await stripe.checkout.sessions.create({
    line_items: [...],
    metadata: {
      datafast_visitor_id: cookieStore.get('datafast_visitor_id')?.value,
      datafast_session_id: cookieStore.get('datafast_session_id')?.value
    }
  });
  
  return new Response(JSON.stringify({ sessionId: session.id }), {
    status: 200,
    headers: { 'Content-Type': 'application/json' }
  });
}
```

Once connected and metadata is properly passed, DataFast will automatically attribute revenue to the correct marketing channels. **No webhook setup is required**.

> After receiving a successful payment, you should see revenue data in your dashboard (referrer, country, browser, etc.).
