Background
⌘K

Polar Checkout API

Learn how to pass Affonso referral data to Polar Checkout sessions for proper commission tracking.

Silvestro
Written by Silvestro
Updated more than a month ago

Polar Checkout API Integration

💡 Make sure your Polar account is connected.

Pass the affonso_referral cookie as metadata to your Polar Checkout session:

import { cookies } from 'next/headers';

// Get Affonso referral cookie (Next.js 15+)
// For Next.js 13-14: const cookieStore = cookies(); (without await)
const cookieStore = await cookies();
const affonsoReferral = cookieStore.get('affonso_referral')?.value || '';

// Create checkout session with Polar
const checkout = await polar.checkouts.create({
  // ... your existing config
  metadata: {
    affonso_referral: affonsoReferral, // Add this line
  },
});

Testing

  1. Visit your site with ?atp=test (our test affiliate parameter)
  2. Check browser DevTools → ApplicationCookies → look for affonso_referral
  3. Trigger your checkout flow locally
  4. Check your server logs/terminal - the Polar session should show:
    metadata: { affonso_referral: "cmdhq6ayf..." }
  5. If the metadata appears in your logs, you're all set!

Note: Use 100% discount codes for live testing without payments, or test locally with server logs - Polar test mode won't appear in Affonso.

Was this article helpful?

If you still need help, our support team is here for you.

Contact Support
bg

Ready to Scale Your SaaS?

Affonso is the easiest way to launch your own affiliate program. We take care of the technical stuff, so you can focus on growing your business.