Creem Checkout API Integration
💡 Make sure your Creem account is connected.
Pass the affonso_referral
cookie as metadata to your Creem Checkout session:
import { cookies } from 'next/headers';
import axios from 'axios';
// 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 Creem
const response = await axios.post(
'https://api.creem.io/v1/checkouts',
{
request_id: 'your-request-id',
product_id: 'prod_your-product-id',
// ... your existing config
metadata: {
affonso_referral: affonsoReferral, // Add this line
},
},
{
headers: {
'x-api-key': process.env.CREEM_API_KEY,
},
}
);
Testing
- Visit your site with
?atp=test
(our test affiliate parameter) - Check browser DevTools → Application → Cookies → look for
affonso_referral
- Trigger your checkout flow locally
- Check your server logs/terminal - the Creem session should show:
metadata: { affonso_referral: "cmdhq6ayf..." }
- 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 - Creem test mode won't appear in Affonso.