Integration guide
Integrate ExtCharge into your Chrome extension
ExtCharge adds subscriptions and one-time purchases to a browser extension without a backend of your own. You connect your own Stripe account; payments are charges on that account and you are the merchant of record. ExtCharge hosts the plan, checkout and trial pages and tells your extension whether a user has paid. The client targets Chrome Manifest V3 and also runs in Firefox and Edge (it uses webextension-polyfill). The fee is 5% per transaction, with no monthly or setup fee; Stripe's processing fees apply separately.
Using Claude Code, Cursor or Copilot? Let your assistant do it: one prompt asks about your pricing and adds ExtCharge to your extension.
Quick start
- Sign up in the dashboard, connect Stripe, register your extension and add a plan.
- Download
ExtCharge.jsand put it next tobackground.js. - Add the
storagepermission and the ExtCharge content script tomanifest.json. - Call
ExtCharge("your-extension-id").startBackground()in your background script. - Check
user.paidwithgetUser()and callopenPaymentPage()from your upgrade button.
Before you start
Everything here happens in the dashboard:
- Create an account and confirm your email address.
- Connect Stripe. You sign in to your own Stripe account (Stripe Connect, Standard account). ExtCharge never holds your money.
- Register your extension. You get an extension ID such as
my-extension-3fa9c1. Your code passes it toExtCharge(). - Add a plan. Each plan has a name (its nickname), a price, a currency (USD, EUR, GBP, CHF, CAD or AUD) and a billing period: monthly, quarterly, yearly or one-time.
Download the client
The client is a single file, ExtCharge.js (a plain script build for importScripts and <script> tags). It is not on npm yet; download it and ship it inside your extension.
- ExtCharge.js — the file you ship
- ExtCharge.esm.js — the same client as a self-contained ES module, for
"type": "module"service workers:import ExtCharge from "./ExtCharge.esm.js". The payment-page content script still usesExtCharge.js. - ExtCharge.src.js — readable source
- NOTICE — license and attribution
The client is licensed under LGPL-3.0. It is a fork of ExtPay.js 3.1.3 by Glen Chiacchieri and keeps its API.
Put the file in your extension's root folder, next to background.js:
my-extension/
manifest.json
background.js
ExtCharge.js
popup.html
popup.js
manifest.json
A minimal Manifest V3 setup:
{
"manifest_version": 3,
"background": { "service_worker": "background.js" },
"permissions": ["storage"],
"content_scripts": [{
"matches": ["https://pay.extcharge.com/*"],
"js": ["ExtCharge.js"],
"run_at": "document_start"
}]
}
background.service_worker- The script that calls
startBackground(). See Background script. permissions: ["storage"]- Required. The client stores the install's key and the last known user state. Without it the client throws a setup error.
content_scriptsonhttps://pay.extcharge.com/*- Required for
onPaidandonTrialStarted. The hosted pages signal your extension through this content script. Keeprun_at: "document_start". If it is missing, the client throws a setup error that shows the block to copy.
Content Security Policy. If your manifest sets a custom content_security_policy, allow the API:
connect-src https://pay.extcharge.com
Background script
Load the client and call startBackground() once. It must run in the background script; it receives the "paid" and "trial started" signals.
// background.js
importScripts("ExtCharge.js");
const extcharge = ExtCharge("your-extension-id");
extcharge.startBackground();
extcharge.onPaid.addListener(user => {
// The user just paid. Unlock features, show a thank-you page, etc.
console.log("Paid:", user.plan && user.plan.nickname);
});
extcharge.onTrialStarted.addListener(user => {
// The user confirmed their email for a free trial.
console.log("Trial started at", user.trialStartedAt);
});
Firefox: Firefox runs the background as an event page, where importScripts does not exist. In the Firefox build, list the files in manifest.json instead, "background": { "scripts": ["ExtCharge.js", "background.js"] }, and drop the importScripts line.
Register both listeners in the background script. The payment flow behind onPaid:
- The user clicks your upgrade button;
openPaymentPage()opens the hosted page with your plans; the user pays in Stripe Checkout on your Stripe account. - Stripe sends a webhook to ExtCharge, which marks the install as paid.
- The hosted "paid" page signals the extension through the content script;
onPaidfires andgetUser()returnspaid: true.
Check if a user paid
getUser() works in the popup, options page, content scripts and background. In an HTML page, load the client before your script:
<!-- popup.html -->
<button id="upgrade">Upgrade</button>
<script src="ExtCharge.js"></script>
<script src="popup.js"></script>
// popup.js
const extcharge = ExtCharge("your-extension-id");
document.addEventListener("DOMContentLoaded", async () => {
const user = await extcharge.getUser();
if (user.paid) {
enablePro();
} else {
document.querySelector("#upgrade").onclick = () => extcharge.openPaymentPage();
}
});
paid is true for an active subscription or a one-time purchase. For subscriptions it turns false when a payment fails (past_due) and once a canceled subscription's paid period has ended.
| Field | Type | Meaning |
|---|---|---|
paid | boolean | Turn paid features on. |
paidAt | Date | null | When the user first paid. |
email | string | null | The user's email, if known. |
installedAt | Date | When the extension was installed. |
trialStartedAt | Date | null | When the user confirmed a free trial. |
plan | object | null | { unitAmountCents, currency, nickname, interval, intervalCount }; interval is "month", "year" or "once". |
subscriptionStatus | string | null | "active", "past_due" or "canceled". Subscriptions only. |
subscriptionCancelAt | Date | null | When the subscription is set to cancel or did cancel. |
Every install gets a random key on first use. ExtCharge holds no personal data for an install until the user pays or starts a trial.
Open the payment page
openPaymentPage() opens the hosted plan page in a new tab. It lists your plans; the user picks one and pays in Stripe Checkout.
extcharge.openPaymentPage(); // all plans
extcharge.openPaymentPage("Pro yearly"); // straight to Checkout for this plan nickname
To show prices in your own UI, read the plans with getPlans() and pass the chosen nickname on:
const plans = await extcharge.getPlans();
for (const plan of plans) {
const price = (plan.unitAmountCents / 100).toFixed(2) + " " + plan.currency.toUpperCase();
const period = plan.interval === "once"
? "one-time"
: "every " + (plan.intervalCount > 1 ? plan.intervalCount + " " : "") + plan.interval;
const button = document.createElement("button");
button.textContent = `${plan.nickname}: ${price}, ${period}`;
button.onclick = () => extcharge.openPaymentPage(plan.nickname);
document.querySelector("#plans").append(button);
}
A quarterly plan comes back as interval: "month" with intervalCount: 3.
Free trials
openTrialPage() opens a hosted page where the user enters an email address. Once they confirm the link in their inbox, ExtCharge sets trialStartedAt and onTrialStarted fires.
extcharge.openTrialPage("7-day"); // heading: "Start your 7-day free trial"
The argument only changes the heading. Your extension decides how long the trial lasts:
const TRIAL_DAYS = 7;
const user = await extcharge.getUser();
const inTrial = user.trialStartedAt &&
(Date.now() - user.trialStartedAt) < TRIAL_DAYS * 86400e3;
if (user.paid || inTrial) {
enablePro();
}
Clearing storage or reinstalling does not reset a trial. The trial is stored on the server and bound to a confirmed email address. A user with a second email address can start a second trial, as with any email-based trial.
Users on another device
A purchase belongs to the install it was made on. When a customer installs your extension in another browser or on another device, offer a "Log in" link:
document.querySelector("#login").onclick = () => extcharge.openLoginPage();
The hosted page asks for the email the user confirmed or paid with. After the user confirms it, the purchase follows them to the new install.
Subscriptions
Renewals, failed payments and cancellations reach ExtCharge through Stripe webhooks. You write no code for them; read subscriptionStatus when you need detail.
| Status | paid | What happened |
|---|---|---|
active | true | The subscription is paid for. |
past_due | false | The latest payment failed, for example an expired card. |
canceled | false | The user canceled and the last paid period has ended. |
A user who cancels keeps paid: true until the paid period ends; subscriptionCancelAt tells you when.
Customer portal. When an active subscriber opens the payment page (openPaymentPage()), it shows "Manage subscription". That button leads to the Stripe customer portal, where they manage or cancel their subscription.
Refunds. A full refund of a one-time purchase, made in your Stripe Dashboard, sets paid back to false.
Testing
- Load your extension unpacked (
chrome://extensions, developer mode, "Load unpacked"). - Register it in the dashboard and paste your extension ID into
ExtCharge("…"). - Unpacked installs get development keys.
Payments always run in live mode. There is no ExtCharge test mode. To test the full flow:
- Create a cheap one-time plan, for example 1.00.
- Buy it yourself.
onPaidfires andgetUser().paidis true. - Refund the payment in your Stripe Dashboard. The refund revokes
paid.
Going live checklist
- Your extension ID in
ExtCharge("…")matches the dashboard. manifest.jsonhas thestoragepermission and the content script forhttps://pay.extcharge.com/*; a custom CSP allowsconnect-src https://pay.extcharge.com.- Your real plans are in the dashboard; remove the test plan if you no longer need it.
- Your privacy policy names ExtCharge (Solytics GmbH, servers in Frankfurt, Germany) and Stripe as processors of payment data. Transactional emails go out via Amazon SES (USA).
- You have read the data processing agreement and the terms.
- You uploaded the update to the Chrome Web Store (and other stores you list in).
Migrating from ExtPay.js
ExtPay.js / ExtensionPay is a good open-source project, and the ExtCharge client keeps the ExtPay.js 3.1.3 API, so your existing calls keep working. The code change:
- Replace
ExtPay.jswithExtCharge.js, and use the new file name inmanifest.json,importScriptsand<script>tags. - Use your new ExtCharge extension ID. Your existing
ExtPay("…")calls keep working:ExtCharge.jsdefines that name as an alias ofExtCharge("…"). - Change the content script match (and CSP
connect-src) fromextensionpay.comtohttps://pay.extcharge.com/*. - Ship a store update.
Existing paying users do not move automatically. Their purchases live in the old provider's data. openLoginPage() only restores purchases made through ExtCharge. Moving existing subscribers takes manual steps; write to jens.laufer@solytics.de before you switch.
API reference
| Call | Returns | Use |
|---|---|---|
ExtCharge(extensionId) | client | Create the client with the ID from the dashboard. |
startBackground() | — | Background script only. Required once. |
getUser() | Promise<User> | Paid, trial and subscription state. See fields. |
getPlans() | Promise<Plan[]> | Your plans: unitAmountCents, currency, nickname, interval, intervalCount. |
openPaymentPage(planNickname?) | Promise<void> | Hosted plan page, or Checkout for one plan. |
openTrialPage(displayText?) | Promise<void> | Hosted trial sign-up; displayText fills the heading. |
openLoginPage() | Promise<void> | Restore a purchase on another device or browser. |
onPaid.addListener(cb) | — | Background script. cb(user) runs after payment. |
onTrialStarted.addListener(cb) | — | Background script. cb(user) runs after trial confirmation. |
Help
Stuck, or found a gap in this guide? Write to jens.laufer@solytics.de. Include your extension ID and the error message from the extension's console.