Short answer
Leverprice runs price tests on Stripe Checkout. Your server charges each visitor's assigned price with inline price_data, and a sale counts only after Stripe's signed webhook confirms it. You connect a webhook signing secret (whsec_), never an API key. Verified revenue covers one-time Checkout payments; subscription first payments are reported with trackPurchase() and labeled unverified.
- Your server charges the tested price through line_items[].price_data, so you don't add a catalog Price for every test price.
- The Leverprice endpoint listens to checkout.session.completed, checkout.session.async_payment_succeeded and charge.refunded.
- Create the Stripe destination with the Snapshot payload: Leverprice holds no API key, so it can't fetch what a thin event leaves out.
- Only Checkout Sessions in payment mode are verified. A subscription's first payment is reported with trackPurchase() and shows as unverified.
- With Adaptive Pricing, the session still reports your integration currency, so a sale paid in yen counts at the tested price.
Leverprice runs price tests on top of the Stripe Checkout you already have. Your server asks Leverprice which price a visitor should see, creates the Checkout Session at that amount with your own Stripe key, and Stripe's signed webhook reports the sale back. A sale counts toward the test only after Leverprice has checked Stripe's signature, so the revenue in your results is revenue Stripe recorded.
To connect, you paste the signing secret of a Stripe webhook endpoint (whsec_…). It lets Leverprice check the signature on each event, and it can't charge a card or call Stripe's API.
How does price testing work on Stripe?
- 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.
- Where the price is shown, your server calls
getPrice()and rendersquote.price. A signed first-party cookie keeps each visitor on one price, and passinguserIdputs a signed-in user in the same bucket on every device. - Where the checkout is created, your server asks again and opens a Checkout Session for
quote.pricewithquote.metadataattached. - Stripe sends
checkout.session.completedto Leverprice, which checks the signature, credits the sale to the price that visitor saw and moves traffic toward the price that earns the most per visitor.
No Leverprice script runs in the browser, and your Stripe keys never leave your server.
How do I connect Stripe webhooks to Leverprice?
- In Leverprice, open Payments, click Connect provider, and choose Stripe and a mode, Test or Live. Leverprice generates a webhook URL for the project.
- In Stripe, open the Webhooks tab in Workbench and click Create an event destination. Choose Your account and the Snapshot payload format.
- Select the three events below, pick Webhook endpoint as the destination type and paste the Leverprice URL.
- On the endpoint's page, click Reveal secret and paste the
whsec_…value into Leverprice.
| Event | What Leverprice does with it |
|---|---|
checkout.session.completed | Counts the sale once the session is paid |
checkout.session.async_payment_succeeded | Counts sales paid by bank debit and other delayed methods when the payment succeeds |
charge.refunded | Takes refunds off that price's revenue |
Stripe signs each delivery with the secret and a timestamp (Stripe docs). Leverprice rejects any delivery whose timestamp is more than five minutes off, so a copied request can't be replayed.
How do I charge the tested price in Stripe Checkout?
Pass the amount inline with price_data instead of a saved Price ID. Stripe builds the price for that session from currency, unit_amount in minor units and product_data (API reference), so you don't add a catalog Price for every test price.
Create the Leverprice client once (setup details):
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 },
},
});Then the checkout route asks for the price again and charges it:
import Stripe from "stripe";
import { leverprice } from "@/lib/leverprice";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
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 session = await stripe.checkout.sessions.create({
mode: "payment",
line_items: [
{
quantity: 1,
price_data: {
currency: quote.currency,
unit_amount: quote.price, // minor units: 2900 = $29.00
product_data: { name: "Pro" },
},
},
],
metadata: quote.metadata, // signed attribution: pass it whole
payment_intent_data: { metadata: quote.metadata },
success_url: "https://example.com/thanks?session_id={CHECKOUT_SESSION_ID}",
cancel_url: "https://example.com/pricing",
});
const headers = new Headers({ Location: session.url! });
for (const cookie of quote.setCookie) headers.append("Set-Cookie", cookie);
return new Response(null, { status: 303, headers });
}quote.metadata carries four signed values: pp_exp, pp_var, pp_vid and pp_sig. Pass the object whole. Leverprice drops attribution whose signature doesn't match, so nobody can credit a sale to a different price by editing it.
From the paid session, Leverprice takes the amount after discounts and before tax (amount_total minus total_details.amount_tax) and files the sale under its PaymentIntent ID, which is how a refund finds it later. The Next.js guide shows the pricing page and this route working together.
Do Stripe subscriptions count as verified revenue?
No. Leverprice verifies Checkout Sessions in payment mode, which are one-time purchases. A session in subscription mode reaches the endpoint and is skipped.
You can still test a subscription price. Stripe accepts a recurring interval in price_data, so the same route can open a subscription at the tested price. Report only the first payment from your own Stripe webhook handler with trackPurchase(), passing the session's metadata. Leverprice labels that revenue unverified. While a Stripe webhook is connected, the default Learn from setting (Automatic) learns from verified purchases only, so set it to Reported in Project settings, or the engine won't use those reports.
Renewals never count toward a test on any provider: each price is judged on first payments minus refunds. If you want subscription first payments verified by a signed webhook, Polar does that today.
What happens when I refund a Stripe payment?
Stripe sends charge.refunded with the total refunded so far, and Leverprice matches it to the sale through the PaymentIntent ID. A full refund turns the sale into a refunded purchase, which adds nothing to that price's revenue. A partial refund keeps the sale and lowers its amount.
The refund event has no tax breakdown, while the sale was recorded before tax. Leverprice caps each refund at the sale amount, so a full refund comes out exact and a partial one takes off slightly more than its pre-tax share.
Can I try it in Stripe test mode first?
Yes. Connect two endpoints in Leverprice, one in Test mode and one in Live, each with its own Stripe destination. Stripe issues a separate secret for every endpoint, and test and live mode never share one (Stripe docs).
Run your app with your pp_sk_test_… key and Stripe test keys, then pay with Stripe's test card 4242 4242 4242 4242 (Stripe docs). The endpoint's row on the Payments page shows when its last event arrived. Leverprice stores test and live purchases apart and reads the livemode flag Stripe puts on every event, so a test sale never reaches live results.
What if a customer pays in another currency?
With Adaptive Pricing, Stripe can charge a customer in their own currency while the Checkout Session still reports the amount in your integration currency, with the local amount in presentment_details. Leverprice reads the session amount, so a sale paid in yen counts at the assigned price, in the experiment's currency. Stripe's docs confirm this applies to prices created inline with price_data, as in the route above.
Regional prices need nothing extra on Stripe: the route already passes quote.currency with quote.price, so a regional price is charged in the currency it was quoted in. A sale in any currency other than the experiment's is converted back at daily reference exchange rates.
Can I test prices with Stripe Payment Links and no code?
Yes, for one-time products. No-code mode is for sites without a backend, such as Webflow, Framer, Carrd or a static page (no-code price testing).
- In Stripe, create one Payment Link per test price and copy its
buy.stripe.comaddress, not a custom-domain one. - In Leverprice, paste each link next to its price.
- Point your Buy button at the product's Leverprice link (
/l/…) from the Install page.
On a click, Leverprice assigns a price, remembers it in a first-party cookie and redirects to that price's Payment Link with a signed client_reference_id. Stripe passes that value to the checkout.session.completed event (Stripe docs), and Leverprice reads the attribution from it.
Your page can't show the tested price in this mode, because no Leverprice code runs there; the visitor first sees it on Stripe's checkout page. Checkout links also carry standard prices only, so regional prices need the server-side route.
What does Leverprice verify on Stripe?
| How you charge | Verified revenue |
|---|---|
Checkout Session in payment mode | Yes |
| Delayed payment method in Checkout | Yes, once the payment succeeds |
| Payment Link for a one-time product | Yes |
Checkout Session in subscription mode | No: report the first payment with trackPurchase() |
| PaymentIntents or Payment Element without Checkout | No: report the sale with trackPurchase() |
| Full refund | Yes, exact |
| Partial refund | Yes, over by its tax share |
Self-reported sales show as unverified and never override a verified purchase of the same order.
Frequently asked questions
Does Leverprice ever need my Stripe secret key?
No. Your server keeps its key and creates every Checkout Session. Leverprice stores only the webhook signing secret, encrypted, and the Payments page refuses keys that start with sk_ or rk_.
Can I keep my existing Stripe webhook handler?
Yes. Leverprice is a separate destination for the same events, and Stripe allows up to 16 destinations per live or sandbox account (Stripe docs). Your handler keeps fulfilling orders as before.
What happens if Leverprice is down during a checkout?
getPrice() returns your fallback price within 500 ms, so the customer pays your normal price. If the Leverprice endpoint misses an event, Stripe retries live-mode deliveries for up to three days (Stripe docs).
How long does a price test on Stripe take?
It depends on sales volume and how far apart the prices are. In our simulations of the production engine, a price that earned 10% more per visitor took a median of 40 days to find at 300 sales a month (full table).