Build a headless web paywall with Stripe checkout
To build a headless web paywall with BillDog, connect your Stripe account in the dashboard, call BillDog.getOffering('pricing_page') from @billdog.io/web to get the products for a placement, render them in your own components, then call BillDog.purchaseProduct(id) to send the buyer to Stripe Checkout. When they come back, checkEntitlement('premium') tells you whether to unlock.
Steps last checked against the SDK source on 15 Nov 2026.
What you'll build
- A pricing section in your own UI, driven by dashboard offerings
- Stripe Checkout started from your buttons, in test mode
- Premium content unlocked by the
premiumentitlement
What you'll need
- A web app with npm and React 18+ (the web SDK's peer dependency)
- A Stripe account in test mode (
sk_test_key) - A free BillDog project (sign up)
1. Connect Stripe
5 min- In the dashboard, open Settings → Web Checkout.
- Under Stripe Integration → Direct API Keys, paste your Stripe Secret Key (
sk_test_…). - Copy the webhook URL from Manual Webhook Configuration (it includes
?project_id=). In Stripe, open Developers → Webhooks, add an endpoint with that URL and subscribe to every event the page lists, including theasync_paymentones. - Copy the endpoint's signing secret (
whsec_…) from Stripe and paste it into Stripe Webhook Secret. - Turn on Enable Web Checkout and Enable Test Mode, then click Save Web Checkout Settings.
2. Create a product, offering and placement
5 min- Monetization → Products → New Product: set a price, turn on Enable Web Checkout, then click Sync All to create the Stripe price. Already have prices in Stripe? Use Import from Stripe.
- Monetization → Entitlements: create
premiumand attach the product. - Monetization → Offerings → New Offering, then Create Offering. In the editor that opens, click Add Product, tick the product, type a Package Identifier, click Add Package, then Save Changes.
- Monetization → Placements → Create Placement with the identifier
pricing_page, then link the offering and tick Default.
3. Install and configure the web SDK
4 minnpm install @billdog.io/web@^1.2.0-beta.1Create a key under Integration & Data → API Keys → Generate API Key with Environment: Sandbox and Key Type: Public (Client), and copy it from the dialog. It starts bd_public_test_ and is shown only once. Configure on every page load: the checkout finishes on the page the buyer returns to, and the delegate is how you hear about it.
import BillDog from '@billdog.io/web';
BillDog.configure({
apiKey: 'bd_public_test_YOUR_KEY',
delegate: {
onPurchaseCompleted: () => {
if (BillDog.hasEntitlement('premium')) unlockPremium();
},
onWebCheckoutUnconfirmed: (productId, reason) => {
// Stripe hasn't confirmed yet: check again shortly
},
onPurchaseFailed: (productId, message) => {
showError(message); // e.g. the card was declined
},
onPurchaseCancelled: (productId) => {},
},
});
// unlockPremium() and showError() are your own UI functions.The key's environment must match Stripe's mode. A bd_public_test_ key needs Enable Test Mode on; a mismatch is refused with 403 ACCESS_DENIED (reason environment_mismatch).
4. Fetch the offering and render your own UI
6 mingetOffering returns the offering the dashboard assigned to the placement, presentation flags such as holdout and withheld, and any campaign experiment in result.experiment. Render the packages however you like, and record the impression so conversion rates and experiments count it.
// An ES module (top-level await). renderPlans() is your own UI code.
// With pnpm or Yarn, add @billdog.io/core to your dependencies.
import BillDog from '@billdog.io/web';
import { PlacementNotFoundError } from '@billdog.io/core';
try {
const result = await BillDog.getOffering('pricing_page');
const { offering, presentation } = result;
if (offering && !presentation.holdout && !presentation.withheld) {
BillDog.trackPaywallPresented(offering, result.placement);
renderPlans(
offering.packages.map((pkg) => ({
id: pkg.product.id,
title: pkg.product.title,
price: pkg.product.priceString,
})),
);
}
} catch (e) {
if (e instanceof PlacementNotFoundError) console.warn('Check the placement identifier');
else throw e;
}Unlike the mobile register() call, a headless getOffering doesn't create unknown placements; it throws PlacementNotFoundError.
5. Start checkout
3 minpurchaseProduct takes the BillDog product id, creates a Stripe Checkout session and redirects. It resolves true once the buyer has been handed to Stripe, and throws when the server refuses, for example a key/mode mismatch, Web Checkout turned off, or a product with no Stripe price. When checkout can't start or is refused, the SDK already calls your onPurchaseFailed delegate, so show the error there, in one place, and only catch the throw here.
async function buy(productId: string) {
try {
await BillDog.purchaseProduct(productId);
} catch {
// onPurchaseFailed already showed it
}
}Pay with Stripe's test card 4242 4242 4242 4242, any future expiry date and any CVC. Stripe sends the buyer back to the same page (origin and path, without your query string or hash) with ?bd_purchase=success. There, configure() checks the checkout's status and calls onPurchaseCompleted, or onWebCheckoutUnconfirmed if Stripe hasn't confirmed yet.
Because the return URL keeps only the origin and path, a hash-routed app (/#/pricing) comes back to /. Configure the SDK on that page too.
6. Check the entitlement
3 minhasEntitlement is synchronous and reads the cache. checkEntitlement asks the server (cached for up to 5 minutes), so use it before showing paid content.
if (await BillDog.checkEntitlement('premium')) showPremium();To confirm on the server side, switch the dashboard header to Sandbox and open Customers: the purchase and entitlement should be there.