extcharge

AI setup

Add payments to your extension with one prompt

Open your extension's folder in Claude Code, Cursor, Copilot or Windsurf and paste this. Your assistant asks how you want to charge, then wires up ExtCharge for you.

Read https://extcharge.com/ai-setup.txt and follow it to add paid plans to this extension.

What your assistant asks

  1. Subscription, one-time purchase, or both?
  2. Plan names, prices and currencies.
  3. A free trial, and how many days?
  4. Which features are paid, and what free users see instead.
  5. Where the Upgrade button goes.

What it does

We tested the prompt on a popup extension with a classic service worker and on one with a module service worker, an options page and a content script. Review the changes like any other pull request.

What it costs

5% per transaction, no monthly fee, no setup fee. Customers pay on Stripe Checkout and the money goes to your own Stripe account. There is no test mode: test with a cheap plan and refund it.

Start earning

The full prompt

If your assistant cannot open URLs, paste the full text instead. Plain text: ai-setup.txt. Prefer doing it by hand? Read the integration guide.

Show the full prompt
# ExtCharge setup for AI coding assistants

You are an AI coding assistant (Claude Code, Cursor, Copilot, Windsurf, or similar) working inside the source folder of a browser extension. Your job: add paid plans to this extension with ExtCharge, guided by the developer's answers. Follow the phases below in order. Do not skip the questions.

## What ExtCharge is (facts — do not add to them)

- Hosted payments for browser extensions. The developer connects their own Stripe account; customers pay on Stripe Checkout; the money goes to the developer's Stripe account. ExtCharge never holds the money.
- Fee: 5% per transaction, no monthly fee, no setup fee. Stripe's processing fees apply separately.
- Plans: subscription (monthly, quarterly, yearly) or one-time purchase. Currencies: USD, EUR, GBP, CHF, CAD, AUD.
- Free trials: started on a hosted page and bound to a confirmed email address on the server, so clearing storage or reinstalling does not reset them. The extension decides how long a trial lasts.
- Dashboard: https://pay.extcharge.com/dashboard?ref=ai-setup (sign up, connect Stripe, register the extension, add plans).
- Client library: a single file, LGPL-3.0, a fork of ExtPay.js 3.1.3 by Glen Chiacchieri with the same API. Not on npm. Downloads:
  - https://extcharge.com/downloads/ExtCharge.js — classic script, for `importScripts` and `<script>` tags.
  - https://extcharge.com/downloads/ExtCharge.esm.js — self-contained ES module, for `"type": "module"` service workers and bundlers: `import ExtCharge from "./ExtCharge.esm.js"`.
- Full guide: https://extcharge.com/docs.html
- There is no test mode. Payments are always real; test with a cheap plan and refund it in Stripe.
- Do not claim anything else about ExtCharge. If something is not covered here or in the guide, say so.

## Phase 1 — Read the project (no edits yet)

0. This prompt targets Manifest V3 (the code below uses promise-based `chrome.*` APIs). If the extension uses `"manifest_version": 2`, stop and tell the developer: migrate to MV3 first, or integrate by hand following https://extcharge.com/docs.html with callback-style APIs.
1. Find `manifest.json` (or the manifest config of a framework such as WXT, Plasmo, CRXJS, or a Vite/webpack setup). Note: manifest version, background script or service worker (and whether it is `"type": "module"`), popup, options page, content scripts, `permissions`, `host_permissions`, `content_security_policy`.
2. Find where static files end up in the built extension (the folder that is copied unchanged, e.g. `public/`, `static/`, or the project root when there is no build step).
3. List the extension's user-facing features (buttons, menu items, settings, context menus, content-script actions) so you can ask which ones are paid.
4. Report a short summary of what you found to the developer. Mention obvious existing problems you noticed (e.g. a missing permission), but do not fix them unless the developer asks.

## Phase 2 — Ask the developer (one question at a time, wait for each answer)

1. Pricing model: subscription, one-time purchase, or both?
2. Prices: for each plan, a short name (lowercase, e.g. `monthly`, `yearly`, `lifetime`), the price, and the currency. Billing for subscriptions: monthly, quarterly or yearly.
3. Free trial: yes or no? If yes, how many days?
4. Which features are paid? Offer the list from Phase 1 and let the developer pick. For EACH paid feature ask what free users get instead (hidden, disabled with an upgrade hint, opens the payment page, or a limited version).
5. Where should the "Upgrade" entry point go (popup button, options page, a hint next to a locked feature)?
6. Does the extension already use ExtPay.js / ExtensionPay? If yes: existing paying users stay with the old provider; tell the developer to contact jens.laufer@solytics.de before switching. Do not promise an automatic migration.

Then repeat the plan back in a short list and ask for confirmation before editing.

## Phase 3 — Onboarding checklist for the developer

Write this checklist with the exact values from Phase 2 and ask the developer to do it now (the code needs the extension ID from step 3):

1. Open https://pay.extcharge.com/dashboard?ref=ai-setup, create an account and confirm the email address.
2. Connect Stripe (sign in to an existing Stripe account or create one).
3. Register the extension. Copy the extension ID it shows (looks like `my-extension-3fa9c1`).
4. Add each plan with exactly these values — plan name, price, currency, billing (monthly, quarterly, yearly or one-time): <list them>. The plan name must match the code exactly.
5. Paste the extension ID here.

While waiting, you may continue with Phase 4 using the placeholder `"YOUR-EXTENSION-ID"` and replace it once you have the ID.

## Phase 4 — Integrate

Make the smallest changes that fit the existing code style. Keep the existing formatting of `manifest.json` and other files. Do not refactor unrelated code.

1. Add the client file next to the scripts that load it (usually the background script's folder), inside the part of the project that is copied unchanged into the build (see Phase 1):
   - Classic service worker or plain `<script>` pages: download `ExtCharge.js`.
   - `"type": "module"` service worker or a bundler: download `ExtCharge.esm.js` and import it.
   - Download with `curl -fsSL -o <path>/ExtCharge.js https://extcharge.com/downloads/ExtCharge.js` (or the `.esm.js` URL). Never load it from the network at runtime: extensions must ship their code.
   - The library is LGPL-3.0: also download `NOTICE`, `LICENSE`, `COPYING.LESSER` and `COPYING` from https://extcharge.com/downloads/ into a folder `licenses/extcharge/` (keep the file names) so the license ships with the extension. The library source is published at https://extcharge.com/downloads/ExtCharge.src.js; nothing else is needed.
   - If the background is a module but the content script needs the classic file, ship both files.
2. Manifest:
   - Add `"storage"` to `permissions` if missing.
   - Add a content script that loads the classic `ExtCharge.js` on the payment pages, running at document start:
     `{ "matches": ["https://pay.extcharge.com/*"], "js": ["ExtCharge.js"], "run_at": "document_start" }`
     The path is relative to the manifest (e.g. `"src/ExtCharge.js"` if the file lives in `src/`). Use the classic file here even if the background uses the ES module.
   - If the manifest has a `content_security_policy` (usually `extension_pages`, which also covers the service worker) that restricts `connect-src`, add `https://pay.extcharge.com`.
   - No extra `host_permissions` are needed.
3. Background: it must start the client created in the shared file from step 4 (never create a second client):
   - Classic MV3 service worker: `importScripts("ExtCharge.js", "pro.js");` at the top, then `extcharge.startBackground();`.
   - Module service worker: `import { extcharge } from "./pro.js";` then `extcharge.startBackground();`.
   - `startBackground()` must run at the top level of the background, on every start of the worker.
   - Refresh the cached access state when it changes: `extcharge.onPaid.addListener(() => getAccess());` and `extcharge.onTrialStarted.addListener(() => getAccess());` (import or load `getAccess` from the shared file). Add other reactions there if wanted (e.g. update the badge).
4. One shared access check. Create the client ONCE in a small shared file next to the client file and reuse it everywhere:
   - Module contexts (module service worker, `<script type="module">` pages): a file like `pro.js`:
     ```js
     import ExtCharge from "./ExtCharge.esm.js";
     export const extcharge = ExtCharge("YOUR-EXTENSION-ID");
     const TRIAL_DAYS = <from Phase 2, or 0>;

     // Access state for gating and for choosing buttons.
     // maxAgeMs > 0 reuses a recent answer instead of asking the server again.
     export async function getAccess(maxAgeMs = 0) {
       const { accessCache } = await chrome.storage.local.get("accessCache");
       if (accessCache && Date.now() - accessCache.at < maxAgeMs) return accessCache;
       try {
         const user = await extcharge.getUser();
         const trialActive = TRIAL_DAYS > 0 && !!user.trialStartedAt &&
           Date.now() - new Date(user.trialStartedAt).getTime() < TRIAL_DAYS * 86400000;
         const access = {
           pro: user.paid || trialActive,
           paid: user.paid,
           trialActive,
           trialUsed: !!user.trialStartedAt,
           subscription: user.paid && user.subscriptionStatus != null, // false for one-time purchases
           at: Date.now(),
         };
         await chrome.storage.local.set({ accessCache: access });
         return access;
       } catch (e) {
         // Offline or server unreachable: use the last known answer.
         return accessCache || { pro: false, paid: false, trialActive: false, trialUsed: false, subscription: false, at: 0 };
       }
     }
     export async function hasPro(maxAgeMs = 0) { return (await getAccess(maxAgeMs)).pro; }
     ```
   - Classic contexts (classic service worker, plain `<script>` pages): the same code without `import`/`export` (`const extcharge = ExtCharge("YOUR-EXTENSION-ID");` at the top), in a file loaded after `ExtCharge.js` (`importScripts("ExtCharge.js", "pro.js")` in the worker; two `<script>` tags in pages, `ExtCharge.js` first). Load it once per context; never declare `extcharge` anywhere else.
   - `getUser()` asks the server and throws when offline; never call it without the fallback above.
   - `user.paid` is true for an active subscription or a one-time purchase; it is false when a subscription is past due or canceled and its paid period ended.
   - Call it inside async functions or after `DOMContentLoaded`, never with top-level `await` in a classic script.
   - Content scripts must not create their own client. Ask the background, and let the background reuse a recent answer so page loads don't each hit the server. If the background already has an `onMessage` listener, add the branch to it instead of adding a second listener:
     ```js
     // background
     chrome.runtime.onMessage.addListener((msg, sender, send) => {
       if (msg.type === "has-pro") { hasPro(10 * 60 * 1000).then(send); return true; }
     });
     // content script (classic script: no top-level await)
     chrome.runtime.sendMessage({ type: "has-pro" }).then((pro) => { if (pro) { /* paid UI */ } });
     ```
   - Gate paid actions where they run: if a paid action is executed in the background (e.g. via a message), check `hasPro()` there too, and answer free users with something like `{ ok: false, reason: "upgrade" }` so the UI can show the upgrade hint or call `openPaymentPage()`.
   - Gating in the extension is a convenience, not security: anything shipped in an extension can be modified by its user. Keep valuable server-side work (if any) behind your own server checks.
5. Upgrade and trial entry points (from Phase 2):
   - Upgrade: `extcharge.openPaymentPage()` shows all plans; `extcharge.openPaymentPage("yearly")` goes straight to one plan (use the exact plan name).
   - Trial: `extcharge.openTrialPage("<N>-day")` — the text only changes the page heading.
   - "Already paid?" link: `extcharge.openLoginPage()` for users on another device or browser.
   - Optional price display: `const plans = await extcharge.getPlans();` → `{ nickname, unitAmountCents, currency, interval, intervalCount }`. `currency` is a lowercase ISO code (`"eur"`), `interval` is `"month"`, `"year"` or `"once"`, and quarterly plans come back as `interval: "month"`, `intervalCount: 3`. Format with `new Intl.NumberFormat(undefined, { style: "currency", currency: p.currency.toUpperCase() }).format(p.unitAmountCents / 100)`.
   - Choose entry points from `getAccess()`: Upgrade while `!paid` (also during a trial); the trial button only while `!paid && !trialUsed` (a trial can be started once per email); "Manage subscription" only when `subscription` is true — it calls `extcharge.openPaymentPage()`, where the Stripe customer portal is offered; one-time buyers see neither Upgrade nor Manage. Keep "Already paid?" visible while `!paid`.
   - A popup closes when the payment or trial page opens in a tab. Re-check `hasPro()` every time the popup or options page opens; use `onPaid` / `onTrialStarted` in the background if the extension should react immediately (e.g. update the badge).
6. Replace `"YOUR-EXTENSION-ID"` with the real ID once the developer has it. The ID must be identical in every file.

## Phase 5 — Verify and hand over

1. Check: manifest is valid JSON; `ExtCharge.js` is present in the build output at the path the manifest and `importScripts` use; the extension ID is set everywhere; no top-level `await` in classic scripts.
2. Tell the developer how to test:
   - Build, open `chrome://extensions`, enable Developer mode, "Load unpacked". Open the service worker console: there must be no "ExtCharge setup error".
   - Click Upgrade, buy the cheapest plan with a real card, confirm the paid features unlock, then refund the payment in the Stripe Dashboard (a full refund of a one-time purchase removes access; for subscriptions cancel in the customer portal).
   - If a trial is offered: start it, confirm the email link, check the trial features, and check that they lock after the trial (temporarily set `TRIAL_DAYS` to 0 to see the locked state).
3. Going live checklist: ship a store update; mention in the store listing and privacy policy that payments are processed by Stripe via ExtCharge (data processing agreement: https://extcharge.com/dpa.html).
4. Finish with a short summary of every file you changed and why.