Skip to content
extensionstart

Stripe in a Chrome extension: checkout, webhooks and entitlements that hold up

How a paid Chrome extension takes Stripe payments under Manifest V3: Checkout in a tab, prices by lookup key, a webhook that is the only writer of entitlements, the two Stripe events that race, trials without a card, the customer portal, and how to test it all.

By The ExtensionStart team

You can’t put Stripe inside a Chrome extension, and you don’t need to. Your server creates a Checkout Session, the extension opens it in a tab, Stripe calls your webhook, and the webhook writes the user’s entitlement, which the extension mirrors into chrome.storage. This post walks that flow with the code we ship, including two Stripe events that arrive in either order and, handled naively, leave a new subscriber on the free plan with the trial offered again.

The code is from ExtensionStart, the starter kit we sell, and the screenshots are from its demo, which you can install from the Chrome Web Store. If you haven’t picked a pricing model yet, start with how to monetize a Chrome extension.

Why Stripe can’t run inside the extension

Two reasons:

  1. No remote code. Stripe.js and Elements must load from js.stripe.com, and Manifest V3 does not allow remotely hosted code in extension pages. You could frame a page of your own site that hosts the form, but a popup closes the moment it loses focus, so use a tab.
  2. The bundle is public. Anyone can download your extension and read it. A secret key in there is leaked on day one, and so is any logic that decides who paid.

So the extension never talks to Stripe. It talks to your server, and your server talks to Stripe.

The flow

popup ── "checkout" message ──▶ background
background ── POST /billing/checkout + the user's ID token ──▶ your server
server ── creates a Checkout Session ──▶ its URL opens in a new tab (the popup closes)
user pays on checkout.stripe.com
Stripe ── signed webhook ──▶ POST /billing/webhook
webhook ──▶ writes customers/{uid}   (the only writer)
background ── watches customers/{uid} ──▶ chrome.storage.local.entitlements
popup, side panel and content scripts read storage

The extension sends one thing to start a purchase: the plan’s lookup key, such as premium_monthly. The server decides the price, the user id and everything else.

Checkout: a redirect with the user attached

The server finds the price, then creates the session. This is the kit’s gateway call, trimmed:

const session = await stripe.checkout.sessions.create({
  mode: price.type === "recurring" ? "subscription" : "payment",
  line_items: [{ price: price.id, quantity: 1 }],
  client_reference_id: uid, // who is paying, for the webhook
  metadata: { uid, lookupKey },
  success_url: successUrl,
  cancel_url: cancelUrl,
  allow_promotion_codes: allowPromotionCodes,
  automatic_tax: { enabled: automaticTax },
});

client_reference_id is how the webhook will know whose purchase it is. For a subscription, the kit also copies uid into the subscription’s own metadata, because later events such as renewals and cancellations carry the subscription, not the session.

The checkout route makes two more checks:

  • The route refuses a second subscription once the first is recorded. If the account already has a paid plan and the requested price is recurring, it answers “already subscribed” instead of opening another checkout.
  • One-time buyers get a Stripe customer. In payment mode, Checkout only creates a customer when asked, and the customer portal needs one. Without customer_creation: "always", a lifetime buyer who clicks “Manage billing” gets “no billing account”.

The kit's checkout return page: Payment successful, your purchase is confirmed and reaches the extension within a few seconds, you can close this tab

That return page is a courtesy, not proof. It says the purchase “reaches the extension within a few seconds” because the webhook, not this page, grants it.

Prices by lookup key, never by id

The extension never sends a price id or an amount, so a modified client asking for Pro at one cent has nothing to send. The server looks the price up by its lookup key:

const prices = await stripe.prices.list({
  lookup_keys: [lookupKey],
  active: true,
  limit: 1,
  expand: ["data.product"],
});

Stripe prices can’t be edited. To change an amount, create a new price and move the lookup key to it with transfer_lookup_key. The code only knows premium_monthly, premium_yearly and premium_lifetime, so no release is needed. One caution: the route sells any active lookup key in the account, so keep one Stripe account per product.

The webhook: the only writer of entitlements

Everything that grants or removes access happens here. Four parts, in order.

1. Verify the signature on the raw body. Stripe signs the exact bytes it sends, so verifying a re-serialized body fails. On Firebase, Cloud Functions has already consumed the body by the time your router runs, so reading it again gives you nothing. The kit’s routes read the raw bytes Firebase keeps, through a port:

const payload = typeof rawBody === "string" ? rawBody : new TextDecoder().decode(rawBody);
const event = await stripe.webhooks.constructEventAsync(payload, signature, webhookSecret);

It uses the async variant because the same file also runs on Deno, where Web Crypto is async.

2. Process each event once. Stripe retries a failed delivery for up to three days in live mode, and three times over a few hours in a sandbox. It can also send the same event more than once. The kit records each event id in the same database transaction as the entitlement change, so a replay writes nothing:

const written = await store.applyEvent(event.id, writes);
if (written === null) return { outcome: "duplicate" };

3. Ignore stale status changes, except one kind. Stripe doesn’t guarantee delivery order, so a status change older than the record’s updatedAt is dropped. Stripe’s docs also warn that an event’s created time is in whole seconds and not an ordering signal; the guard uses >=, so two events from the same second both apply, in arrival order.

The exception matters. Stripe stamps customer.subscription.created about a second before checkout.session.completed and delivers the two in either order (a unit test in the kit pins this race). If the session event, which only links the Stripe customer, moved updatedAt forward, the subscription event arriving after it would look stale and be dropped. The account would never record paid or trialUsed: the new subscriber stays on the free plan, and the trial is offered again. So a patch that only links the customer merges without touching the clock:

export function applyDelta(current: EntitlementDoc, delta: EntitlementDelta): EntitlementDoc {
  const { customerId, ...statusPatch } = delta.patch;
  let next = current;
  if (Object.keys(statusPatch).length > 0) {
    if (delta.occurredAt >= current.updatedAt) {
      next = { ...current, ...delta.patch, updatedAt: delta.occurredAt };
    }
  } else if (customerId !== undefined && customerId !== current.customerId) {
    next = { ...current, customerId }; // a link: no clock movement
  }
  if (delta.credits !== undefined) next = applyCredits(next, delta.credits);
  if (next === current) return current;
  next.paid = isPaidStatus(next.status);
  return next;
}

Credit grants skip the stale check too: a skipped grant loses credits someone paid for, and the event-id check already prevents doubles.

4. Derive paid, never set it. One function decides what counts as paid, including a grace period while Stripe retries a failed renewal:

const PAID_STATUSES = new Set(["trialing", "active", "past_due", "lifetime"]);

That grace ends only if your retry settings cancel the subscription or mark it unpaid when the retries run out. If they leave it past due, access never ends.

After each write, the kit also copies paid into the user’s Firebase Auth custom claims. A claim reaches a token only when the token is reissued, and an older token keeps the old value until it refreshes, within the hour. So use the claim for cheap checks, and read the record for anything that decides money.

Trials without a card, once per account

With a trial configured, the kit creates subscription checkouts with payment_method_collection: "if_required" and trial_settings.end_behavior.missing_payment_method: "cancel". The user starts the trial without a card, and if none is added by the end, the subscription cancels instead of failing to charge.

Once per account is enforced where the user can’t reach it: the webhook sets trialUsed on the entitlement record when a trial starts, and checkout for that account leaves the trial out from then on.

The extension side: a mirror, read everywhere

The background watches the user’s record and mirrors each change into chrome.storage.local.entitlements. It is the only writer on the extension side. Billing UI reads it through useBilling(), and feature gates read the paywall’s usePlan() and useFeature(), which the background derives from the same mirror:

const { locked, loading } = useFeature("export-pdf");

The popup closes when the checkout tab opens. If the service worker is still running when the webhook lands, an open side panel updates at once. If Chrome has stopped it, the next time the popup opens the worker restarts, the listener reattaches, and Pro shows. No reload, no polling.

The demo popup's Account tab: Pro with an Active badge, a renewal date, and a Manage billing button

The renewal date in that row comes from the subscription item: since API version 2025-03-31, current_period_end is no longer on the subscription itself. The kit reads both places, so it works on any API version.

A patched copy of the extension can unlock features that run only inside the extension. What goes through your server, such as credits or calls to a paid API, stays enforced.

Cancel and change plans: the customer portal

Don’t build plan management. “Manage billing” asks your server for a customer portal session and opens it in a tab:

const session = await stripe.billingPortal.sessions.create({ customer: customerId, return_url: returnUrl });

Once you turn these on in the portal settings, people cancel, switch plans, update their card and see invoices there. Create the session when they click: an unused portal link expires after five minutes. Every change comes back through the same webhook, so the extension needs no extra code. A cancellation at period end keeps Pro until the paid period runs out, then the customer.subscription.deleted event ends it.

Test it before real money moves

Stripe’s test mode runs the whole flow with no charges:

  1. Run your backend locally and forward webhooks to it with the Stripe CLI. Current versions want the events named along with the target: stripe listen --events checkout.session.completed,customer.subscription.updated --forward-to <your webhook URL>. It prints a whsec_… signing secret for your local config. The kit wraps this as pnpm stripe:listen, which passes the same event list the deployed webhook is registered for.
  2. Buy from the extension with the test card 4242 4242 4242 4242, any future date and any CVC.
  3. Watch the plan row turn to Pro.

Renewals, trial endings and cancellations take a month in real time. Test clocks compress that: you advance a frozen clock, up to two billing periods per step, and Stripe generates the real invoices and events.

The kit’s lifecycle suite runs against Stripe’s test mode (STRIPE_SECRET_KEY=sk_test_… pnpm test:lifecycle). It feeds each real Stripe object through the same mapping and entitlement code as the webhook, and checks what the extension would see. Paraphrased from the suite, for a monthly plan:

  • Trial start: paid, trialing, trial marked used.
  • Trial end: active, after a real invoice is paid under the clock.
  • Cancel at period end: still paid, cancellation pending.
  • Period end: canceled, access revoked.

And for a metered plan with a monthly credit allowance:

  • First paid invoice: the allowance is granted.
  • Renewal: the allowance resets; purchased packs roll over, unused allowance does not.

The suite creates subscriptions through the API with a test card attached. It doesn’t cover Checkout, the no-card trial, the portal or delivery order; the race above is pinned by a unit test instead. Deleting the clock at the end deletes its customer and subscription, so test mode stays clean.

What the store cares about

Stripe itself raises no Chrome Web Store issue. What matters is the listing and the first run. A fresh, unpaid install must do what the listing says. A listing whose basic features need payment must say so, and must make clear that you, not Google, are the seller. The full list is in how to monetize a Chrome extension.

If you build it yourself

Build it in this order: the webhook with signature checks and event-id dedupe first, then the entitlement record and its stale-event rule (with the customer-link exception), then checkout, then the extension’s mirror. The webhook is where the bugs that cost money live, and it’s the part you can’t see from the popup. Comparing payment providers before you commit to Stripe? See Stripe vs Paddle vs Lemon Squeezy vs Polar.

The kit ships all of the above wired together. Its doctor command checks the chain the way you would by hand: the return URLs, the provider secrets, the deployed API and the webhook’s signature check. It also checks the plans the picker sells and the events the Stripe webhook listens for. The billing guide covers each part.

Code from ExtensionStart (WXT 0.21, React 19, stripe-node 20.4). Checked against Stripe’s and Chrome’s documentation on November 14, 2026.

Frequently asked questions

Can I embed Stripe Checkout inside a Chrome extension popup?

Not in a way that works. Stripe.js has to load from Stripe's own server, and Manifest V3 does not allow remotely hosted code in extension pages. Your secret key also can't ship in a bundle anyone can unzip. The pattern that works: your server creates a Checkout Session and the extension opens its URL in a normal tab.

How does the extension know the user has paid?

Stripe calls your webhook, and the webhook writes an entitlement for the user id you attached to the Checkout Session. The extension's background watches that record and mirrors it into chrome.storage, so open surfaces update without a reload, and the popup shows the plan the next time it opens.

Can users edit the extension to unlock paid features?

A patched copy can unlock features that run only inside the extension. What goes through your server, such as credits or calls to a paid API, stays enforced, because the entitlement lives on your server and clients can't write it.

How do I stop users from getting a free trial twice?

Record it on the server. When a trial starts, the webhook marks the account's trial as used, and later Checkout Sessions for that account are created without a trial. A reinstall can't reset a record the extension can't write.

Do I need a backend to sell a Chrome extension subscription with Stripe?

Yes. Something has to hold the Stripe secret key and receive webhooks. It can be small: one serverless function that creates Checkout Sessions, opens the customer portal and handles webhook events, plus one table or collection for entitlements.

How do I test Stripe payments in an extension without real money?

Use Stripe's test mode. Forward webhooks to your local server with `stripe listen`, naming the events you handle, pay with the test card 4242 4242 4242 4242, and use a test clock to move a subscription through its trial, renewal and cancellation in minutes instead of a month.

Written by

The ExtensionStart team

We build ExtensionStart, the starter kit for browser extensions people pay for. Found a mistake or have a question? Write to support@extensionstart.com.

Read next