Http client: it lists products, sends customers to checkout and handles webhooks. It uses API version 2026-10. For a ready-made package with a Billable trait, Blade components and webhook handling, see the community-maintained Laravel adapter.
Build against the sandbox first. Nothing there moves real money. The complete code is in the polar-laravel example on GitHub.
Set the access token
Create an organization access token in your sandbox organization’s Settings → Access Tokens, or runpolar auth token, and add it to .env:
.env
https://sandbox-api.polar.sh. When you go live, switch to https://api.polar.sh and a production token.
List products
Add a route inroutes/web.php:
ProductsController in app/Http/Controllers:
products view in resources/views:
/checkout, which you add next.
Create a Checkout Session
This route creates a Checkout Session, redirects the customer to it, and sends them to a confirmation page after payment. Add it toroutes/web.php:
auth middleware sends visitors who aren’t signed in to your login page first, so every checkout belongs to one of your users. If your app has no login yet, add one with a Laravel starter kit. To sell to guests instead, drop the middleware and the external_customer_id line below.
Then create CheckoutController in app/Http/Controllers:
/checkout?productId=<product_id>, as the products page does. After payment, Polar redirects the customer to the confirmation page. external_customer_id links the Polar customer to your signed-in user, so you can look them up by your own ID later.
Show a confirmation page
Add the route toroutes/web.php:
ConfirmationController in app/Http/Controllers:
confirmed until the payment goes through and it becomes succeeded. Polar sends a checkout.updated webhook when that happens, so rely on webhooks, not this page, to grant access.
Receive webhooks
Webhooks keep your database in sync with checkouts, orders and subscriptions.Forward webhooks locally
The Polar CLI forwards your sandbox organization’s webhooks to your local server. Withphp artisan serve on port 8000:
Terminal
.env:
.env
https://<your-domain>/api/webhook/polar and use that endpoint’s secret instead. See Webhook events for the events you can subscribe to.
Install the packages
Install the Standard Webhooks library, which verifies signatures:Terminal
routes/api.php:
bootstrap/app.php loads routes/api.php:
Terminal
Terminal
config/webhook-client.php. Point it at your secret, validator and job:
Prepare the database
The client stores every webhook call in the database. Publish its migration:Terminal
php artisan migrate.
Set up the queue
SetQUEUE_CONNECTION=database in .env, or use another connection such as Redis. Create the jobs table with php artisan queue:table, then run php artisan migrate.
Create the handlers
Create two files inapp/Handler: PolarSignature.php and ProcessWebhook.php.
PolarSignature checks that the request came from Polar. It tries Standard Webhooks first, with the secret as-is, then Polar’s original HMAC scheme, with the full whsec_… string base64-encoded. See Custom validation.
ProcessWebhook extends ProcessWebhookJob, which holds the stored webhook call:
php artisan queue:listen to process the jobs.
Track subscriptions
- Grant access on
subscription.activeand remove it onsubscription.revoked. subscription.canceleddoesn’t end access. A customer who cancels usually keeps access until the end of the billing period, when Polar sendssubscription.revoked.
customer.state_changed. See Customer state.

