Skip to main content
This guide calls the Polar API from Laravel with the 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 run polar auth token, and add it to .env:
.env
The examples call https://sandbox-api.polar.sh. When you go live, switch to https://api.polar.sh and a production token.

List products

Add a route in routes/web.php:
Then create ProductsController in app/Http/Controllers:
Then create the products view in resources/views:
Each Buy link passes the product ID to /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 to routes/web.php:
The 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:
Link to /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 to routes/web.php:
Then create ConfirmationController in app/Http/Controllers:
The checkout isn’t successful yet when the customer lands here. Its status is 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. With php artisan serve on port 8000:
Terminal
Copy the secret it prints into .env:
.env
When you deploy, create a webhook endpoint in Settings → Webhooks for 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
Add the route to routes/api.php:
Make sure bootstrap/app.php loads routes/api.php:
Spatie’s Webhook Client receives the requests, calls your signature validator, stores each call and queues a job to process it:
Terminal
Publish its config:
Terminal
This creates 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
Then run php artisan migrate.

Set up the queue

Set QUEUE_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 in app/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:
Run php artisan queue:listen to process the jobs.

Track subscriptions

  • Grant access on subscription.active and remove it on subscription.revoked.
  • subscription.canceled doesn’t end access. A customer who cancels usually keeps access until the end of the billing period, when Polar sends subscription.revoked.
To handle access in one place instead, listen to customer.state_changed. See Customer state.

Learn more