# Price testing for Polar: test prices with verified revenue

Source: https://leverprice.com/integrations/polar
Updated: 2026-11-17

> Leverprice tests prices on Polar: your server creates each checkout with an ad-hoc price set to the visitor's assigned amount, and an order counts only after Polar's signed order.paid webhook confirms it. You connect the webhook secret, never an access token. One-time orders and a subscription's first payment are verified; renewals never count.

Leverprice runs price tests on Polar checkouts without ever holding a Polar access token. Your server creates each checkout with its own token at the price Leverprice picked for that visitor, and Polar's signed `order.paid` webhook reports the order back. An order counts toward the test only after Leverprice has checked the signature, so the revenue in your results is revenue Polar recorded.

The connection uses the endpoint's webhook secret, which confirms that an event came from Polar and can't call Polar's API. Polar is the [merchant of record](https://leverprice.com/glossary/merchant-of-record) and collects sales tax, so Leverprice counts every order before tax: a buyer's VAT rate never makes one price look better than another.

## How does price testing work on Polar?

1. In Leverprice, you add a product with the price range you'd accept, for example $19 to $49, and start a test. Your current price stays the fallback.
2. Where the price is shown, your server calls `getPrice()` and renders `quote.price`. A signed first-party cookie keeps each visitor on one price.
3. Your checkout route asks again and creates a Polar checkout with an ad-hoc price of `quote.price`, passing `quote.metadata` as the checkout metadata.
4. Polar copies that metadata to the order and sends `order.paid`. Leverprice checks the signature, credits the order to the price the visitor saw and moves traffic toward the price that earns the most per visitor.

No Leverprice script runs in the browser. If Leverprice is slow or down, `getPrice()` returns your fallback price within 500 ms.

## How do I connect Polar webhooks to Leverprice?

1. In Leverprice, open **Payments**, click **Connect provider**, and choose Polar and a mode: Test for the sandbox, Live for production. Leverprice generates a webhook URL.
2. In Polar, go to **Settings → Webhooks** and click **Add Endpoint** ([Polar docs](https://polar.sh/docs/integrate/webhooks/endpoints)). Paste the Leverprice URL and keep the **Raw** format.
3. Let Polar generate a secret or enter your own, and select `order.paid` and `order.refunded`.
4. Paste the same secret into Leverprice.

| Event | What Leverprice does with it |
|---|---|
| `order.paid` | Counts one-time orders and a subscription's first payment |
| `order.refunded` | Takes the refunded amount, before tax, off that price's revenue |

Paste the secret exactly as Polar shows it. Secrets created on or after September 8, 2026 sign with Standard Webhooks and older ones with Polar's earlier HMAC scheme ([Polar docs](https://polar.sh/docs/integrate/webhooks/delivery)), and Leverprice accepts both. A wrong secret gets a 401 from Leverprice, and Polar disables an endpoint after 10 failed deliveries in a row ([Polar docs](https://polar.sh/docs/integrate/webhooks/delivery)), so re-enable it in Polar's webhook settings once the secret is fixed.

*Figure: An order moves from your checkout to Polar, then as a signed webhook to Leverprice, which records a verified purchase. Leverprice is one more webhook endpoint in Polar. Any endpoint you already use keeps receiving the same events.*

## How do I charge the tested price in a Polar checkout?

Pass an ad-hoc price in `prices`, keyed by product ID. Ad-hoc prices exist only for the checkout that creates them and never appear in your catalog ([Polar docs](https://polar.sh/docs/features/checkout/session)). Polar copies the checkout's `metadata` to the resulting order ([API reference](https://polar.sh/docs/api-reference/checkouts/create-session)), which is where Leverprice reads the attribution.

Create the Leverprice client once ([setup details](https://leverprice.com/docs)):

```ts title="lib/leverprice.ts"
import { Leverprice } from "@leverprice/sdk";

export const leverprice = new Leverprice({
  secretKey: process.env.LEVERPRICE_SECRET_KEY, // server only
  products: {
    // Prices outside these bounds are never returned.
    pro: { currency: "usd", fallbackPrice: 2900, minPrice: 1900, maxPrice: 4900 },
  },
});
```

The checkout route uses Polar's TypeScript SDK, pinned to the 2026-10 API version:

```ts title="app/api/checkout/route.ts"
import { createPolar, type models } from "@polar-sh/sdk/2026-10";
import { leverprice } from "@/lib/leverprice";

const polar = createPolar({
  accessToken: process.env.POLAR_ACCESS_TOKEN!,
  environment: process.env.POLAR_SANDBOX === "1" ? "sandbox" : "production",
});

const PRODUCT_ID = process.env.POLAR_PRODUCT_ID!;

export async function POST(request: Request) {
  // Ask again here. Never trust a price sent by the browser.
  const quote = await leverprice.getPrice("pro", { request });

  const checkout = await polar.checkouts.create({
    products: [PRODUCT_ID],
    prices: {
      // An ad-hoc price that exists only for this checkout
      [PRODUCT_ID]: [
        {
          amount_type: "fixed",
          price_amount: quote.price, // cents: 2900 = $29.00
          price_currency: quote.currency as models.PresentmentCurrency,
        },
      ],
    },
    metadata: quote.metadata, // signed attribution: pass it whole
    success_url: "https://example.com/thanks?checkout_id={CHECKOUT_ID}",
  });

  const headers = new Headers({ Location: checkout.url });
  for (const cookie of quote.setCookie) headers.append("Set-Cookie", cookie);
  return new Response(null, { status: 303, headers });
}
```

`price_amount` is in cents, the same minor units as `quote.price`. `quote.metadata` carries four signed values (`pp_exp`, `pp_var`, `pp_vid` and `pp_sig`), and Leverprice drops attribution whose signature doesn't match, so pass the object whole. Before you send live traffic, make one sandbox purchase and check that the order shows the tested amount and lands under its price in Leverprice.

From each order, Leverprice takes `net_amount`, which Polar defines as the amount after discounts and before taxes ([API reference](https://polar.sh/docs/api-reference/orders/get)). The [Next.js guide](https://leverprice.com/guides/nextjs) shows the pricing page and this route together.

## Do Polar subscriptions count as verified revenue?

The first payment does. Leverprice verifies `order.paid` events whose billing reason is `purchase` (a one-time order) or `subscription_create` (a subscription's first payment). Renewals (`subscription_cycle`) and plan changes (`subscription_update`) never count, because they aren't a new decision at the price the visitor saw. Each price is judged on first payments minus refunds.

Polar says a subscription locks in the price it was created with ([Polar docs](https://polar.sh/docs/features/subscriptions/introduction)). Its docs don't spell that out for ad-hoc prices, so before testing a subscription price, check that a sandbox subscription shows the tested amount. To keep everything in the catalog instead, create one product per test price, pick the product ID from `quote.price` on your server and still pass `quote.metadata`.

## What happens when I refund a Polar order?

Polar sends `order.refunded` with the total refunded so far, for full and partial refunds alike. Leverprice takes `refunded_amount` off the price's revenue; it leaves out tax, which Polar reports separately as `refunded_tax_amount`. A full refund turns the order into a refunded purchase that adds nothing to its price, and a partial refund keeps the sale and lowers it. The sale and the refund are both before tax, so partial refunds come out exact.

## Can I test in Polar's sandbox first?

Yes. The sandbox at sandbox.polar.sh is a separate Polar environment with its own organization and access tokens ([Polar docs](https://polar.sh/docs/integrate/sandbox)), so it gets its own webhook endpoint. Connect that endpoint in Leverprice as Test and your production endpoint as Live, and run your app with your `pp_sk_test_…` key while you test.

Polar's payloads carry no test or live flag, so the mode you pick when connecting is what keeps sandbox orders out of live results. For sandbox payments, Polar's docs suggest Stripe's test card 4242 4242 4242 4242 ([Polar docs](https://polar.sh/docs/integrate/sandbox)).

## What if a customer pays in another currency?

An ad-hoc price has a single currency, the `price_currency` you pass, so in the route above the order comes back in the currency of the quote. That also makes [regional prices](https://leverprice.com/blog/regional-pricing) work without extra code: a visitor quoted a price in euros gets an ad-hoc price in euros.

Polar can also price a catalog product in several currencies and pick one from the customer's location ([Polar docs](https://polar.sh/docs/features/products)). Whenever an order's currency differs from the experiment's, Leverprice converts it back at daily reference exchange rates, so the order still counts for the price the visitor was assigned.

## Can I test prices with Polar checkout links and no code?

Yes. For a site without a backend ([no-code price testing](https://leverprice.com/for/no-code)), create one product per test price in Polar, each with its own checkout link, paste each link into Leverprice next to its price, and point your Buy button at the product's Leverprice link (`/l/…`) from the **Install** page. Leverprice assigns the visitor a price, keeps it in a first-party cookie and redirects to that price's link with a signed `reference_id`.

Polar attaches a link's `reference_id` to the checkout's metadata ([Polar docs](https://polar.sh/docs/features/checkout/links)) and copies checkout metadata to the order, where Leverprice reads it. Make one sandbox purchase through the Leverprice link before you send traffic, and check that it shows up under its price. In this mode your page can't show the tested price, and checkout links carry standard prices only.

## What does Leverprice verify on Polar?

| Polar order | Counts toward the test |
|---|---|
| One-time purchase (`purchase`) | Yes, at `net_amount` |
| Subscription's first payment (`subscription_create`) | Yes |
| Start of a free trial | Yes, as a $0 sale |
| Renewal, including the first charge after a trial | No |
| Plan change (`subscription_update`) | No |
| Refund, full or partial | Yes, exact |

Keep free trials out of a test. With a trial, Polar charges nothing at checkout ([Polar docs](https://polar.sh/docs/features/trials)): the subscription's first order is a $0 trial order, and the first real charge arrives later with the billing reason `subscription_cycle` ([Polar source](https://github.com/polarsource/polar/blob/main/server/polar/models/order.py)). Test prices on plans without a trial, or set `allow_trial: false` on the test checkouts ([API reference](https://polar.sh/docs/api-reference/checkouts/create-session)).

## Frequently asked questions

### Does Leverprice need a Polar access token?

No. Your server keeps its organization access token and creates every checkout. Leverprice stores only the webhook secret, encrypted, and that secret can't call Polar's API.

### Do I need a Polar product for every test price?

Not for one-time products. One product is enough, because the route attaches an ad-hoc price to each checkout. You need a product and checkout link per price only in no-code mode, where there is no server to set the price.

### How do Polar's fees affect the result?

With the profit goal, Leverprice compares prices after the provider fee and your unit cost, both set on the product through the API or an AI agent over MCP. Polar's rates are broken down in [Polar fees](https://leverprice.com/blog/polar-fees).

### How long does a price test on Polar take?

It depends mostly on sales volume. In our simulations of the production engine, a price that earned 10% more per visitor took a median of 14 days to find at 1,000 sales a month and 113 days at 100 ([full table](https://leverprice.com/blog/how-long-should-a-price-test-run)).
