How to A/B test prices on Stripe: 3 ways, from no-code to SDK

Stripe has no built-in price test. Three ways to run a Stripe A/B test of prices: Payment Links, your own bucketing over Price IDs, or price_data from an SDK.

Short answer

Stripe has no built-in price A/B test; its A/B testing feature compares payment methods. You can test prices three ways: one Payment Link per price behind a random redirect, your own server-side bucketing across Price objects with the variant in Checkout metadata, or inline price_data from an SDK. Judge each price by revenue per visitor after tax and refunds.

  • Stripe's built-in A/B testing compares payment methods such as Klarna or Affirm and never changes the amount charged.
  • Payment Links behind a cookie-based redirect can test a checkout price the same day, but your own page can't show that price.
  • Server-side bucketing should store each assignment and put the variant in both Checkout metadata and payment_intent_data.metadata.
  • Revenue per visitor is amount_total minus tax, minus refunds from charge.refunded, divided by every visitor who saw the price.
  • Subscription tests carry the variant in subscription_data.metadata, because payment_intent_data only applies in payment mode.

Stripe will charge two visitors two different prices for the same product without complaint. It won't split your traffic between those prices or tell you which one earned more per visitor, so that layer is yours to build. Below are three ways to build it, from a redirect you can ship this afternoon to a server-side setup with verified revenue, plus the details that quietly break Stripe price tests: subscriptions, tax, Adaptive Pricing and refunds.

Does Stripe have built-in price A/B testing?

No. As of November 2026, Stripe's built-in A/B testing compares payment methods: it shows a treatment set of methods, such as Klarna or Affirm, to part of your checkout traffic and reports average revenue per session. You start and manage it only in the Dashboard, with no API option, and it never changes the amount you charge.

Stripe's own guide to pricing experiments describes the do-it-yourself route instead: create several Price IDs for one product, route customers randomly and keep the reporting separate. Every method below is a version of that advice. Stripe supplies Prices, inline price_data, Checkout metadata and signed webhooks. Deciding who sees which price, and adding up the money afterwards, is up to you.

What does every Stripe price test need?

Whichever method you choose, a working test has four parts:

  1. Each visitor gets one price and keeps it on later visits.
  2. The price on your page matches the price at checkout, and your server decides the checkout amount. The browser never sends it.
  3. The Checkout Session carries the variant, so every payment and every refund can be traced back to it.
  4. You measure revenue per visitor for each price: revenue after tax and refunds, divided by everyone who saw that price, with sandbox payments left out.

The fourth part decides the result. Conversion rate almost always favors the cheaper price, so it can't tell you which price earns more; revenue per visitor can. For picking the prices to test and reading the numbers, see the general method. This guide covers the Stripe wiring.

Create one Payment Link per price, point your Buy button at a small redirect that picks a link for each visitor and remembers it in a cookie, and read the results from the checkout.session.completed webhook. Your pricing page and backend stay as they are.

  1. In the Stripe Dashboard, create a Payment Link for each test price of the same product, for example $29 and $39. Copy each link's URL and its ID (plink_…).
  2. Deploy the redirect below on any serverless platform; this one is a Cloudflare Worker. It appends the visitor's ID as client_reference_id, which Stripe returns in the checkout.session.completed event. The value may contain letters, digits, dashes and underscores, up to 200 characters (Payment Link URL parameters).
  3. Point every Buy button at the redirect.
  4. In your webhook handler, map session.payment_link to a variant. If you create the links through the API, metadata you set on a link is copied to each Checkout Session it creates (Stripe metadata docs).
worker.ts
const LINKS = {
  A: "https://buy.stripe.com/test_aaa111", // $29
  B: "https://buy.stripe.com/test_bbb222", // $39
} as const;
type Variant = keyof typeof LINKS;

export default {
  async fetch(request: Request): Promise<Response> {
    const cookies = request.headers.get("Cookie") ?? "";
    const saved = cookies.match(/(?:^|;\s*)pt_pro=([AB])\.([\w-]{1,64})/);
    const variant: Variant = (saved?.[1] as Variant | undefined) ?? (Math.random() < 0.5 ? "A" : "B");
    const visitorId = saved?.[2] ?? crypto.randomUUID();

    const target = new URL(LINKS[variant]);
    target.searchParams.set("client_reference_id", visitorId);

    return new Response(null, {
      status: 302,
      headers: {
        Location: target.toString(),
        "Set-Cookie": `pt_pro=${variant}.${visitorId}; Max-Age=15552000; Path=/; Secure; HttpOnly; SameSite=Lax`,
        "Cache-Control": "no-store",
      },
    });
  },
};

Log every new cookie the redirect sets, as one line in your analytics or one row in a database. That count is the denominator of revenue per visitor, and Stripe can't give it to you.

It's the fastest way to get a real signal. Most of its limits come from the price living on Stripe's page:

  • Your pricing page can't show the tested price. A page that says $29 in front of a $39 link is a bait-and-switch, so you end up testing checkout completion at a price visitors meet only after they click.
  • Visitors who never click Buy are invisible. You measure revenue per checkout visitor, and the test can't capture how a price on your page changes the click rate.
  • The cookie is the only memory. A second device or a cleared browser means a new coin flip, and the same person can see both prices.
  • Each link is a public URL that anyone can bookmark or share, the cheaper one included.
  • Adaptive Pricing is always on for Payment Links (Stripe docs), so international visitors see a converted amount (more on that below).

Leverprice's no-code mode is a hosted version of this method for Webflow, Framer and static sites: you paste one checkout link per price, and the Buy button points to a Leverprice link that assigns the visitor and redirects with signed attribution. The same limit applies, since the page itself can't show the tested price.

Method 2: How do you split traffic across Stripe Price objects yourself?

Create one Price per variant, assign visitors on your server by hashing a visitor ID, store each assignment, render the assigned price, and carry the variant through Checkout into your webhook. It is more code than Method 1, and it is the complete version: your page shows the tested price, and every payment is attributed to it.

Step 1: Create one Price per variant

Add the test prices to your existing Product, for example 2900 and 3900 USD cents. A Price's amount can't be edited after creation (the update endpoint has no unit_amount), so each new test amount means a new Price. Keep everything else identical across variants: product, currency, tax_behavior and billing interval.

Step 2: Assign each visitor and store the assignment

assignment.ts
import { createHash, randomUUID } from "node:crypto";
import type { Request, Response } from "express";
import { db } from "./db"; // your Postgres client (node-postgres style)

export const TEST_ID = "pro-2026-11";
export const VARIANTS = [
  { key: "A", priceId: "price_1A29", amount: 2900 }, // control
  { key: "B", priceId: "price_1B39", amount: 3900 },
] as const;
export type Variant = (typeof VARIANTS)[number];

// A minimal check. Crawlers, previews and monitors get the control price and no row.
const BOTS = /bot|crawl|spider|slurp|preview|facebookexternalhit|headless|lighthouse|curl|wget/i;

function bucket(visitorId: string): Variant {
  const n = createHash("sha256").update(`${TEST_ID}:${visitorId}`).digest().readUInt32BE(0);
  return VARIANTS[n % VARIANTS.length];
}

export async function assign(req: Request, res: Response): Promise<{ variant: Variant; visitorId: string | null }> {
  if (BOTS.test(req.get("user-agent") ?? "")) return { variant: VARIANTS[0], visitorId: null };

  let visitorId: string | undefined = req.cookies.vid; // cookie-parser
  if (!visitorId) {
    visitorId = randomUUID();
    res.cookie("vid", visitorId, { maxAge: 180 * 86_400_000, httpOnly: true, secure: true, sameSite: "lax" });
  }

  await db.query(
    `INSERT INTO price_assignments (test_id, visitor_id, variant)
     VALUES ($1, $2, $3) ON CONFLICT (test_id, visitor_id) DO NOTHING`,
    [TEST_ID, visitorId, bucket(visitorId).key],
  );
  const { rows } = await db.query(
    "SELECT variant FROM price_assignments WHERE test_id = $1 AND visitor_id = $2",
    [TEST_ID, visitorId],
  );
  return { variant: VARIANTS.find((v) => v.key === rows[0].variant) ?? VARIANTS[0], visitorId };
}

The hash makes assignment deterministic: the same visitor gets the same answer on every server without a lookup. The stored row keeps that answer fixed even if you later add a third price, which would change n % VARIANTS.length for most visitors. For signed-in users, save the visitor ID on the account and reuse it, so a second device sees the same price.

The table doubles as your exposure log: one row per human who saw a price, which is exactly the denominator you need. Call assign() where the pricing page renders and display variant.amount. Crawlers get the control price and no row, so Googlebot never dilutes the test or sees two prices for one URL (price tests and SEO).

Step 3: Create the Checkout Session with the variant

checkout.ts
import express from "express";
import cookieParser from "cookie-parser";
import Stripe from "stripe";
import { assign, TEST_ID } from "./assignment";

export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export const app = express();
app.use(cookieParser());

app.post("/checkout", async (req, res) => {
  const { variant, visitorId } = await assign(req, res); // the price comes from the assignment
  const tags = { price_test: TEST_ID, variant: variant.key, visitor_id: visitorId ?? "" };

  const session = await stripe.checkout.sessions.create({
    mode: "payment",
    line_items: [{ price: variant.priceId, quantity: 1 }],
    client_reference_id: visitorId ?? undefined,
    metadata: tags,
    payment_intent_data: { metadata: tags },
    success_url: "https://example.com/thanks?session_id={CHECKOUT_SESSION_ID}",
    cancel_url: "https://example.com/pricing",
  });
  res.redirect(303, session.url!);
});

The variant travels in two places on purpose. Session metadata arrives with checkout.session.completed. payment_intent_data.metadata lands on the PaymentIntent, and Stripe copies a PaymentIntent's metadata onto the Charge it creates, so charge.refunded carries the variant too. Stripe doesn't copy session metadata to the PaymentIntent by itself (Stripe metadata docs).

Step 4: Record purchases and refunds from the webhook

Revenue reaches your database through Stripe's signed webhook, never through the browser.
webhook.ts
import express from "express";
import type Stripe from "stripe";
import { app, stripe } from "./checkout";
import { db } from "./db";

// Register before any JSON body parser: the signature covers the raw bytes.
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.sendStatus(400);
    return;
  }

  if (event.type === "checkout.session.completed" || event.type === "checkout.session.async_payment_succeeded") {
    const s = event.data.object;
    if (s.mode === "payment" && s.payment_status === "paid" && s.metadata?.price_test) {
      const gross = s.amount_total ?? 0;
      const net = gross - (s.total_details?.amount_tax ?? 0);
      await db.query(
        `INSERT INTO price_orders (order_id, test_id, variant, visitor_id, currency, gross, net, livemode)
         VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (order_id) DO NOTHING`,
        [s.payment_intent, s.metadata.price_test, s.metadata.variant, s.metadata.visitor_id, s.currency, gross, net, event.livemode],
      );
    }
  }

  if (event.type === "charge.refunded") {
    const charge = event.data.object; // charge.metadata holds the variant as well
    await db.query("UPDATE price_orders SET refunded = GREATEST(refunded, $2) WHERE order_id = $1", [
      charge.payment_intent,
      charge.amount_refunded,
    ]);
  }

  res.sendStatus(200);
});

A few details in that handler matter:

  • Stripe's fulfillment guide warns that your handler can run several times for the same session, even concurrently, so the insert ignores duplicates.
  • Delayed payment methods complete the session unpaid and succeed later with checkout.session.async_payment_succeeded, which is why both events are handled.
  • charge.refunded fires for full and partial refunds, and amount_refunded is a running total (Stripe refunds). Taking the larger value keeps the update correct when events arrive out of order.
  • Stripe doesn't return its processing fee when you refund (Stripe refunds), so a refunded sale costs you money. Count it as zero revenue at best.

Step 5: Compute revenue per visitor

report.sql
SELECT a.variant,
       COUNT(DISTINCT a.visitor_id) AS visitors,
       COUNT(o.order_id) FILTER (WHERE o.refunded < o.gross) AS kept_orders,
       ROUND(SUM(COALESCE(o.net * (o.gross - o.refunded)::numeric / NULLIF(o.gross, 0), 0)) / 100, 2) AS kept_revenue,
       ROUND(SUM(COALESCE(o.net * (o.gross - o.refunded)::numeric / NULLIF(o.gross, 0), 0)) / 100
             / COUNT(DISTINCT a.visitor_id), 4) AS revenue_per_visitor
FROM price_assignments a
LEFT JOIN price_orders o
       ON o.test_id = a.test_id AND o.visitor_id = a.visitor_id AND o.livemode
WHERE a.test_id = 'pro-2026-11'
GROUP BY a.variant;

Kept revenue scales each order's pre-tax amount by the share that wasn't refunded, so a partial refund counts partially and a refunded tax amount doesn't push revenue below zero.

Example: after four weeks, each price has reached 4,000 visitors.

PriceVisitorsKept ordersConversionKept revenueRevenue per visitor
$294,0001142.85%$3,306$0.83
$394,000962.40%$3,744$0.94

Revenue per visitor is kept revenue divided by visitors: $3,306 ÷ 4,000 = $0.83 and $3,744 ÷ 4,000 = $0.94. The $39 price converts worse and earns 13% more per visitor. With about 100 orders per price, that gap is still noise. A two-sample z-test gives z = (0.936 − 0.827) ÷ √(4.83²/4,000 + 5.97²/4,000) ≈ 0.9, far below the 1.96 that 95% confidence needs; each standard deviation comes from s² = p × price² − (p × price)², with p the kept-order rate. Size the test with the sample size calculator before you start.

Method 3: How do you test prices with price_data and the Leverprice SDK?

Ask the Leverprice SDK for the visitor's price on your server, show it, and pass the same number to Checkout as inline price_data, which creates the Price on the fly (Checkout Session API). Testing $34 next week then means changing a range in a dashboard, with no new Price objects.

pricing.ts
import express from "express";
import Stripe from "stripe";
import { Leverprice } from "@leverprice/sdk";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
const app = express();

export const leverprice = new Leverprice({
  secretKey: process.env.LEVERPRICE_SECRET_KEY, // server-only, never in the browser
  products: {
    // Local guardrails: prices outside these bounds are never returned.
    pro: { currency: "usd", fallbackPrice: 2900, minPrice: 1900, maxPrice: 4900 },
  },
});
leverprice.preload(); // optional: fetch the config at startup

app.get("/pricing", async (req, res) => {
  const quote = await leverprice.getPrice("pro", { request: req });
  res.append("Set-Cookie", quote.setCookie);
  res.render("pricing", { price: quote.price }); // minor units: 2900 = $29.00
});

app.post("/checkout", async (req, res) => {
  const q = await leverprice.getPrice("pro", { request: req }); // never trust a price sent by the browser
  const session = await stripe.checkout.sessions.create({
    mode: "payment",
    line_items: [{ quantity: 1, price_data: { currency: q.currency, unit_amount: q.price, product_data: { name: "Pro" } } }],
    metadata: q.metadata, // signed attribution: pass it whole
    payment_intent_data: { metadata: q.metadata },
    success_url: "https://example.com/thanks",
    cancel_url: "https://example.com/pricing",
  });
  res.redirect(303, session.url!);
});

Pass userId to getPrice() for signed-in visitors so they get the same bucket on every device. Then connect revenue: in the Leverprice dashboard open Payments, connect Stripe, add the generated URL as a webhook endpoint in Stripe for checkout.session.completed, checkout.session.async_payment_succeeded and charge.refunded, and paste back that endpoint's signing secret. A signing secret can confirm events but can't move money (how verified revenue works).

That replaces most of Method 2:

  • Visitors keep their price through an HMAC-signed first-party cookie, and userId, hashed on your server, puts a signed-in user in the same bucket on every device.
  • Crawlers, link previews, headless browsers and monitors get your standard price and are never enrolled. Prefetch requests are priced but not counted.
  • Purchases come from Stripe's signed webhooks, refunds reduce the variant's revenue, and test and live data stay separate.
  • On Pro, a Thompson-sampling bandit moves traffic toward the price with the highest revenue per visitor and keeps at least 5% on every price. The Free plan runs a manual split.
  • If Leverprice is slow or down, getPrice() returns your fallbackPrice within 500 ms and never throws for that reason, and every price is checked against your own minPrice and maxPrice.

As of November 2026 the Free plan covers one product and one experiment with up to $500 a month in tested revenue, and Pro costs $29 a month or $199 a year (Leverprice pricing). Framework-specific install steps are in the docs.

How do you test subscription prices on Stripe?

Use mode: "subscription" and give each variant a recurring price: a recurring Price ID per variant, or inline price_data with recurring (Checkout Session API). Put the variant in subscription_data.metadata, because payment_intent_data only applies to sessions in payment mode.

subscription-checkout.ts
const tags = { price_test: TEST_ID, variant: variant.key, visitor_id: visitorId ?? "" };

const session = await stripe.checkout.sessions.create({
  mode: "subscription",
  line_items: [{
    quantity: 1,
    price_data: {
      currency: "usd",
      unit_amount: variant.amount, // 2900 or 3900
      recurring: { interval: "month" },
      product: "prod_PRO", // your existing Product ID
    },
  }],
  client_reference_id: visitorId ?? undefined,
  metadata: tags,
  subscription_data: { metadata: tags },
  success_url: "https://example.com/thanks",
  cancel_url: "https://example.com/pricing",
});

The events change with the mode:

  • The first payment arrives as checkout.session.completed with mode: "subscription". With a free trial, payment_status is still paid, which there means the $0 trial invoice was processed (Checkout Session object), so record amount_total instead of trusting the status.
  • Renewals arrive as invoice.paid with billing_reason: "subscription_cycle". The variant sits in invoice.parent.subscription_details.metadata, a snapshot of the subscription's metadata taken when the invoice is created (Stripe metadata docs).
  • A refunded renewal arrives as charge.refunded without your metadata, because nothing copies subscription metadata to the invoice's payment. Find the invoice with stripe.invoicePayments.list({ payment: { type: "payment_intent", payment_intent: charge.payment_intent } }), then its subscription's variant.

Pick the revenue window before launch. First payment only is fast but blind to churn; 90-day revenue per visitor is slower and closer to the truth, because a higher monthly price that churns faster can win the first month and lose by the third.

Leverprice's Stripe connection counts one-time Checkout payments (mode: "payment") and their refunds; a subscription-mode session isn't counted as a verified purchase. For a Stripe subscription price test, use Method 2.

How do taxes affect a Stripe price test?

Compare prices on revenue before tax. With Stripe Tax on (automatic_tax: { enabled: true }), the session reports the tax in total_details.amount_tax, so amount_total - total_details.amount_tax is the pre-tax amount whether your prices include tax or add it on top.

Set tax_behavior the same way on every variant (Checkout Session API). exclusive adds tax to the price the visitor saw; inclusive carves it out of that price, and once a price is set to either, it can't be changed. Example: a €29 tax-inclusive price at a 20% VAT rate nets €24.17 (29 ÷ 1.20), while a buyer from a place where you don't collect tax nets you the full €29. Mixed traffic is fine as long as every price gets the same mix of countries, which random assignment gives you.

What happens with Adaptive Pricing and local currencies?

Adaptive Pricing shows visitors in more than 150 countries a converted local price at checkout (Adaptive Pricing docs). It is always on for Payment Links, and you switch it on or off for Checkout in your Dashboard settings. Your test survives it: the Checkout Session and PaymentIntent report the amount in your integration currency, and the local amount sits in presentment_details.

Stripe's own example shows a session with amount_total: 1000 in USD and presentment_details of 1370 CAD (Adaptive Pricing docs). What else changes:

  • The customer pays a conversion fee of 2% to 4% built into the exchange rate, and you pay 0% (Adaptive Pricing docs). Every price gets the same treatment, so the comparison stays fair, but your page says $29 while Stripe's page shows Canadian dollars.
  • Adaptive Pricing doesn't convert into a currency you've already priced manually through currency_options. If you set your own local prices, keep the same relative gap between test prices in every currency.
  • For cross-border subscriptions it supports only cards, Link, Apple Pay and Google Pay.
  • Refunds go back in the customer's currency at the original exchange rate.

For the report, keep using amount_total and currency from the session. If you also charge in several currencies yourself, convert everything to one currency before you compare prices.

How do you test the setup before real traffic?

Run everything in a Stripe sandbox first. Stripe recommends general sandboxes over the older test-mode sandbox for new integrations (sandboxes); either way, no money moves.

  1. Forward events locally with stripe listen --forward-to localhost:4242/webhooks/stripe. It prints a whsec_ secret to use as STRIPE_WEBHOOK_SECRET (fulfillment guide).
  2. Buy through your own page with card 4242 4242 4242 4242, any future expiry date and any CVC (Stripe testing).
  3. Fire the edge cases from the Stripe CLI: stripe trigger charge.refunded, and stripe trigger checkout.session.completed --add checkout_session:metadata.price_test=pro-2026-11.
  4. Preview Adaptive Pricing by creating a session with customer_email: "test+location_FR@example.com".
  5. Check that the report excludes livemode: false orders and that curl and a Googlebot user agent get the control price without creating a row.

Which method should you pick?

Method 1: Payment LinksMethod 2: Price IDs + your bucketingMethod 3: price_data + Leverprice SDK
Code to writeOne redirectAssignment, checkout, webhook, reportSDK calls where you show and charge the price
Price shown on your pageNo, only on Stripe's pageYesYes
Sticky assignmentCookie on the redirectCookie plus database rowSigned cookie, same bucket per userId
CrawlersRarely reach itYour user-agent checkStandard price, never enrolled
Revenue sourceYour webhook handlerYour webhook handlerStripe's signed webhooks sent to Leverprice
RefundsYou match charge.refundedYou match charge.refundedSubtracted from the variant
Traffic splitFixedFixed, changed by handFree: fixed; Pro: moves toward the best revenue per visitor
Stripe subscriptionsYesYesOne-time payments only
Cost (November 2026)FreeFree, plus your timeFree up to $500/month tested revenue; Pro $29/month

The decision rule: start with Method 1 if you have no backend and want a first signal this week. Use Method 2 if you sell subscriptions or want to own every line of the analysis. Use Method 3 if you sell one-time payments through Checkout and would rather not maintain Method 2's assignment and refund code yourself.

Frequently asked questions

Can I change the amount of an existing Stripe Price?

No. The Prices update endpoint accepts fields like active, metadata, nickname and lookup_key, but not unit_amount (Prices API). Create a new Price for each test amount and set the losing ones to active: false when the test ends.

What should existing customers pay during the test?

Their current price. Assign only new visitors, and keep existing subscriptions on the Price they signed up with; moving them is a price change, which is a separate decision from the test.

How long should a Stripe price test run?

Until each price has enough kept orders to separate the revenue per visitor you care about, and in whole weeks so weekday and weekend buyers land in every arm. In the example above, about 100 orders per price could not separate a 13% gap; how long a price test should run covers the math.

Do refunded purchases count against a price?

Yes. A refunded sale earned nothing, and Stripe keeps its processing fee, so subtract refunds from the price that made the sale. A cheap price that attracts more refunds can look better than it is until you do.

Does Stripe's built-in A/B testing work for subscription prices?

No. It tests which payment methods appear at checkout, it works with the Payment Element or Checkout in payment mode, and it never changes the amount (Stripe A/B testing).