# How to A/B test prices without breaking your customers' trust (step by step)

Source: https://leverprice.com/blog/how-to-ab-test-prices
Updated: 2026-11-17

> Keep your current price as the control, add one or two test prices, and give each visitor one price, chosen on your server, that sticks across visits. Render that price, charge exactly that price at checkout with signed metadata, count purchases from your payment provider's webhooks net of refunds, and roll out the price with the highest revenue per visitor.

A price test can fail in two ways. The math fails when you crown the price with the best conversion rate and lose money. The plumbing fails when a visitor sees $29, gets charged $39 and posts the screenshot. Below are the ten steps in the order you would build them, with working TypeScript for Stripe Checkout and a version you can build without any vendor.

*Figure: Flow diagram: a visitor arrives, the server asks for a price, the checkout charges that price, traffic moves to the leader. The loop you are building: one price per visitor, decided on the server and charged at checkout.*

## Step 1: Which metric should pick the winner?

Revenue per visitor: the revenue a price brought in, net of refunds, divided by the number of people who saw that price. With one purchase per buyer it equals price × conversion rate, which is why it can rank prices that conversion rate alone gets backwards.

Example: three prices, 5,000 visitors each.

| Price | Buyers | Conversion rate | Revenue | Revenue per visitor |
|---|---|---|---|---|
| $19 | 200 | 4.0% | $3,800 | $0.76 |
| $29 | 150 | 3.0% | $4,350 | $0.87 |
| $39 | 120 | 2.4% | $4,680 | $0.94 |

The $19 price wins on conversion and comes last on revenue. [The complete guide to price testing](https://leverprice.com/blog/price-testing) covers the adjustments for fees and subscription retention; two details matter for the build.

Count a visitor once, when they actually see a price. Page views, prefetches and bots all inflate the denominator. And subtract each refund from the price group that earned the sale, even when the refund arrives after the test ends.

## Step 2: How do you choose the control and the test prices?

Your current price is the control. Add one or two prices far enough from it that a difference would be detectable, and check each against the break-even rule before you start: moving from an old price to a new one earns more as long as you lose fewer than 1 − old ÷ new of your buyers.

| Test price (control: $29) | Change | Buyers you can lose and still earn the same |
|---|---|---|
| $35 | +20.7% | 17.1% |
| $39 | +34.5% | 25.6% |
| $49 | +69.0% | 40.8% |
| $24 | -17.2% | None: you need 20.8% more buyers |

Then check that you can afford the test. Small differences take far more traffic than large ones. Example, with $29 converting 3% of visitors and a fixed 50/50 split against $39, at 95% confidence and 80% power:

| $39 earns more per visitor by | $39 conversion rate | Visitors needed per price |
|---|---|---|
| 10% | 2.45% | 63,131 |
| 20% | 2.68% | 16,617 |
| 30% | 2.90% | 7,755 |

If your pricing page gets 1,000 visitors a week, only the last row finishes in under four months. Plug your own numbers into the [sample size calculator](https://leverprice.com/tools/price-test-sample-size-calculator) before you write any code.

Finally, set hard bounds in your code: a minimum and maximum price your server will accept no matter what a dashboard says, so a typo can never sell your product for $0.29.

## Step 3: Should you use a fixed split or a bandit?

Use a fixed split when you need a clean estimate of the difference and have the traffic for it. Use a bandit when you test three or more prices, or when sending half your visitors to a losing price for months costs too much.

| | Fixed split | Bandit |
|---|---|---|
| Traffic per price | Constant, usually even | Moves toward the leader |
| When you read the result | Once, at a sample size set in advance | Continuously, with a stopping rule |
| Revenue lost during the test | Half the traffic sees the worse price until the end | Shrinks as the leader takes over |
| What you learn about losing prices | A precise estimate | A rough one |
| Prices you can test at once | 2 to 3 | 3 to 5 |

The classic fixed-split mistake is reading it early. In [Evan Miller's simulation](https://www.evanmiller.org/how-not-to-run-an-ab-test.html), a test checked after every observation and stopped at the first significant result produced a false winner 26.1% of the time. Set the sample size, then look once. [Bandit vs A/B test](https://leverprice.com/blog/bandit-vs-ab-test-pricing) goes deeper on the trade-off.

A bandit also needs a floor: keep a minimum share of traffic, such as 5%, on every price, so an unlucky first week can't starve a good price of the visitors it needs to recover.

## Step 4: How do you assign prices on the server and keep them sticky?

Pick the price in your server code before the page is sent, then store the choice so the same visitor gets the same price on every later request, checkout included.

1. Identify the visitor: the account id when signed in, otherwise a random id stored in a signed first-party cookie.
2. Hash that id with the experiment name into a bucket from 0 to 9,999, and map buckets to prices by their traffic weights.
3. Write the assigned price into the cookie, so a later change in weights (a bandit moving traffic) only affects new visitors.
4. Skip crawlers and link previews: give them your standard price and don't count them.

Doing this in the browser breaks in predictable ways: the price flickers, ad blockers remove the test, and anyone can edit the number before paying. [Server-side price testing](https://leverprice.com/blog/server-side-price-testing) explains each failure and how to cache pages that show per-visitor prices.

One rule from that guide matters on day one: any response that contains a test price must send `Cache-Control: private` (or `no-store`). Without it, a shared cache can store the page and serve one visitor's price to everyone ([MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control)).

## Step 5: How do you show the price and charge the same price at checkout?

Ask for the price where it is shown and again where the checkout is created, and give the checkout the amount from your server, never from the browser. Here is a complete Express and Stripe Checkout setup with `@leverprice/sdk`, following the SDK's README. The same two calls work in any framework, and the [docs](https://leverprice.com/docs) show them in Python, PHP, Ruby and Go.

```bash
npm install @leverprice/sdk stripe express
```

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

export const leverprice = new Leverprice({
  secretKey: process.env.LEVERPRICE_SECRET_KEY, // server-only, never in the browser
  products: {
    // fallbackPrice is your current price. Prices outside minPrice/maxPrice are never returned.
    pro: { currency: "usd", fallbackPrice: 2900, minPrice: 1900, maxPrice: 4900 },
  },
});

leverprice.preload(); // long-lived server: fetch the signed config at startup
```

```ts title="src/server.ts"
import express from "express";
import Stripe from "stripe";
import { getUserId } from "./auth.js"; // yours: the signed-in user's id, or undefined
import { grantAccess } from "./fulfillment.js"; // yours: must be safe to run twice
import { leverprice } from "./leverprice.js";

const app = express();
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY ?? "");
const SITE_URL = process.env.SITE_URL ?? "http://localhost:3000";

const money = (amount: number, currency: string) =>
  new Intl.NumberFormat("en-US", { style: "currency", currency }).format(amount / 100);

// 1. Show the price. A visitor keeps the same price for the whole test.
app.get("/pricing", async (req, res) => {
  const quote = await leverprice.getPrice("pro", { request: req, userId: await getUserId(req) });
  res.append("Set-Cookie", quote.setCookie); // an array, usually empty: append it anyway
  res.set("Cache-Control", "private, no-store"); // per-visitor page: keep it out of shared caches
  res.send(`<h1>Pro</h1>
<p>${money(quote.price, quote.currency)}</p>
<form method="post" action="/checkout"><button>Buy Pro</button></form>`);
});

// 2. Charge the same price. The form sends no amount; the server asks again.
app.post("/checkout", async (req, res) => {
  const quote = await leverprice.getPrice("pro", { request: req, userId: await getUserId(req) });
  const session = await stripe.checkout.sessions.create({
    mode: "payment",
    line_items: [
      {
        quantity: 1,
        price_data: { currency: quote.currency, unit_amount: quote.price, product_data: { name: "Pro" } },
      },
    ],
    metadata: quote.metadata, // signed attribution: pass it whole
    payment_intent_data: { metadata: quote.metadata },
    success_url: `${SITE_URL}/welcome?session_id={CHECKOUT_SESSION_ID}`,
    cancel_url: `${SITE_URL}/pricing`,
  });
  res.append("Set-Cookie", quote.setCookie);
  res.redirect(303, session.url ?? `${SITE_URL}/pricing`);
});
```

What each piece is doing:

- `quote.price` is in minor units: 2900 is $29.00. The same number is what the page displays and what Stripe charges as `unit_amount`.
- Both routes pass the same `userId`, so a signed-in buyer is bucketed by account on the pricing page and at checkout. For anonymous visitors, the signed `__pp` cookie set on the pricing page carries the assignment to the checkout request.
- `quote.metadata` is a small signed record of the experiment, the price and the visitor. Pass it whole, on the session and the PaymentIntent as above. Stripe allows 50 metadata keys with values up to 500 characters ([Stripe](https://docs.stripe.com/metadata)), so it leaves room for your own keys.
- If the pricing service is slow (no config within 500 ms), down or switched off with `LEVERPRICE_DISABLED=1`, `getPrice()` returns your `fallbackPrice` instead of throwing. The worst case is your current price.
- The example sells a one-time purchase (`mode: "payment"`), the flow the SDK's README documents.

> [!WARNING]
> Never put the amount, or a price ID the server trusts, in the form or the URL. A hidden input is a suggestion: anyone can change it in the browser before submitting. The checkout route has to work out the price itself.

## Step 6: How do you verify purchases with webhooks?

Count a purchase only when your payment provider says it happened, in a signed webhook. Success-page visits miss buyers who close the tab, and Stripe's own guide says you can't rely on the landing page alone because customers aren't guaranteed to reach it ([Stripe](https://docs.stripe.com/checkout/fulfillment)).

Three facts shape the code. Stripe retries a failed delivery for up to three days in live mode, can deliver the same event more than once, and doesn't guarantee order ([Stripe](https://docs.stripe.com/webhooks)), so every handler must be safe to run twice. Payment methods that settle later, like ACH Direct Debit, complete the session first and send `checkout.session.async_payment_succeeded` when the money arrives. And the signature is computed over the exact bytes Stripe sent, so verify it against the raw body before any JSON parser touches it.

*Figure: Flow diagram: your checkout, the payment provider, a signed webhook, a verified purchase. A purchase counts when the provider's signed event arrives, not when the customer reaches your thank-you page.*

For the test itself, connect Stripe straight to Leverprice: copy the endpoint URL from its Payments page, add it as a webhook endpoint in Stripe, subscribe it to `checkout.session.completed`, `checkout.session.async_payment_succeeded` and `charge.refunded`, and paste its signing secret back. A signing secret can confirm events but can't move money. Polar, Lemon Squeezy and Dodo Payments connect the same way; [verified revenue from webhooks](https://leverprice.com/blog/verified-revenue-webhooks) explains the details.

You still need your own handler to deliver what the customer bought:

```ts title="src/server.ts (continued)"
// 3. Fulfill from the signed webhook. express.raw keeps the exact bytes Stripe signed.
app.post("/webhooks/stripe", express.raw({ type: "application/json" }), async (req, res) => {
  let event: Stripe.Event;
  try {
    event = stripe.webhooks.constructEvent(
      req.body,
      req.get("stripe-signature") ?? "",
      process.env.STRIPE_WEBHOOK_SECRET ?? "",
    );
  } catch {
    res.status(400).send("Invalid signature");
    return;
  }

  if (event.type === "checkout.session.completed" || event.type === "checkout.session.async_payment_succeeded") {
    const session = event.data.object;
    if (session.payment_status === "paid") await grantAccess(session.id);
  }
  res.sendStatus(200);
});

app.listen(3000);
```

If you can't connect the provider's webhook directly, call `leverprice.trackPurchase()` from this handler with the session's `payment_intent`, amount, currency and metadata. That works, but the dashboard labels the revenue unverified, because it comes from your server rather than a provider signature.

## Step 7: How do you handle refunds and currencies?

Refunds arrive as their own signed events (Stripe `charge.refunded`, Polar `order.refunded`, Lemon Squeezy `order_refunded`, Dodo `refund.succeeded`) and should reduce the revenue of the price group that earned the sale. Keep counting them for your refund window after the test stops, and compare refund rates across prices: a price that sells more and refunds more is a worse price than it looks.

Compare prices before tax. Subtract the tax amount (Stripe's `total_details.amount_tax`) from each purchase, so a sale into a high-VAT country doesn't look like a higher price.

Run each test in one currency, and if customers can pay in their own, convert back before comparing. With Stripe's Adaptive Pricing, customers in more than 150 countries can pay in local currency and pay a 2 to 4% conversion fee themselves, while the Checkout Session still reports `amount_total` and `currency` in your currency and puts the local amount in `presentment_details` ([Stripe](https://docs.stripe.com/payments/currencies/localize-prices/adaptive-pricing)). Use `amount_total`, and keep `presentment_details` for your records.

## Step 8: How do you decide which price won?

With a fixed split, wait for the sample size you set, then compare revenue per visitor once. With a bandit, stop when its rule says one price is best or the rest are too close to matter.

Example: 14,000 visitors per price. $29 sold 420 times ($12,180, or $0.870 per visitor). $49 sold 308 times ($15,092, or $1.078 per visitor).

Each visitor's revenue is either zero or the price, so the variance per visitor is price² × c × (1 − c): 24.47 for $29 and 51.66 for $49. The standard error of the difference is √(24.47 ÷ 14,000 + 51.66 ÷ 14,000) = $0.074. The difference is $0.208, so z = 0.208 ÷ 0.074 = 2.82 (p ≈ 0.005), and the 95% interval runs from $0.063 to $0.353 per visitor. Even the low end is 7% above $0.87, so $49 wins.

If the interval includes zero, you haven't found a difference worth acting on at this sample size. Keep the control, or rerun with prices further apart.

A bandit needs a stopping rule instead. Leverprice calls a winner when one price is at least 95% likely to be the best, or when the remaining prices are practically equivalent (picking the leader loses less than 0.5% in expectation), and it only scores visitors older than 30 minutes so fresh traffic that hasn't had time to buy doesn't drag a price down.

Before rolling out, look past the headline: refund rates by price, support tickets that mention price, and for subscriptions, how many buyers of each price renew.

## Step 9: How do you roll out the winning price?

Make the winner the standard price for every new visitor, end the test, and update every place the old price lives.

- Change your `fallbackPrice` to the winner, so the code's last resort matches the new price.
- Update the pricing page copy, structured data, ads, onboarding emails, docs and comparison pages.
- Let buyers from the test keep the price they paid. If some paid more than the price you roll out, refunding the difference is the trust-preserving move.
- End the test promptly. Google warns that experiments left running for an unnecessarily long time can be read as an attempt to deceive search engines ([Google](https://developers.google.com/search/docs/crawling-indexing/website-testing)).
- Leave existing subscribers out of it. Moving them to a new price is a separate decision; [how to raise SaaS prices](https://leverprice.com/blog/how-to-raise-saas-prices) covers notice periods and grandfathering.

Then plan the next test: a narrower range around the winner, or the annual price.

## Step 10: What should you tell customers and support?

Write replies for the customers who notice before you launch, so support doesn't improvise.

| Customer asks | Example reply |
|---|---|
| Why did my friend see a lower price? | We test prices with new visitors for a few weeks at a time to find the right price for the product. Prices are assigned at random, not based on who you are. If you paid more during a test, we'll refund the difference. |
| Will my price change? | No. The price you signed up at stays yours; tests only apply to new visitors. |
| Can I get the price I saw last week? | Yes. Reply with the date and we'll honor it. |

The refund promise has a precedent. After a random DVD price test in 2000, Amazon refunded 6,896 customers an average of $3.10 and promised future test buyers the lowest test price automatically ([Amazon](https://press.aboutamazon.com/2000/9/amazon-com-issues-statement-regarding-random-price-testing)).

Give support a way to look up what a customer saw: the variant is in the Checkout Session's metadata, next to the payment, so a refund of the difference takes one lookup.

## How do you A/B test prices without any vendor?

With a stable visitor id, a hash, two Stripe Prices and checkout metadata. Build it once and you'll understand every moving part of a price test. Create two Prices on the same Stripe Product ($29 and $39), keep their IDs in config, and assign visitors like this:

```ts title="src/price-test.ts"
import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";

export const EXPERIMENT = "pro-price-2026-11";
const SECRET = process.env.ASSIGNMENT_SECRET ?? ""; // long random string, server-only

// Two Prices on the same Stripe Product, created in the Dashboard or with the API.
const ARMS = [
  { id: "control", amount: 2900, stripePrice: process.env.STRIPE_PRICE_29 ?? "" },
  { id: "b", amount: 3900, stripePrice: process.env.STRIPE_PRICE_39 ?? "" },
] as const;

const sign = (id: string) => createHmac("sha256", SECRET).update(id).digest("base64url");

// Cookie value "<id>.<signature>". An edited or forged cookie fails the check.
export function visitorFromCookie(value: string | undefined): string | null {
  const [id, sig] = (value ?? "").split(".");
  if (!id || !sig) return null;
  const given = Buffer.from(sig);
  const expected = Buffer.from(sign(id));
  return given.length === expected.length && timingSafeEqual(given, expected) ? id : null;
}

export function newVisitor(): { id: string; cookie: string } {
  const id = randomBytes(16).toString("hex");
  return { id, cookie: `${id}.${sign(id)}` };
}

// Same id in, same arm out. The experiment name salts the hash, so tests stay independent.
export function armFor(visitorId: string) {
  const digest = createHash("sha256").update(`${EXPERIMENT}:${visitorId}`).digest();
  const bucket = digest.readUInt32BE(0) % 10_000; // 0 to 9,999
  return bucket < 5_000 ? ARMS[0] : ARMS[1]; // 50/50
}
```

On the pricing page, read the cookie (or mint a new visitor and send the cookie), render `armFor(id).amount`, and log an exposure row (experiment, arm, visitor) the first time each visitor sees the price, skipping bots and prefetch requests. At checkout, read the same cookie and charge the arm's Stripe Price:

```ts title="checkout handler"
const arm = armFor(visitorId); // the id from the signed cookie, never from the form
const tag = { experiment: EXPERIMENT, arm: arm.id, visitor: visitorId };
const session = await stripe.checkout.sessions.create({
  mode: "payment",
  line_items: [{ price: arm.stripePrice, quantity: 1 }],
  metadata: tag,
  payment_intent_data: { metadata: tag },
  success_url: `${SITE_URL}/welcome?session_id={CHECKOUT_SESSION_ID}`,
  cancel_url: `${SITE_URL}/pricing`,
});
```

In your webhook, store (experiment, arm, amount minus tax) for each paid session, keyed by event id so retries don't count twice, and subtract refunds by PaymentIntent. Revenue per visitor for an arm is its revenue divided by its distinct exposed visitors, and step 8 gives the test. For a subscription, Stripe needs `mode: "subscription"`, recurring Prices and `subscription_data.metadata`, because `payment_intent_data` only applies in payment mode ([Stripe API](https://docs.stripe.com/api/checkout/sessions/create)). [A/B testing Stripe prices](https://leverprice.com/blog/ab-test-stripe-prices) goes further into the Stripe side.

Two gaps remain in this version. If buyers sign up on one device and pay on another, copy their arm onto the user record at sign-up and read it from there; otherwise the second device gets a fresh cookie and possibly a different price. And the split stays 50/50 until you stop it.

The rest is the hard part: bots and prefetches inflating exposures, a CDN serving one arm to everyone, refunds and local currencies in the webhook, and the urge to peek. That part is what Leverprice does for you: the SDK handles assignment, signed cookies, bot filtering and fallbacks on your own server, revenue comes from your provider's signed webhooks, and the bandit moves traffic without a weekly spreadsheet.

## What are the most common price testing mistakes?

Check for these eight before launch. Each one either corrupts the result or reaches a customer.

| Mistake | What happens | Fix |
|---|---|---|
| Picking the winner by conversion rate | The cheapest price wins and revenue drops | Compare revenue per visitor, net of refunds |
| Deciding the price in the browser | Flicker, blocked scripts, editable prices | Assign on the server and render the price into the HTML |
| Reading the amount from the checkout form | Anyone can pay what they like | Recompute the amount at checkout from the stored assignment |
| No sticky assignment | Visitors see $29, then $39 after a reload | A signed cookie, plus the account id for signed-in users |
| Enrolling crawlers and link previews | Test prices in search snippets and Slack previews; bots dilute the metric | Standard price for bots, never counted |
| Caching the pricing page in a CDN | One visitor's price is served to everyone | `Cache-Control: private, no-store`, or render the price at the edge |
| Stopping at the first significant result | False winners, 26.1% of the time in Evan Miller's peeking simulation | Fix the sample size first, or use a bandit with a stopping rule |
| Counting purchases from the success page | Missed and double-counted sales | Count signed webhook events, deduplicated by event id |

## Frequently asked questions

### Can I A/B test prices with Stripe Payment Links?

Yes, with one Payment Link per price and a redirect link that assigns each visitor to one of them. The limitation is that your own page can't show the tested price: the visitor first sees it on Stripe's checkout page.

### How many visitors do I need to A/B test prices?

It depends on the size of the difference. With $29 converting 3% of visitors, detecting a 30% gain in revenue per visitor needs about 7,800 visitors per price, and a 10% gain needs about 63,000 (95% confidence, 80% power).

### Should I test monthly or annual prices first?

Start with the monthly price of your most popular plan, where most of your volume is. Test the annual price second, and count it over 12 months so the upfront payment doesn't flatter it.

### What happens to customers who bought at a losing price?

They keep the price they paid. If they paid more than the price you roll out, refund the difference; it costs little and it is the answer you want on record if anyone asks.

### Can I run two price tests at the same time?

On different products, yes, as long as each visitor's prices are assigned independently. Two tests on the same plan or the same page split each group again and blur both results, so run them one after another.
