What you’re setting up
Four things to make Polar work:- Products inside Polar
- Checkout links your users can click
- A webhook endpoint Polar can call
- A way for the repo to know what each product means
Env vars
Setup
Create products in Polar
Head to your Polar dashboard and create the products you want to sell.For your first setup, keep it simple:
- One Medium plan product
- One Small credits product
plan-medium or credits-small.Create checkout links
Once your products are ready, create hosted checkout links in Polar and add them to These are the links your app will use for payment buttons.
.env.local:Tell the repo what each product means
You have two ways to do this. Pick whichever you prefer.
- Option A: Metadata (recommended)
- Option B: Product map in env
Add a The repo reads this directly. It’s the cleanest approach because the payment already says what it is.
type field to your Polar product or order metadata:How it works under the hood
When Polar sends a successful webhook:- The repo verifies the webhook signature
- It reads the purchase type from metadata or
POLAR_PRODUCT_MAP - It stores the purchase in the
purchasestable - It tries to match the purchase to a user (using external customer ID if available)
- It updates credits or purchase state
A quick example
Say you want to sell one credits pack through Polar. Here’s everything you’d set:- The checkout button sends them to Polar
- Polar charges them
- Polar calls your webhook
- The repo recognizes
credits-small - The repo adds the correct number of credits
Verify your setup
Your Polar setup is working if all of these are true:
- The app opens the Polar checkout page
- Polar shows a successful webhook delivery
- A row appears in your
purchasestable - A credits purchase increases the user’s credits
- A plan purchase updates the user’s access state
Created the product but nothing shows in the app
Created the product but nothing shows in the app
You probably forgot to save the checkout URL in your
.env.local file. Without it, the app can’t build payment buttons.Checkout works but purchases aren't recorded
Checkout works but purchases aren't recorded
You configured checkout but forgot the webhook. The webhook is what tells your app the payment happened — without it, your app is in the dark.
Webhook fires but purchase type is unknown
Webhook fires but purchase type is unknown
Make sure you’ve mapped the Polar product to a valid purchase type, either via metadata or
POLAR_PRODUCT_MAP. If neither is set, the repo can’t determine what was bought.Changed env vars but nothing changed
Changed env vars but nothing changed
Restart your dev server. Next.js doesn’t hot-reload environment variable changes.
Webhook works locally but not in production
Webhook works locally but not in production
Check that the webhook URL in Polar points to your production domain, not
localhost or a dev tunnel URL.Payments Overview
Go back to the shared payment architecture and basics.

