diff --git a/FAQ.md b/FAQ.md index 5c5c8a15..83b8a382 100644 --- a/FAQ.md +++ b/FAQ.md @@ -166,7 +166,7 @@ The runtime and model are free, open source (Apache-2.0) and need no API key or genclass.dev service are defined in `billing/plans.json`, which the collector and the pricing page read, and it defines three (since 2026-11-11). Free is what finds, shows and fixes the problems: the dashboard's problems for one person, 3 apps and the last 7 days, the coding-agent loop on your machine, and the GitHub App on public repositories. -Team, US$50 a developer a month (US$15 in Canada), adds the GitHub App on private repositories, visitor analytics, forwarding, data +Team, US$50 a developer a month, adds the GitHub App on private repositories, visitor analytics, forwarding, data export, 90 days of history and members. Enterprise, agreed by email, adds your own classifier, which GenClass trains, GenClass's models in its cloud, a year of history and contract terms. Your data is kept 90 days on every plan, so an upgrade shows what was counted before it. A collector you host yourself locks nothing. The pricing page shows the diff --git a/README.md b/README.md index 580ed645..22ec301e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ npx genclass # signs you in, starts Pro, adds GenClass to your app and walks y Run it in your web app's folder and press Enter for each step: account, Pro, runtime, app plan, dashboard, test workflow, GitHub App, coding agent, suggestions. The command comes with Pro: 3 days free, then US$50 a developer a -month (US$15 in Canada). The card is asked for on Stripe when the trial starts, and nothing is charged if you cancel before the 3 days +month. The card is asked for on Stripe when the trial starts, and nothing is charged if you cancel before the 3 days end. Free stays on the website ([pricing](https://genclass.dev/pricing)). A step that does not fit your project is skipped, Enter also stops any wait, and running it again continues from where things are. It draws nothing on your pages. Then: @@ -204,7 +204,7 @@ GenClass's GitHub App puts what the runtime saw on the pull request it was seen the GenClass fixture, your workflow uploads the race files it writes, and the app posts one check and one comment: each finding with its test, the seeds it was flagged in and the evidence line. It reads those files and never your source code, it comments only where it is installed, and it is free on public repositories. Private repositories -come with Pro (US$50 a developer a month (US$15 in Canada); [pricing](https://genclass.dev/pricing)). +come with Pro (US$50 a developer a month; [pricing](https://genclass.dev/pricing)). > **Install** at (the app is GenClass.dev, ). With > no change to your tests, one workflow file is the whole setup: the check on your first pull request links to it, @@ -249,7 +249,7 @@ export const submitOrder = protect("checkout submit", (cart) => fetch("/api/orde - **Token and dashboard.** A token (`gc_` plus 22 letters and digits, public) groups your app's diagnostics under a private dashboard link (`https://genclass.dev/dashboard/...`). On Free the dashboard shows an app's totals for the - last 7 days, for one app in an account. Pro (US$50 a developer a month (US$15 in Canada), up to 3 apps in an account) adds every + last 7 days, for one app in an account. Pro (US$50 a developer a month, up to 3 apps in an account) adds every problem with its pages and a fix prompt, visitor analytics, forwarding, export, 90 days of history and team members; more apps come with Enterprise ([pricing](https://genclass.dev/pricing)). Plans bought before 13 November 2026 keep every app they cover (an app paid for on its own does not count toward Pro's 3); Free covers an account's oldest app diff --git a/billing/plans.json b/billing/plans.json index d0de0c43..903971af 100644 --- a/billing/plans.json +++ b/billing/plans.json @@ -1,5 +1,5 @@ { - "_about": "The one place GenClass plans are defined. telemetry-worker/src/plans.ts imports this file (limits, entitlements, Stripe lookup keys, the billing page) and genclass.dev's site reads it (the pricing page). Three plans since version 3 (2026-11-11): Free, Team (named Pro since 2026-11-12) and Enterprise; version 4 (2026-11-12) sold a plan per project; version 5 (2026-11-13, below) sells Pro for the account again. The history up to version 4 follows. Free is what finds, shows and fixes the problems: the open-source runtime with every mode and its on-device model, the coding-agent loop on the developer's machine, the dashboard's problems for an account's first 3 projects (the last 7 days shown; a 4th project on Free is locked until it has a plan), and 100 problems fixed live a month per project (limits.live_fixes_per_month; past it the runtime is told to observe only until the month ends) and genclass-dev[bot] on public repositories. Team is sold per project (per_project true: one Stripe subscription of quantity 1 per project, its metadata naming the project; everyone on the account's team sees it; telemetry-worker/src/stripe.ts) and adds what a team uses: genclass-dev[bot] on private repositories, visitor analytics, forwarding, export, 90 days of history and members. Enterprise is agreed by email: a null monthly price means the plan is not sold on the site, and an account gets it from GenClass's own grant (accounts.comp_until, set by hand to the end of the agreement; accounts.comp_plan names the plan granted, grant_plan when it is empty). The classifier a person from GenClass trains is in Enterprise only. retired_plans lists the plan ids GenClass sold before (Pro and Custom until 2026-10-19, Individual until 2026-10-22): their Stripe products and prices stay GenClass's own, so a subscription to one is still cancelled with its account, opens Manage billing and is reported to the owner while it bills, but it gives no plan (it reads as Free). The worker's Stripe code and scripts/stripe-setup.mjs sell any plan given a monthly price above 0, its stripe_lookup_keys and a stripe_tax_code. Prices are US cents (per project for a per_project plan, per seat for a per_seat plan); a null yearly price means no yearly option. limits.apps null means no plan limit (the worker still caps an account at 200 apps against abuse); limits.seats is how many people a plan that is not per_seat holds (null: no limit); limits.history_days is what the dashboard shows, and data is never deleted before 90 days whatever the plan, so the longer history is there the moment an account upgrades. Ingest never depends on the plan: an app's visitor analytics are counted while its plan leaves them out, and shown once it includes them. Pro (id team; named Team until 2026-11-12) has a trial: trial_days (3) days free at Checkout, a card taken up front and charged when it ends unless cancelled, once per account (telemetry-worker/src/billing.ts trialFor). Feature lines with available false are shown as coming next. The entitlement github_private is what lets genclass-dev[bot], the GitHub App, review an account's private repositories (telemetry-worker/src/github/entitlement.ts); public repositories are reviewed for everyone, whatever this file says. A self-hosted collector sets PLAN_GATES = \"open\" and gives every account the grant plan. managed_payments true would sell a plan through Stripe Managed Payments (only for fully automated digital products; telemetry-worker/README.md, Paid plans). `suggestions` (2026-11-12): what `genclass suggest` gives a plan (telemetry-worker/src/suggest.ts): `per_day`, model runs an account has a day, and `shown`, how many items of the plan it is shown (null: all); the measured checks themselves are free for everyone. Entitlements `problems` (the problem lists, pages, activity and fix prompts on the dashboard and in the genclass command; Free shows only the totals) and `ask` (genclass ask) were added 2026-11-12 (the owner's 'limit free fully'); a plan file without the key gives them. Version 5 (2026-11-13, the owner's call): Pro is bought for the account again, not per app, and per developer (per_seat: the subscription's quantity is how many developers, the owner included, US$15 each a month); it covers up to 3 apps (limits.apps) whatever the number of developers, the oldest first, and a later app waits on its plan page, where more apps are Enterprise's, by email. A subscription bought per project under version 4 still covers its app, is not counted in the 3 and holds the whole team (no seat count); an account subscription from before version 5 keeps covering the apps the account had when migration 0021 was applied (accounts.apps_kept) while it lasts. Free covers one app. GenClass's grants cover every app. The genclass command is Pro's (2026-11-13, the owner's 'make the entire CLI paid'): a CLI session without Pro, its trial or a paying team gets 402 from every /api/cli route but the overview and the account; Free is the website's, with the owner's words for its list: one app, a limited dashboard, the open-source basics, and (the owner's 'keep them free') the GitHub App on public repositories, the page check and 100 live fixes a month. Prices by country (2026-11-16, the owner's call): a plan's price_usd_cents and stripe_lookup_keys are what it costs everywhere but the countries its country_prices list (ISO 3166-1 alpha-2 codes, as Cloudflare reports the visitor's country). Pro is US$50 a developer a month everywhere but Canada, where it stays US$15 under the lookup key it was sold under before (genclass_team_monthly, so every subscription on it keeps its price). Checkout sells the price of the country the request comes from (telemetry-worker/src/plans.ts priceFor); a request with no country gets the plan's own price. A subscription keeps the price it was bought at. stripe_product (on a plan, for its own price, or on a country price) names the Stripe product that price is on; left out, the plan's main product genclass_. Pro's US$50 price is on genclass_team_world, because Stripe's Billing Portal allows only one monthly price per product for seat changes; both products are named GenClass Pro and carry metadata genclass_plan team.", + "_about": "The one place GenClass plans are defined. telemetry-worker/src/plans.ts imports this file (limits, entitlements, Stripe lookup keys, the billing page) and genclass.dev's site reads it (the pricing page). Three plans since version 3 (2026-11-11): Free, Team (named Pro since 2026-11-12) and Enterprise; version 4 (2026-11-12) sold a plan per project; version 5 (2026-11-13, below) sells Pro for the account again. The history up to version 4 follows. Free is what finds, shows and fixes the problems: the open-source runtime with every mode and its on-device model, the coding-agent loop on the developer's machine, the dashboard's problems for an account's first 3 projects (the last 7 days shown; a 4th project on Free is locked until it has a plan), and 100 problems fixed live a month per project (limits.live_fixes_per_month; past it the runtime is told to observe only until the month ends) and genclass-dev[bot] on public repositories. Team is sold per project (per_project true: one Stripe subscription of quantity 1 per project, its metadata naming the project; everyone on the account's team sees it; telemetry-worker/src/stripe.ts) and adds what a team uses: genclass-dev[bot] on private repositories, visitor analytics, forwarding, export, 90 days of history and members. Enterprise is agreed by email: a null monthly price means the plan is not sold on the site, and an account gets it from GenClass's own grant (accounts.comp_until, set by hand to the end of the agreement; accounts.comp_plan names the plan granted, grant_plan when it is empty). The classifier a person from GenClass trains is in Enterprise only. retired_plans lists the plan ids GenClass sold before (Pro and Custom until 2026-10-19, Individual until 2026-10-22): their Stripe products and prices stay GenClass's own, so a subscription to one is still cancelled with its account, opens Manage billing and is reported to the owner while it bills, but it gives no plan (it reads as Free). The worker's Stripe code and scripts/stripe-setup.mjs sell any plan given a monthly price above 0, its stripe_lookup_keys and a stripe_tax_code. Prices are US cents (per project for a per_project plan, per seat for a per_seat plan); a null yearly price means no yearly option. limits.apps null means no plan limit (the worker still caps an account at 200 apps against abuse); limits.seats is how many people a plan that is not per_seat holds (null: no limit); limits.history_days is what the dashboard shows, and data is never deleted before 90 days whatever the plan, so the longer history is there the moment an account upgrades. Ingest never depends on the plan: an app's visitor analytics are counted while its plan leaves them out, and shown once it includes them. Pro (id team; named Team until 2026-11-12) has a trial: trial_days (3) days free at Checkout, a card taken up front and charged when it ends unless cancelled, once per account (telemetry-worker/src/billing.ts trialFor). Feature lines with available false are shown as coming next. The entitlement github_private is what lets genclass-dev[bot], the GitHub App, review an account's private repositories (telemetry-worker/src/github/entitlement.ts); public repositories are reviewed for everyone, whatever this file says. A self-hosted collector sets PLAN_GATES = \"open\" and gives every account the grant plan. managed_payments true would sell a plan through Stripe Managed Payments (only for fully automated digital products; telemetry-worker/README.md, Paid plans). `suggestions` (2026-11-12): what `genclass suggest` gives a plan (telemetry-worker/src/suggest.ts): `per_day`, model runs an account has a day, and `shown`, how many items of the plan it is shown (null: all); the measured checks themselves are free for everyone. Entitlements `problems` (the problem lists, pages, activity and fix prompts on the dashboard and in the genclass command; Free shows only the totals) and `ask` (genclass ask) were added 2026-11-12 (the owner's 'limit free fully'); a plan file without the key gives them. Version 5 (2026-11-13, the owner's call): Pro is bought for the account again, not per app, and per developer (per_seat: the subscription's quantity is how many developers, the owner included, US$15 each a month); it covers up to 3 apps (limits.apps) whatever the number of developers, the oldest first, and a later app waits on its plan page, where more apps are Enterprise's, by email. A subscription bought per project under version 4 still covers its app, is not counted in the 3 and holds the whole team (no seat count); an account subscription from before version 5 keeps covering the apps the account had when migration 0021 was applied (accounts.apps_kept) while it lasts. Free covers one app. GenClass's grants cover every app. The genclass command is Pro's (2026-11-13, the owner's 'make the entire CLI paid'): a CLI session without Pro, its trial or a paying team gets 402 from every /api/cli route but the overview and the account; Free is the website's, with the owner's words for its list: one app, a limited dashboard, the open-source basics, and (the owner's 'keep them free') the GitHub App on public repositories, the page check and 100 live fixes a month. Pro is US$50 a developer a month since 2026-11-16 (US$15 from 2026-11-11). The Worker secret PLANS_PRIVATE can add prices to a plan (telemetry-worker/src/plans.ts usePrivatePlans); this file holds none.", "version": 5, "currency": "usd", "contact": "mehar@genclass.dev", @@ -36,11 +36,7 @@ "name": "Pro", "summary": "Everything for up to 3 apps, per developer.", "price_usd_cents": { "monthly": 5000, "yearly": null }, - "stripe_lookup_keys": { "monthly": "genclass_team_world_monthly", "yearly": null }, - "stripe_product": "genclass_team_world", - "country_prices": [ - { "countries": ["CA"], "name": "Canada", "price_usd_cents": { "monthly": 1500, "yearly": null }, "stripe_lookup_keys": { "monthly": "genclass_team_monthly", "yearly": null } } - ], + "stripe_lookup_keys": { "monthly": "genclass_team_monthly", "yearly": null }, "stripe_tax_code": "txcd_10103001", "managed_payments": false, "per_seat": true, diff --git a/docs/runtime/DASHBOARD.md b/docs/runtime/DASHBOARD.md index 618ddbd8..a044de9e 100644 --- a/docs/runtime/DASHBOARD.md +++ b/docs/runtime/DASHBOARD.md @@ -13,7 +13,7 @@ Each web app gets a **project key** (token: `gc_` + 22 letters and digits) that dashboard at genclass.dev. The key is public: it ships in your page and can only add telemetry to its app. Keep the dashboards in a GenClass account, or use one private link per app without an account. The dashboard is free for every app: what GenClass found, on which pages and what it did, for the last 7 days and up to 3 apps in an account. The Team -plan (US$50 a developer a month (US$15 in Canada)) adds visitor analytics, forwarding, export, 90 days of history, unlimited apps and +plan (US$50 a developer a month) adds visitor analytics, forwarding, export, 90 days of history, unlimited apps and members, who open your apps' dashboards with their own sign-in (Plan and billing, Team: make an invite link and send it; it works once, for 7 days). Enterprise adds a year of history and your own classifier, which a person from GenClass trains on your app's traffic, bug reports or labelled examples ([pricing](https://genclass.dev/pricing)). diff --git a/package-lock.json b/package-lock.json index f000351e..feb13fea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16819,7 +16819,7 @@ }, "packages/cli": { "name": "genclass", - "version": "0.3.11", + "version": "0.3.12", "license": "Apache-2.0", "bin": { "genclass": "bin/genclass.mjs" diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 1c4ea488..f38edaeb 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,9 +1,13 @@ # Changelog +## 0.3.12 + +- Before sign-in the command says Pro is 3 days free, then US$50 a developer a month, the price on genclass.dev. + ## 0.3.11 -- **Pro's price by country**: before sign-in the command says Pro is 3 days free, then US$50 a developer a month - (US$15 in Canada). After sign-in it prints the price genclass.dev gives for where you are, as before. +- **Pro's price**: before sign-in the command says Pro is 3 days free, then US$50 a developer a month. After sign-in it + prints the price genclass.dev gives, as before. - **It installs `@genclass/runtime` 0.3.0-beta.7.** Setup still draws nothing on your pages. In an app set up by an older `init`, which added the dev-only overlay, the runtime step now names the file that still loads it and the line to delete. diff --git a/packages/cli/README.md b/packages/cli/README.md index 563564e2..c16fc9be 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -9,7 +9,7 @@ npx genclass Run it in your web app's folder. It shows where the project stands and walks you through the next step: one Enter per step. Stop at any point and run it again: it continues from what is true now. It comes with Pro: 3 days free, -then US$50 a developer a month (US$15 in Canada). +then US$50 a developer a month. ```text ╭─ GenClass ────────────────────────────────────────────── v0.3.7 ─╮ @@ -71,7 +71,7 @@ also a command of its own (`npx genclass problems`), so scripts and coding agent **The command comes with Pro.** Right after the sign-in, an account without Pro sees Pro's card, and Enter opens its checkout in the browser: 3 days free (one trial per account; the card is asked for on Stripe, and nothing is charged -if you cancel before they end), then US$50 a developer a month (US$15 in Canada), for up to 3 apps in the account. More apps come with +if you cancel before they end), then US$50 a developer a month, for up to 3 apps in the account. More apps come with Enterprise, by email. Every command but `login`, `logout`, `whoami`, `plan`, `upgrade`, `profile`, `status`, `remove`, `help` and `version` asks first. Without a terminal (`--yes`, `--json`, a coding agent) nothing is opened: one line with the checkout address, and exit code 1. Free stays on the website: one app's totals for the last 7 days. diff --git a/packages/cli/package.json b/packages/cli/package.json index 5ea13c86..ea643fa5 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "genclass", - "version": "0.3.11", + "version": "0.3.12", "description": "GenClass CLI: one command that sets GenClass up, shows your app in the terminal (problems, analytics, events), hands problems to your coding agent, answers questions about your app and tells you what it is missing.", "type": "module", "license": "Apache-2.0", diff --git a/packages/cli/src/cli.mjs b/packages/cli/src/cli.mjs index bd6d782d..c2edbd7f 100644 --- a/packages/cli/src/cli.mjs +++ b/packages/cli/src/cli.mjs @@ -74,7 +74,7 @@ export function usage(cols = width()) { }; text("genclass: GenClass in your terminal. Set it up, see what it finds, have it fixed."); lines.push(""); - text("The genclass command comes with Pro: 3 days free, then $50 / developer / month ($15 in Canada), with a card on Stripe. Without Pro: login, logout, whoami, status, plan, upgrade, profile, remove, help. Free is on the website: https://genclass.dev", " "); + text("The genclass command comes with Pro: 3 days free, then $50 / developer / month, with a card on Stripe. Without Pro: login, logout, whoami, status, plan, upgrade, profile, remove, help. Free is on the website: https://genclass.dev", " "); const side = w >= 78; const col = 30; for (const [head, rows] of HELP) { diff --git a/packages/cli/src/state.mjs b/packages/cli/src/state.mjs index 29eb8e1d..0f31806f 100644 --- a/packages/cli/src/state.mjs +++ b/packages/cli/src/state.mjs @@ -70,7 +70,7 @@ export function hasPlaywright(cwd, project) { } /** What the command costs, said before the sign-in (the server says it in its own words once signed in). */ -export const PRO_TERMS = "The genclass command comes with Pro: 3 days free, then $50 / developer / month ($15 in Canada)."; +export const PRO_TERMS = "The genclass command comes with Pro: 3 days free, then $50 / developer / month, card on Stripe."; /** Free's limits as a few words ("3 apps, 7 days of history, your top 3 suggestions"), from the numbers the server sent. */ export function freeLimits(free) { @@ -199,7 +199,7 @@ export async function readState(o = {}, deps = {}) { // Pro: the price is said only to someone new (the 0.3.9 user stories: it was quoted to a payer after logout) why: creds || st.token ? `Opens ${host.overridden && !host.error ? new URL(host.host).host : "genclass.dev"} to sign you in again.` - : `Opens ${host.overridden && !host.error ? new URL(host.host).host : "genclass.dev"}. Then Pro: 3 days free, then $50 / developer / month ($15 in Canada).`, + : `Opens ${host.overridden && !host.error ? new URL(host.host).host : "genclass.dev"}. Then Pro: 3 days free, then $50 / developer / month, with a card on Stripe.`, more: `Your account is where your apps, their dashboards and your plan live. New here? It is made on that page. Nothing is typed in the terminal. ${PRO_TERMS} Free stays on the website: one app and its totals.`, run: "npx genclass login", human: "approve the sign-in in your browser", @@ -218,7 +218,7 @@ export async function readState(o = {}, deps = {}) { detail: !me ? creds || st.token ? "" - : "3 days free, then $50 / developer / month ($15 in Canada)" + : "3 days free, then $50 / developer / month" : cli && !cli.paid ? `${cli.price ?? cli.plan}${cli.trialDays ? `, ${cli.trialDays} days free` : ""}` : cli?.paid && cli.via === "team" diff --git a/packages/cli/test/actions.test.ts b/packages/cli/test/actions.test.ts index b2bf0ce1..eb9ff4b4 100644 --- a/packages/cli/test/actions.test.ts +++ b/packages/cli/test/actions.test.ts @@ -266,7 +266,7 @@ describe("genclass: the command line (src/cli.mjs, src/main.mjs)", () => { expect(lines.filter((l) => l.length > max), String(cols)).toEqual([]); expect(lines.join("\n")).toContain("npx genclass dashboard"); } - expect(usage(60).replace(/\s+/g, " ")).toContain("$50 / developer / month ($15 in Canada)"); + expect(usage(60).replace(/\s+/g, " ")).toContain("$50 / developer / month"); // the browser opens only for someone at a terminal (none here: a coding agent, CI, a pipe), never with --no-browser expect(openBrowser("https://genclass.dev/account", {})).toBe(false); expect(openBrowser("https://genclass.dev/account", { noBrowser: true })).toBe(false); diff --git a/packages/cli/test/state.test.ts b/packages/cli/test/state.test.ts index 5146035a..ca417a56 100644 --- a/packages/cli/test/state.test.ts +++ b/packages/cli/test/state.test.ts @@ -216,8 +216,8 @@ describe("genclass: the state of a project (src/state.mjs header)", () => { const s = await readState({ cwd: dir, skip: ["account"] }, { runGit: noGit }); expect(s.next).toBeNull(); // before the sign-in, the first screen says what the command costs - expect(s.steps[0].why).toBe("Opens genclass.dev. Then Pro: 3 days free, then $50 / developer / month ($15 in Canada)."); - expect(s.steps[1].detail).toBe("3 days free, then $50 / developer / month ($15 in Canada)"); + expect(s.steps[0].why).toBe("Opens genclass.dev. Then Pro: 3 days free, then $50 / developer / month, with a card on Stripe."); + expect(s.steps[1].detail).toBe("3 days free, then $50 / developer / month"); // with Pro, a skipped step is not the next one signIn(); const fetchFn = fakeServer({ "GET /api/cli/overview": { json: overview({ plan: { id: "team", name: "Pro" }, cli: { paid: true, via: "plan" } }) } }).fetchFn; diff --git a/packages/runtime/README.md b/packages/runtime/README.md index 63dec5e5..8ff4510c 100644 --- a/packages/runtime/README.md +++ b/packages/runtime/README.md @@ -838,7 +838,7 @@ digits) that groups its diagnostics on a dashboard at genclass.dev, kept in a Ge then `connect`, `whoami`, `logout`) or behind one private link per app (anyone with the link can open it), which `init` saves in `.genclass.local` and `npx @genclass/runtime@beta dashboard` prints again (from `0.3.0-beta.2`; `--open` opens it). On Free the dashboard shows an app's totals for the last 7 days, for one app in an account, and -the `@genclass/mcp` server for coding agents is free. Pro, US$50 a developer a month (US$15 in Canada) for up to 3 apps in an account, +the `@genclass/mcp` server for coding agents is free. Pro, US$50 a developer a month for up to 3 apps in an account, adds every problem with its pages and a fix prompt, visitor analytics, forwarding, export, 90 days of history, team members and the `genclass` command; more apps, your own classifier, which a person from GenClass trains, and a year of history come with Enterprise ([pricing](https://genclass.dev/pricing)). Plans bought before 13 November 2026 keep diff --git a/scripts/stripe-setup.mjs b/scripts/stripe-setup.mjs index 0c8dd150..f392e826 100644 --- a/scripts/stripe-setup.mjs +++ b/scripts/stripe-setup.mjs @@ -19,10 +19,11 @@ // 2. each plan's monthly price under its lookup key from billing/plans.json (all start with genclass_). Prices are // read only by those lookup keys; a key on another product's price stops the script. A changed amount gets a new // price: the old one is archived and keeps a genclass_..._retired_ lookup key, so its subscribers stay -// on it and on their plan (the worker reads a plan from a genclass_ lookup key and the product's metadata). A -// plan's country prices (country_prices: Pro is US$15 in Canada and US$50 elsewhere, 2026-11-16) are made the -// same way; a price that names a product (stripe_product: Pro's own, genclass_team_world) is on that product, -// with the plan's name and metadata, because the Billing Portal's seat changes allow one monthly price a product; +// on it and on their plan (the worker reads a plan from a genclass_ lookup key and the product's metadata). The +// private prices (GENCLASS_PLANS_PRIVATE, the JSON of the Worker secret PLANS_PRIVATE, or GENCLASS_PLANS_PRIVATE_FILE +// naming a file that holds it; never committed) are made the same way; a price that names a product (stripe_product, +// on a plan for its own price or on one of its country_prices) is on that product, with the plan's name and +// metadata, because the Billing Portal's seat changes allow one monthly price a product; // 3. its webhook endpoint https://genclass.dev/api/billing/webhook with the description "GenClass billing", for the // events the worker handles and no others (the customer.subscription events, invoice.paid, charge.refunded and // charge.dispute.created; the worker reads only ids and amounts from the last three, which carry the buyer's @@ -71,6 +72,17 @@ const stripeTs = readFileSync(join(WORKER, "src/stripe.ts"), "utf8"); export const API_VERSION = /export const STRIPE_VERSION = "([^"]+)"/.exec(stripeTs)?.[1]; export const EVENTS = [...(/export const WEBHOOK_EVENTS = \[([^\]]+)\]/.exec(stripeTs)?.[1] ?? "").matchAll(/"([a-z_.]+)"/g)].map((m) => m[1]); const PLANS = JSON.parse(readFileSync(process.env.GENCLASS_PLANS_FILE ? resolve(process.env.GENCLASS_PLANS_FILE) : join(ROOT, "billing/plans.json"), "utf8")); +// the private prices, as the Worker secret PLANS_PRIVATE holds them: { plans: { : { stripe_product?, country_prices? } } } +{ + const raw = process.env.GENCLASS_PLANS_PRIVATE ?? (process.env.GENCLASS_PLANS_PRIVATE_FILE ? readFileSync(resolve(process.env.GENCLASS_PLANS_PRIVATE_FILE), "utf8") : ""); + const extra = raw ? JSON.parse(raw).plans ?? {} : {}; + for (const plan of PLANS.plans) { + const x = extra[plan.id]; + if (!x) continue; + if (typeof x.stripe_product === "string") plan.stripe_product = x.stripe_product; + if (Array.isArray(x.country_prices)) plan.country_prices = x.country_prices; + } +} /** The names of the plans sold on the site (a monthly price above 0), for the printed steps. */ const SOLD = PLANS.plans.filter((p) => p.price_usd_cents.monthly > 0).map((p) => p.name); @@ -205,9 +217,9 @@ export async function main({ argv = process.argv.slice(2), env = process.env, fe const out = []; for (const plan of PLANS.plans.filter((p) => p.price_usd_cents.monthly > 0)) { const main = `genclass_${plan.id}`; - // the plan's own price, then its country prices (billing/plans.json country_prices: Pro is US$15 in Canada); a - // price that names a product (stripe_product) is on that one, the others on the plan's main product, because - // the Billing Portal's seat changes allow one monthly price a product + // the plan's own price, then the private ones (GENCLASS_PLANS_PRIVATE); a price that names a product + // (stripe_product) is on that one, the others on the plan's main product, because the Billing Portal's seat + // changes allow one monthly price a product const groups = new Map(); for (const entry of [plan, ...(plan.country_prices ?? [])]) { const id = entry.stripe_product ?? main; @@ -230,7 +242,7 @@ export async function main({ argv = process.argv.slice(2), env = process.env, fe if (price && price.product !== (product?.id ?? id)) { fail(`the lookup key ${lookup} is on price ${price.id} of product ${price.product}, not on GenClass's product ${product?.id ?? id}; this script does not touch it. Nothing was changed.`); } - prices.push({ interval, field, lookup, cents, price: price ?? null, label: entry === plan ? "" : ` (${entry.name})` }); + prices.push({ interval, field, lookup, cents, price: price ?? null, label: entry === plan ? "" : ` (${entry.name ?? entry.countries?.join(", ") ?? "other"})` }); } } out.push({ plan, id, product, prices }); diff --git a/telemetry-worker/README.md b/telemetry-worker/README.md index dd9ab533..b2cc989a 100644 --- a/telemetry-worker/README.md +++ b/telemetry-worker/README.md @@ -5,7 +5,7 @@ Cloudflare Worker that receives the default-on diagnostics batches from `@gencla a token and a private dashboard on genclass.dev, and that holds the optional accounts (Google, an email and a password, or GitHub, with passkeys as extra security) which keep several apps in one place and let `npx @genclass/runtime@beta login` connect an app ([Accounts](#accounts)). There are three plans (`billing/plans.json` version 5, since 2026-11-13): Free, one app with -its totals, on the website; Pro (plan id `team`), US$50 per developer a month (US$15 in Canada) for up to 3 apps, with the genclass +its totals, on the website; Pro (plan id `team`), US$50 per developer a month for up to 3 apps, with the genclass command, every problem, visitor analytics, forwarding, export, 90 days of history, private repositories for the GitHub App and members ([Teams](#teams)), 3 days free at the first Checkout; and Enterprise, by agreement, with more apps and your own classifier, which GenClass trains ([Paid plans](#paid-plans)). What was bought before 13 November @@ -534,26 +534,17 @@ npx --yes wrangler@4 d1 execute genclass-dashboard --remote --command " ## Paid plans -**Prices by country (2026-11-16, the owner's call).** Pro is US$50 a developer a month everywhere but Canada, where -it stays US$15. `billing/plans.json` gives Pro its own price (US$50, lookup key `genclass_team_world_monthly`, on the -Stripe product `genclass_team_world`, named by `stripe_product`) and `country_prices` (Canada: US$15 under -`genclass_team_monthly`, the key Pro was sold under before, on the product `genclass_team`). Checkout sells the price -of the country Cloudflare reports for the request (`request.cf.country`; `src/plans.ts` countryOf, priceFor) and -records it on the session (metadata `genclass_price`); an open Checkout page for another price, or one made before this -change, is closed and a new one made. A request with no country gets the plan's own price. The billing pages, the -plan pages and the genclass command's answers show the visitor's price; a message read later (the report email, the -seats message) says both ("$50 / developer / month ($15 in Canada)"). Every subscription keeps the price it was bought -at: the live subscription on `genclass_team_monthly` stays at US$15 wherever its buyer is. Both products are named -GenClass Pro with metadata `genclass_plan` team, because Stripe's Billing Portal allows one monthly price per product -for seat changes; the portal configuration lists each product with its own price. The country is the visitor's IP -address as Cloudflare sees it, so a VPN in Canada gets the Canadian price; nothing checks the card's country. -Promotion codes are typed on Stripe's Checkout page (`allow_promotion_codes`): `EFLAUNCH` (coupon "EF launch", 20% off -for as long as the subscription lasts, both Pro products, new customers only) was made in the live account on -2026-11-16. +**Private prices.** The Worker secret `PLANS_PRIVATE` can give a plan more prices than `billing/plans.json` (same +JSON shape as the plan's own price, with the countries each applies to; `src/plans.ts` usePrivatePlans), and +`scripts/stripe-setup.mjs` reads the same JSON from `GENCLASS_PLANS_PRIVATE`. It is never committed. Checkout sells the +price for the country Cloudflare reports for the request and records it on the session (metadata `genclass_price`); an +open Checkout page for another price is closed and a new one made. Without the secret every buyer gets the plan's own +price. A price on its own product (`stripe_product`) keeps the Billing Portal's seat changes, which allow one monthly +price per product. **Version 5 (2026-11-13, the owner's calls; what follows below is the history it replaces where they differ).** Pro (id `team`) is bought for the account again, not per app, and per developer: `per_seat` true, the -subscription's quantity is how many developers (US$15 each a month then; see Prices by country below), and it covers up to 3 apps (`limits.apps`) +subscription's quantity is how many developers (US$15 each a month then, US$50 since 2026-11-16), and it covers up to 3 apps (`limits.apps`) whatever the number of developers, oldest first (`src/plans.ts` coverage, accessIn). An app past them is locked `pro_apps`: its plan page says more apps come with Enterprise, by email (a mailto button, no purchase). A subscription bought per project under version 4 still covers its own app (never locked) and gives the account diff --git a/telemetry-worker/src/collector.ts b/telemetry-worker/src/collector.ts index d35f8879..21c3ca75 100644 --- a/telemetry-worker/src/collector.ts +++ b/telemetry-worker/src/collector.ts @@ -60,7 +60,7 @@ import { afterBatch } from "./paid.js"; import { dashboardPage, notFoundPage, openSourcePage, ownEndpoint, securityHeaders, setupCommand, setupPage, startPage } from "./pages.js"; import { lockedLink } from "./locked.js"; import { applyLock, linkSession, linkUnlocked, lockKind, lockedJson, readBody, readLock, routeLink, startPasskeyOptions, unlockPage } from "./link-lock.js"; -import { countryOf, firstPlanWith, hasAnalytics, hasDashboard, hasProblems, pickRange, problemsLock, projectAccess, viewRanges } from "./plans.js"; +import { countryOf, firstPlanWith, hasAnalytics, hasDashboard, hasProblems, pickRange, problemsLock, projectAccess, usePrivatePlans, viewRanges } from "./plans.js"; import { SAMPLE_PROJECT, SAMPLE_SECRET, sampleStats } from "./sample.js"; export const SCHEMA = "genclass-telemetry/1"; @@ -117,6 +117,8 @@ export interface Env extends GithubEnv { STRIPE_WEBHOOK_SECRET?: string; STRIPE_WEBHOOK_SECRET_TEST?: string; STRIPE_TEST_ACCOUNTS?: string; + /** Private prices for some plans (src/plans.ts usePrivatePlans); a secret, never in wrangler.toml. */ + PLANS_PRIVATE?: string; /** GenClass's own Billing Portal configuration (bpc_...), for a live key and for a test key; scripts/stripe-setup.mjs * stores the one for its key's mode. Without it the portal answers 503. */ STRIPE_PORTAL_CONFIGURATION?: string; @@ -229,6 +231,7 @@ export interface HandleOptions { } export async function handle(request: Request, env: Env, opts: HandleOptions = {}): Promise { + usePrivatePlans(env.PLANS_PRIVATE); const url = new URL(request.url); const path = url.pathname.replace(/\/+$/, ""); diff --git a/telemetry-worker/src/plans.ts b/telemetry-worker/src/plans.ts index d2003d3f..73c5165b 100644 --- a/telemetry-worker/src/plans.ts +++ b/telemetry-worker/src/plans.ts @@ -6,7 +6,7 @@ // price, a limit or an entitlement there, not here. Every check below reads the plan's entitlements and limits, so // nothing here names a plan but Free and the grant's (plans.json grant_plan). // - Since plans.json version 3 (2026-11-11) there are three plans. Free is what finds, shows and fixes the problems: the -// dashboard's problems for one person, 3 apps and the last 7 days shown. Team (US$15 a month per seat then, sold on Stripe +// dashboard's problems for one person, 3 apps and the last 7 days shown. Team (US$15 a month per seat, sold on Stripe // Checkout) adds visitor analytics, forwarding, export, 90 days shown, private repositories for the GitHub App and // members (src/team.ts). Enterprise (by agreement) adds the classifier a person trains (custom_model) and a year. // Individual, US$29 a month, ended on 2026-10-22: a stored "individual" reads as Free, while its Stripe prices stay @@ -21,10 +21,10 @@ // - A plan comes from accounts.plan, which src/stripe.ts derives from the Stripe subscription. Entitlements follow the // plan whatever the server's configuration, except that a plan bought in Stripe's test mode counts only while the // key is a test key (inMode): a test purchase never carries over to live. A live plan always counts. -// - Prices by country (2026-11-16): a plan's price_usd_cents and stripe_lookup_keys are what it costs everywhere but -// the countries its country_prices list (Pro: US$50 a developer a month, US$15 in Canada). Checkout sells the price -// of the country Cloudflare reports for the request (countryOf, priceFor); the screens show it (priceText). Every -// lookup key of a plan, its own or a country's, gives the plan (planByLookupKey), and a subscription keeps its price. +// - Private prices: the Worker secret PLANS_PRIVATE (usePrivatePlans; never in this repository) may give a plan other +// prices for some countries. Checkout sells the price of the country Cloudflare reports for the request (countryOf, +// priceFor) and the screens show it (priceText); without the secret every buyer gets plans.json's price. Every lookup +// key of a plan, plans.json's or the secret's, gives the plan (planByLookupKey), and a subscription keeps its price. // - A plan with a null monthly price (Enterprise) is not sold on the site: it is agreed by email, and an account gets // it from GenClass's own grant (accounts.comp_until, set by hand to the end of the agreement), which gives the plan // accounts.comp_plan names (plans.json grant_plan when it is empty or unknown). When an account has both a paid plan @@ -70,13 +70,6 @@ export interface Plan { /** US cents; monthly null: not sold on the site, agreed by email (byAgreement). */ price_usd_cents: { monthly: number | null; yearly: number | null }; stripe_lookup_keys: { monthly: string | null; yearly: string | null }; - /** - * Prices in some countries instead of the plan's own (2026-11-16: Pro is US$15 in Canada, US$50 elsewhere): Checkout - * sells the price of the country the request comes from (priceFor); every lookup key here gives the plan. - */ - country_prices?: CountryPrice[]; - /** The Stripe product the plan's own price is on (scripts/stripe-setup.mjs); left out: genclass_. */ - stripe_product?: string; /** The Stripe product tax code scripts/stripe-setup.mjs sets on the plan's product (null for Free). */ stripe_tax_code: string | null; /** Sold through Stripe Managed Payments (src/stripe.ts managedPayments): none today. */ @@ -104,19 +97,16 @@ export interface Plan { features: { text: string; available: boolean }[]; } -/** A plan's price in some countries (plans.json country_prices): ISO 3166-1 alpha-2 codes, as Cloudflare reports them. */ -export interface CountryPrice { - countries: string[]; - /** The countries in words, for "($15 in Canada)". */ - name: string; +/** A price: a plan's own (plans.json), or one the private secret gives it for some countries. */ +export interface PlanPrice { price_usd_cents: { monthly: number | null; yearly: number | null }; stripe_lookup_keys: { monthly: string | null; yearly: string | null }; - /** The Stripe product this price is on (scripts/stripe-setup.mjs); left out: the plan's genclass_. */ - stripe_product?: string; } -/** A price as plans.json writes one: a plan's own, or one of its country prices. */ -export type PlanPrice = Pick; +/** A plan's price for some countries (PLANS_PRIVATE): ISO 3166-1 alpha-2 codes, as Cloudflare reports them. */ +export interface CountryPrice extends PlanPrice { + countries: string[]; +} export interface PlansFile { version: number; @@ -150,10 +140,49 @@ export const RETIRED_PLAN_IDS: readonly string[] = Array.isArray(PLANS_FILE.reti /** Every GenClass lookup key starts with this: plans.json's, and those of prices scripts/stripe-setup.mjs retired. */ export const LOOKUP_PREFIX = "genclass_"; -/** Every price a plan has: its own, then its country prices (plans.json country_prices). */ -export const planPrices = (plan: Plan): PlanPrice[] => [plan, ...(plan.country_prices ?? [])]; +// ------------------------------------------------------------------------------------- private prices (PLANS_PRIVATE) + +let privateRaw: string | undefined; +let privatePrices = new Map(); + +const cents = (v: unknown): number | null => (typeof v === "number" && Number.isInteger(v) && v > 0 ? v : null); +const key = (v: unknown): string | null => (typeof v === "string" && v.startsWith("genclass_") && v.length <= 200 ? v : null); + +/** + * Reads the Worker secret PLANS_PRIVATE (JSON: { "plans": { "": { "country_prices": [{ "countries": ["XX"], + * "price_usd_cents": { "monthly": 1234 }, "stripe_lookup_keys": { "monthly": "genclass_..." } }] } } }), once per value. + * A price with no country, no positive monthly cents or no genclass_ lookup key is left out, and anything that does not + * parse gives no private prices: every buyer then gets plans.json's price. Other keys in the secret (stripe_product, + * names) are for scripts/stripe-setup.mjs and are ignored here. Called by handle() for every request. + */ +export function usePrivatePlans(raw: string | undefined): void { + if (raw === privateRaw) return; + privateRaw = raw; + const next = new Map(); + try { + const plans = raw ? (JSON.parse(raw) as { plans?: Record }).plans : undefined; + for (const [id, p] of Object.entries(plans && typeof plans === "object" ? plans : {})) { + if (!PLANS.some((x) => x.id === id) || !Array.isArray(p?.country_prices)) continue; + const list: CountryPrice[] = []; + for (const x of p.country_prices as Record[]) { + const countries = Array.isArray(x?.countries) ? x.countries.filter((c: unknown): c is string => typeof c === "string" && /^[A-Z][A-Z0-9]$/.test(c)) : []; + const monthly = cents(x?.price_usd_cents?.monthly); + const lookup = key(x?.stripe_lookup_keys?.monthly); + if (!countries.length || monthly === null || !lookup) continue; + list.push({ countries, price_usd_cents: { monthly, yearly: null }, stripe_lookup_keys: { monthly: lookup, yearly: null } }); + } + if (list.length) next.set(id, list); + } + } catch { + next.clear(); + } + privatePrices = next; +} + +/** Every price a plan has: its own (plans.json), then those PLANS_PRIVATE gives it. */ +export const planPrices = (plan: Plan): PlanPrice[] => [plan, ...(privatePrices.get(plan.id) ?? [])]; -/** The plan a lookup_key from billing/plans.json sells (monthly or yearly, its own price or a country's), or null for any other key. */ +/** The plan a lookup_key sells (monthly or yearly, plans.json's or PLANS_PRIVATE's), or null for any other key. */ export function planByLookupKey(key: unknown): Plan | null { if (typeof key !== "string" || !key) return null; return PLANS.find((p) => planPrices(p).some((x) => x.stripe_lookup_keys.monthly === key || x.stripe_lookup_keys.yearly === key)) ?? null; @@ -170,12 +199,12 @@ export function countryOf(req: Request | null | undefined): string | null { } /** - * What a plan costs in this country: the country price that lists it (plans.json country_prices), else the plan's own - * (also when the country is not known). Checkout sells its lookup key; the screens show its price. + * What a plan costs in this country: the private price that lists it (PLANS_PRIVATE), else the plan's own (also when + * the country is not known). Checkout sells its lookup key; the screens show its price. */ export function priceFor(plan: Plan, country: string | null | undefined): PlanPrice { const c = (country ?? "").toUpperCase(); - return (c && plan.country_prices?.find((x) => x.countries.includes(c))) || plan; + return (c && privatePrices.get(plan.id)?.find((x) => x.countries.includes(c))) || plan; } /** The paid plan named by a Stripe product's (or price's) metadata.genclass_plan (scripts/stripe-setup.mjs sets it). */ @@ -247,19 +276,14 @@ export function canBuy(env: Env, account: { id: string; email: string | null }): export const dollars = (cents: number): string => `$${cents % 100 ? (cents / 100).toFixed(2) : String(cents / 100)}`; /** - * "$29 / month", "$50 / developer / month" (a per_seat plan), "$0", or "By agreement" for a plan agreed by email, in - * the visitor's country (priceFor). `country` left out: the reader's country is not known (an email, a message read - * later), so a plan with country prices names them too: "$50 / developer / month ($15 in Canada)". null: the request - * had no country, so the plan's own price. + * "$29 / month", "$50 / developer / month" (a per_seat plan), "$0", or "By agreement" for a plan agreed by email, for + * the visitor's country (priceFor); with no country (an email, a message read later), the plan's own price. */ export function priceText(plan: Plan, country?: string | null): string { - const unit = (c: number): string => `${dollars(c)}${plan.per_project === true ? " / project" : plan.per_seat === true ? " / developer" : ""} / month`; const c = priceFor(plan, country).price_usd_cents.monthly; if (c === null) return "By agreement"; if (!c) return "$0"; - if (country !== undefined) return unit(c); - const others = (plan.country_prices ?? []).filter((x) => (x.price_usd_cents.monthly ?? 0) > 0).map((x) => `${dollars(x.price_usd_cents.monthly!)} in ${x.name}`); - return others.length ? `${unit(c)} (${others.join(", ")})` : unit(c); + return `${dollars(c)}${plan.per_project === true ? " / project" : plan.per_seat === true ? " / developer" : ""} / month`; } /** diff --git a/telemetry-worker/src/stripe.ts b/telemetry-worker/src/stripe.ts index f0ac97b6..853eedf8 100644 --- a/telemetry-worker/src/stripe.ts +++ b/telemetry-worker/src/stripe.ts @@ -410,7 +410,7 @@ export async function checkoutSession( ): Promise { // free days only on a first subscription (the caller decides), never on a switch, and only what Stripe allows (1 to 730) const trialDays = !o.switchFrom && Number.isInteger(o.trialDays) && o.trialDays! >= 1 && o.trialDays! <= 730 ? o.trialDays! : 0; - // the price of the buyer's country (plans.json country_prices: Pro is US$15 in Canada), else the plan's own + // the price for the buyer's country (src/plans.ts priceFor), else the plan's own const lookup = priceFor(o.plan, o.country).stripe_lookup_keys.monthly; if (!lookup) throw new StripeError(`the ${o.plan.name} plan has no monthly price`, 400); // a plan sold per seat: the quantity is the seats asked for, and the buyer can still change it on Stripe's page @@ -426,7 +426,7 @@ export async function checkoutSession( if ((x.metadata?.genclass_project ?? undefined) !== o.project?.id) continue; const same = x.metadata?.genclass_plan === o.plan.id && - // a page for another country's price is closed, and so is one made before prices by country (no genclass_price) + // a page for another price is closed, and so is one made before the session named its price (genclass_price) x.metadata?.genclass_price === lookup && (x.metadata?.genclass_switch_from ?? undefined) === o.switchFrom && x.metadata?.genclass_trial !== "1" && diff --git a/telemetry-worker/test/account-helpers.ts b/telemetry-worker/test/account-helpers.ts index 588e175d..0436a167 100644 --- a/telemetry-worker/test/account-helpers.ts +++ b/telemetry-worker/test/account-helpers.ts @@ -364,13 +364,13 @@ export function fakeStripe(o: { answer?: (url: URL, init: RequestInit) => Respon return { fetch, calls, other, customers, subs, sessions, invoices, refunds, charges, paymentIntents, portal, genclassCustomer }; } -/** The GenClass prices the fake Stripe knows by lookup key: the fixture's (Pro, Custom), the retired Individual and the real plans' Pro (Canada's price and everyone else's). */ +/** The GenClass prices the fake Stripe knows by lookup key: the fixture's (Pro, Custom), the retired Individual, the real plans' Pro and a private price the tests give it. */ const KNOWN_PRICES: Record = { genclass_pro_monthly: { plan: "pro", id: "price_pro000001" }, genclass_custom_monthly: { plan: "custom", id: "price_custom0001" }, genclass_individual_monthly: { plan: "individual", id: "price_indiv00001" }, genclass_team_monthly: { plan: "team", id: "price_team000001" }, - genclass_team_world_monthly: { plan: "team", id: "price_teamworld1" }, + genclass_team_zz_monthly: { plan: "team", id: "price_teamzz00001" }, }; /** A price as a subscription fetched with its products expanded shows it: GenClass's carry product metadata genclass_plan. */ diff --git a/telemetry-worker/test/country-prices.test.ts b/telemetry-worker/test/country-prices.test.ts deleted file mode 100644 index e0019488..00000000 --- a/telemetry-worker/test/country-prices.test.ts +++ /dev/null @@ -1,127 +0,0 @@ -// Prices by country (billing/plans.json country_prices, the owner's call of 2026-11-16): Pro is US$50 a developer a -// month everywhere but Canada, where it stays US$15 under the lookup key it was sold under before -// (genclass_team_monthly). Checkout sells the price of the country Cloudflare reports for the request (request.cf.country); -// a request with no country gets the plan's own price; every lookup key of the plan gives Pro; the screens show the -// visitor's price, and a message read later (an email) names both. -import { beforeEach, describe, expect, it } from "vitest"; -import { resetTokenCache } from "../src/dashboard.js"; -import { resetOwnerCache } from "../src/paid.js"; -import { countryOf, planById, planByLookupKey, planForPrice, priceFor, priceText, problemsLock } from "../src/plans.js"; -import { CLI_ACCOUNT_FROM } from "../src/cli.js"; -import { resetStripeCache } from "../src/stripe.js"; -import { call, cliToken, createApp, fakeStripe, GENCLASS_PORTAL, price, resetClock, setNow, setup, signedIn, WEBHOOK_SECRET } from "./account-helpers.js"; - -const LIVE = { STRIPE_SECRET_KEY: "sk_live_fake", STRIPE_WEBHOOK_SECRET: WEBHOOK_SECRET, STRIPE_PORTAL_CONFIGURATION: GENCLASS_PORTAL }; -const PRO = planById("team"); - -beforeEach(() => { - resetClock(); - resetTokenCache(); - resetOwnerCache(); - resetStripeCache(); -}); - -async function buyer() { - const t = setup(LIVE); - const a = await signedIn(t.env); - const s = fakeStripe(); - t.sql.db.prepare("UPDATE accounts SET stripe_customer_id = 'cus_ada0000001', stripe_mode = 'live' WHERE id = ?").run(a.account.id); - s.genclassCustomer("cus_ada0000001", a.account.id); - await createApp(t.env, a.cookie, "Shop"); - return { ...t, ...a, s }; -} -const sessionsOf = (s: ReturnType) => s.calls.filter((c) => c.method === "POST" && c.url.pathname === "/v1/checkout/sessions").map((c) => Object.fromEntries(c.form!)); - -describe("prices by country (billing/plans.json country_prices)", () => { - it("Pro is $50 a developer a month, $15 in Canada; both lookup keys give Pro", () => { - expect(PRO.price_usd_cents.monthly).toBe(5000); - expect(priceFor(PRO, "CA")).toMatchObject({ price_usd_cents: { monthly: 1500 }, stripe_lookup_keys: { monthly: "genclass_team_monthly" } }); - for (const c of ["US", "GB", "IN", "XX", "T1", null, undefined]) expect(priceFor(PRO, c).stripe_lookup_keys.monthly, String(c)).toBe("genclass_team_world_monthly"); - expect(priceFor(PRO, "ca").price_usd_cents.monthly).toBe(1500); - expect(planByLookupKey("genclass_team_monthly")?.id).toBe("team"); - expect(planByLookupKey("genclass_team_world_monthly")?.id).toBe("team"); - // a price on either Pro product is GenClass's Pro - expect(planForPrice(price("genclass_team_world_monthly", { product: "genclass_team_world" }))?.id).toBe("team"); - expect(planForPrice(price("genclass_team_monthly"))?.id).toBe("team"); - }); - - it("the price text: the visitor's country's, the plan's own without one, both for a reader whose country is not known", () => { - expect(priceText(PRO, "CA")).toBe("$15 / developer / month"); - expect(priceText(PRO, "US")).toBe("$50 / developer / month"); - expect(priceText(PRO, null)).toBe("$50 / developer / month"); - expect(priceText(PRO)).toBe("$50 / developer / month ($15 in Canada)"); - expect(priceText(planById("free"), "CA")).toBe("$0"); - expect(priceText(planById("enterprise"), "CA")).toBe("By agreement"); - expect(problemsLock("https://genclass.dev/account/billing", "CA").price).toBe("$15 / developer / month"); - }); - - it("countryOf reads Cloudflare's request.cf.country, and nothing else", () => { - const req = (cf?: unknown) => { - const r = new Request("https://genclass.dev/"); - if (cf !== undefined) Object.defineProperty(r, "cf", { value: cf }); - return r; - }; - expect(countryOf(req({ country: "CA" }))).toBe("CA"); - expect(countryOf(req({ country: "us" }))).toBe("US"); - expect(countryOf(req({ country: "T1" }))).toBe("T1"); - for (const cf of [undefined, null, {}, { country: "" }, { country: "Canada" }, { country: 1 }]) expect(countryOf(req(cf)), JSON.stringify(cf)).toBeNull(); - expect(countryOf(null)).toBeNull(); - // a header saying Canada is not Cloudflare's word - expect(countryOf(new Request("https://genclass.dev/", { headers: { "cf-ipcountry": "CA" } }))).toBeNull(); - }); - - it("Checkout from Canada sells the $15 price, from anywhere else the $50 one, and says which on the session", async () => { - for (const [country, priceId, key] of [["CA", "price_team000001", "genclass_team_monthly"], ["US", "price_teamworld1", "genclass_team_world_monthly"], [undefined, "price_teamworld1", "genclass_team_world_monthly"]] as const) { - resetStripeCache(); - const b = await buyer(); - const r = await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, ...(country ? { country } : {}) }); - expect(r.status, String(country)).toBe(200); - const [form] = sessionsOf(b.s); - expect(form, String(country)).toMatchObject({ "line_items[0][price]": priceId, "metadata[genclass_plan]": "team", "metadata[genclass_price]": key, allow_promotion_codes: "true" }); - // Stripe was asked for that price by its lookup key only - const asked = b.s.calls.filter((c) => c.method === "GET" && c.url.pathname === "/v1/prices").map((c) => c.url.searchParams.get("lookup_keys[0]")); - expect(asked, String(country)).toEqual([key]); - } - }); - - it("an open Checkout page for the other country's price, or one made before prices by country, is closed, not reused", async () => { - const b = await buyer(); - expect((await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, country: "CA" })).status).toBe(200); - const first = [...b.s.sessions.values()][0] as any; - expect(first.metadata.genclass_price).toBe("genclass_team_monthly"); - // the same country again: the same page - const again = (await (await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, country: "CA" })).json()) as any; - expect(again.url).toBe(first.url); - // from elsewhere: the Canadian page is closed and a $50 one made - const other = (await (await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, country: "DE" })).json()) as any; - expect(other.url).not.toBe(first.url); - expect(b.s.calls.some((c) => c.method === "POST" && c.url.pathname === `/v1/checkout/sessions/${first.id}/expire`)).toBe(true); - expect(sessionsOf(b.s).at(-1)).toMatchObject({ "line_items[0][price]": "price_teamworld1", "metadata[genclass_price]": "genclass_team_world_monthly" }); - // a page from before (no genclass_price) is closed too - const old = [...b.s.sessions.values()].at(-1) as any; - delete old.metadata.genclass_price; - const after = (await (await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, country: "DE" })).json()) as any; - expect(after.url).not.toBe(old.url); - }); - - it("the billing page and the genclass command show the visitor's price", async () => { - const b = await buyer(); - const ca = await (await call(b.env, "GET", "/account/billing", { cookie: b.cookie, country: "CA" })).text(); - expect(ca).toContain('

$15 / developer / month

'); - expect(ca).not.toContain("$50"); - const us = await (await call(b.env, "GET", "/account/billing", { cookie: b.cookie, country: "US" })).text(); - expect(us).toContain('

$50 / developer / month

'); - expect(us).not.toContain("$15 /"); - // the genclass command, on a new account approved after the approval page listed the account route - setNow(new Date(Date.parse(CLI_ACCOUNT_FROM) + 3_600_000)); - const t = setup(LIVE); - const me = await signedIn(t.env, "grace@example.com"); - const token = await cliToken(t.env, me.cookie); - for (const [country, want] of [["CA", "$15 / developer / month"], ["FR", "$50 / developer / month"]] as const) { - const res = await call(t.env, "GET", "/api/cli/account", { bearer: token, origin: null, country }); - const cli = (await res.json()) as any; - expect(res.status, JSON.stringify(cli)).toBe(200); - expect(cli.cli.price, country).toBe(want); - } - }); -}); diff --git a/telemetry-worker/test/pages.test.ts b/telemetry-worker/test/pages.test.ts index c304092b..403c4106 100644 --- a/telemetry-worker/test/pages.test.ts +++ b/telemetry-worker/test/pages.test.ts @@ -655,7 +655,7 @@ describe("dashboard page: interaction analytics (docs/runtime/ANALYTICS.md secti const { doc, text, hidden, close } = await render(st); expect(hidden("prolock")).toBe(false); expect(text("#prolock b")).toBe("Free shows the totals"); - expect(text("#prolockmsg")).toBe("Every problem, the pages it happens on, what GenClass did about it and a fix prompt for your coding agent come with Pro. 3 days free, then $50 / developer / month ($15 in Canada). Cancel any time."); + expect(text("#prolockmsg")).toBe("Every problem, the pages it happens on, what GenClass did about it and a fix prompt for your coding agent come with Pro. 3 days free, then $50 / developer / month. Cancel any time."); expect(doc.getElementById("prolocka")!.getAttribute("href")).toBe("https://genclass.dev/account/billing?project=p1"); expect(text("#prolocka")).toBe("Start your 3-day free trial"); // the lists give way to the banner, so an empty list never reads as "no problems" diff --git a/telemetry-worker/test/plans.test.ts b/telemetry-worker/test/plans.test.ts index d8e086b2..746102e2 100644 --- a/telemetry-worker/test/plans.test.ts +++ b/telemetry-worker/test/plans.test.ts @@ -54,14 +54,14 @@ describe("billing/plans.json: the one source of plans", () => { expect(PLANS.map((p) => p.name)).toEqual(["Free", "Pro", "Enterprise"]); const [free, team, enterprise] = PLANS; expect(free!.price_usd_cents).toEqual({ monthly: 0, yearly: null }); - // US$50 a developer a month (US$15 in Canada, 2026-11-16; US$15 everywhere from 2026-11-13), for up to 3 apps + // US$50 a developer a month (2026-11-16; US$15 from 2026-11-11), for up to 3 apps expect(team!.price_usd_cents).toEqual({ monthly: 5000, yearly: null }); - expect(team!.country_prices).toEqual([{ countries: ["CA"], name: "Canada", price_usd_cents: { monthly: 1500, yearly: null }, stripe_lookup_keys: { monthly: "genclass_team_monthly", yearly: null } }]); - expect(team!.stripe_product).toBe("genclass_team_world"); + // nothing in the file but the plan's own price + expect(Object.keys(team!)).not.toContain("country_prices"); expect(enterprise!.price_usd_cents).toEqual({ monthly: null, yearly: null }); expect(PLANS.map((p) => p.stripe_lookup_keys)).toEqual([ { monthly: null, yearly: null }, - { monthly: "genclass_team_world_monthly", yearly: null }, + { monthly: "genclass_team_monthly", yearly: null }, { monthly: null, yearly: null }, ]); // Free: finds and fixes the problems and shows their totals, for one person and one app (version 5); the problem @@ -108,10 +108,9 @@ describe("billing/plans.json: the one source of plans", () => { expect(GRANT_PLAN.id).toBe("enterprise"); expect(FREE.id).toBe("free"); expect(priceText(free!)).toBe("$0"); - expect(priceText(team!)).toBe("$50 / developer / month ($15 in Canada)"); + expect(priceText(team!)).toBe("$50 / developer / month"); expect(priceText(enterprise!)).toBe("By agreement"); expect(planByLookupKey("genclass_team_monthly")?.id).toBe("team"); - expect(planByLookupKey("genclass_team_world_monthly")?.id).toBe("team"); // Individual (until 2026-10-22) and the plans before it name no plan any more for (const k of ["genclass_individual_monthly", "genclass_pro_monthly"]) expect(planByLookupKey(k), k).toBeNull(); expect(viewRanges(free!)).toEqual(["24h", "7d"]); @@ -137,7 +136,7 @@ describe("billing/plans.json: the one source of plans", () => { // the plan an upgrade names: the first one on sale with it expect(firstPaidWith("problems")?.id).toBe("team"); expect(firstPaidWith("ask")?.id).toBe("team"); - expect(problemsLock("https://genclass.dev/account/billing?project=p1")).toEqual({ plan: "Pro", upgrade_url: "https://genclass.dev/account/billing?project=p1", trial_days: 3, price: "$50 / developer / month ($15 in Canada)" }); + expect(problemsLock("https://genclass.dev/account/billing?project=p1")).toEqual({ plan: "Pro", upgrade_url: "https://genclass.dev/account/billing?project=p1", trial_days: 3, price: "$50 / developer / month" }); // the per-seat plans of version 3 (test/fixtures/plans-v3-seats.json) say nothing of them: every plan gives them const v3 = (SEATS_JSON as any).plans as Plan[]; expect(v3.every((p) => !("problems" in p.entitlements) && !("ask" in p.entitlements))).toBe(true); diff --git a/telemetry-worker/test/private-prices.test.ts b/telemetry-worker/test/private-prices.test.ts new file mode 100644 index 00000000..8dee48ed --- /dev/null +++ b/telemetry-worker/test/private-prices.test.ts @@ -0,0 +1,150 @@ +// Private prices (the Worker secret PLANS_PRIVATE, src/plans.ts usePrivatePlans): a plan can have other prices for some +// countries, never written in this repository. Checkout sells the price for the country Cloudflare reports for the +// request (request.cf.country); a request with no country, or no secret, gets plans.json's price; every lookup key of +// the plan gives it; the screens show the visitor's price, and a message read later shows plans.json's. The values here +// are made up ("ZZ" is no country). +import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { CLI_ACCOUNT_FROM } from "../src/cli.js"; +import { resetTokenCache } from "../src/dashboard.js"; +import { resetOwnerCache } from "../src/paid.js"; +import { countryOf, planById, planByLookupKey, planForPrice, priceFor, priceText, problemsLock, usePrivatePlans } from "../src/plans.js"; +import { resetStripeCache } from "../src/stripe.js"; +import { call, cliToken, createApp, fakeStripe, GENCLASS_PORTAL, price, resetClock, setNow, setup, signedIn, WEBHOOK_SECRET } from "./account-helpers.js"; + +const PRIVATE = JSON.stringify({ + plans: { + team: { + stripe_product: "genclass_team_alt", + country_prices: [{ countries: ["ZZ"], name: "Zedland", price_usd_cents: { monthly: 2000, yearly: null }, stripe_lookup_keys: { monthly: "genclass_team_zz_monthly", yearly: null } }], + }, + }, +}); +const LIVE = { STRIPE_SECRET_KEY: "sk_live_fake", STRIPE_WEBHOOK_SECRET: WEBHOOK_SECRET, STRIPE_PORTAL_CONFIGURATION: GENCLASS_PORTAL, PLANS_PRIVATE: PRIVATE }; +const PRO = planById("team"); + +beforeEach(() => { + resetClock(); + resetTokenCache(); + resetOwnerCache(); + resetStripeCache(); +}); +afterEach(() => usePrivatePlans(undefined)); + +async function buyer(over: Record = {}) { + const t = setup({ ...LIVE, ...over }); + const a = await signedIn(t.env); + const s = fakeStripe(); + t.sql.db.prepare("UPDATE accounts SET stripe_customer_id = 'cus_ada0000001', stripe_mode = 'live' WHERE id = ?").run(a.account.id); + s.genclassCustomer("cus_ada0000001", a.account.id); + await createApp(t.env, a.cookie, "Shop"); + return { ...t, ...a, s }; +} +const sessionsOf = (s: ReturnType) => s.calls.filter((c) => c.method === "POST" && c.url.pathname === "/v1/checkout/sessions").map((c) => Object.fromEntries(c.form!)); + +describe("private prices (PLANS_PRIVATE)", () => { + it("plans.json has one price for Pro; the secret adds one for its countries, and both lookup keys give Pro", () => { + expect(PRO.price_usd_cents.monthly).toBe(5000); + usePrivatePlans(undefined); + expect(priceFor(PRO, "ZZ").stripe_lookup_keys.monthly).toBe("genclass_team_monthly"); + expect(planByLookupKey("genclass_team_zz_monthly")).toBeNull(); + usePrivatePlans(PRIVATE); + expect(priceFor(PRO, "ZZ")).toMatchObject({ price_usd_cents: { monthly: 2000 }, stripe_lookup_keys: { monthly: "genclass_team_zz_monthly" } }); + expect(priceFor(PRO, "zz").price_usd_cents.monthly).toBe(2000); + for (const c of ["US", "GB", "XX", "T1", null, undefined]) expect(priceFor(PRO, c).stripe_lookup_keys.monthly, String(c)).toBe("genclass_team_monthly"); + expect(planByLookupKey("genclass_team_monthly")?.id).toBe("team"); + expect(planByLookupKey("genclass_team_zz_monthly")?.id).toBe("team"); + // a price on either Pro product is GenClass's Pro + expect(planForPrice(price("genclass_team_zz_monthly", { product: "genclass_team_alt" }))?.id).toBe("team"); + }); + + it("a secret that does not parse, or a price without countries, cents or a genclass_ key, gives no private price", () => { + const one = (x: unknown) => JSON.stringify({ plans: { team: { country_prices: [x] } } }); + for (const raw of ["{", "[]", JSON.stringify({ plans: { nope: { country_prices: [] } } }), one({ countries: [], price_usd_cents: { monthly: 2000 }, stripe_lookup_keys: { monthly: "genclass_x" } }), one({ countries: ["ZZ"], price_usd_cents: { monthly: 0 }, stripe_lookup_keys: { monthly: "genclass_x" } }), one({ countries: ["ZZ"], price_usd_cents: { monthly: 2000 }, stripe_lookup_keys: { monthly: "other_x" } }), one({ countries: ["Zedland"], price_usd_cents: { monthly: 2000 }, stripe_lookup_keys: { monthly: "genclass_x" } })]) { + usePrivatePlans(raw); + expect(priceFor(PRO, "ZZ").stripe_lookup_keys.monthly, raw).toBe("genclass_team_monthly"); + } + }); + + it("the price text: the visitor's country's, else plans.json's, and never the other prices", () => { + usePrivatePlans(PRIVATE); + expect(priceText(PRO, "ZZ")).toBe("$20 / developer / month"); + expect(priceText(PRO, "US")).toBe("$50 / developer / month"); + expect(priceText(PRO, null)).toBe("$50 / developer / month"); + expect(priceText(PRO)).toBe("$50 / developer / month"); + expect(priceText(planById("free"), "ZZ")).toBe("$0"); + expect(priceText(planById("enterprise"), "ZZ")).toBe("By agreement"); + expect(problemsLock("https://genclass.dev/account/billing", "ZZ").price).toBe("$20 / developer / month"); + expect(problemsLock("https://genclass.dev/account/billing").price).toBe("$50 / developer / month"); + }); + + it("countryOf reads Cloudflare's request.cf.country, and nothing else", () => { + const req = (cf?: unknown) => { + const r = new Request("https://genclass.dev/"); + if (cf !== undefined) Object.defineProperty(r, "cf", { value: cf }); + return r; + }; + expect(countryOf(req({ country: "ZZ" }))).toBe("ZZ"); + expect(countryOf(req({ country: "us" }))).toBe("US"); + expect(countryOf(req({ country: "T1" }))).toBe("T1"); + for (const cf of [undefined, null, {}, { country: "" }, { country: "Zedland" }, { country: 1 }]) expect(countryOf(req(cf)), JSON.stringify(cf)).toBeNull(); + expect(countryOf(null)).toBeNull(); + // a header is not Cloudflare's word + expect(countryOf(new Request("https://genclass.dev/", { headers: { "cf-ipcountry": "ZZ" } }))).toBeNull(); + }); + + it("Checkout from a country with a private price sells it, from anywhere else plans.json's, and says which on the session", async () => { + for (const [country, priceId, key] of [["ZZ", "price_teamzz00001", "genclass_team_zz_monthly"], ["US", "price_team000001", "genclass_team_monthly"], [undefined, "price_team000001", "genclass_team_monthly"]] as const) { + resetStripeCache(); + const b = await buyer(); + const r = await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, ...(country ? { country } : {}) }); + expect(r.status, String(country)).toBe(200); + const [form] = sessionsOf(b.s); + expect(form, String(country)).toMatchObject({ "line_items[0][price]": priceId, "metadata[genclass_plan]": "team", "metadata[genclass_price]": key, allow_promotion_codes: "true" }); + const asked = b.s.calls.filter((c) => c.method === "GET" && c.url.pathname === "/v1/prices").map((c) => c.url.searchParams.get("lookup_keys[0]")); + expect(asked, String(country)).toEqual([key]); + } + // without the secret, that country gets plans.json's price too + resetStripeCache(); + const b = await buyer({ PLANS_PRIVATE: undefined }); + expect((await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, country: "ZZ" })).status).toBe(200); + expect(sessionsOf(b.s)[0]).toMatchObject({ "line_items[0][price]": "price_team000001", "metadata[genclass_price]": "genclass_team_monthly" }); + }); + + it("an open Checkout page for another price, or one made before the session named its price, is closed, not reused", async () => { + const b = await buyer(); + expect((await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, country: "ZZ" })).status).toBe(200); + const first = [...b.s.sessions.values()][0] as any; + expect(first.metadata.genclass_price).toBe("genclass_team_zz_monthly"); + const again = (await (await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, country: "ZZ" })).json()) as any; + expect(again.url).toBe(first.url); + const other = (await (await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, country: "DE" })).json()) as any; + expect(other.url).not.toBe(first.url); + expect(b.s.calls.some((c) => c.method === "POST" && c.url.pathname === `/v1/checkout/sessions/${first.id}/expire`)).toBe(true); + expect(sessionsOf(b.s).at(-1)).toMatchObject({ "line_items[0][price]": "price_team000001", "metadata[genclass_price]": "genclass_team_monthly" }); + const old = [...b.s.sessions.values()].at(-1) as any; + delete old.metadata.genclass_price; + const after = (await (await call(b.env, "POST", "/api/billing/checkout", { body: { plan: "team" }, cookie: b.cookie, fetch: b.s.fetch, country: "DE" })).json()) as any; + expect(after.url).not.toBe(old.url); + }); + + it("the billing page and the genclass command show the visitor's price, and nothing about other prices", async () => { + const b = await buyer(); + const zz = await (await call(b.env, "GET", "/account/billing", { cookie: b.cookie, country: "ZZ" })).text(); + expect(zz).toContain('

$20 / developer / month

'); + expect(zz).not.toContain("$50"); + const us = await (await call(b.env, "GET", "/account/billing", { cookie: b.cookie, country: "US" })).text(); + expect(us).toContain('

$50 / developer / month

'); + expect(us).not.toContain("$20"); + expect(us).not.toContain("Zedland"); + setNow(new Date(Date.parse(CLI_ACCOUNT_FROM) + 3_600_000)); + const t = setup(LIVE); + const me = await signedIn(t.env, "grace@example.com"); + const token = await cliToken(t.env, me.cookie); + for (const [country, want] of [["ZZ", "$20 / developer / month"], ["FR", "$50 / developer / month"]] as const) { + const res = await call(t.env, "GET", "/api/cli/account", { bearer: token, origin: null, country }); + const cli = (await res.json()) as any; + expect(res.status, JSON.stringify(cli)).toBe(200); + expect(cli.cli.price, country).toBe(want); + } + }); +}); diff --git a/telemetry-worker/test/project-plans.test.ts b/telemetry-worker/test/project-plans.test.ts index b16cac2c..7d0a4d13 100644 --- a/telemetry-worker/test/project-plans.test.ts +++ b/telemetry-worker/test/project-plans.test.ts @@ -66,11 +66,9 @@ async function withApps(names: string[], over: Record = {}) { } describe("plans.json version 5: Pro for the account, per developer, up to 3 apps", () => { - it("Pro is $50 a developer a month ($15 in Canada), sold by seats, for up to 3 apps; Free covers one app and 100 live fixes a month", () => { + it("Pro is $50 a developer a month, sold by seats, for up to 3 apps; Free covers one app and 100 live fixes a month", () => { const [free, team, enterprise] = PLANS; - expect(priceText(team!)).toBe("$50 / developer / month ($15 in Canada)"); - expect(priceText(team!, null)).toBe("$50 / developer / month"); - expect(priceText(team!, "CA")).toBe("$15 / developer / month"); + expect(priceText(team!)).toBe("$50 / developer / month"); expect(team!.per_project).toBeUndefined(); expect(team!.per_seat).toBe(true); expect(team!.apps_per_unit).toBeUndefined(); @@ -223,7 +221,7 @@ describe("checkout for the account (POST /api/billing/checkout { plan, seats?, p mode: "subscription", customer: "cus_ada0000001", client_reference_id: b.account.id, - "line_items[0][price]": "price_teamworld1", + "line_items[0][price]": "price_team000001", "line_items[0][quantity]": "1", "line_items[0][adjustable_quantity][enabled]": "true", "line_items[0][adjustable_quantity][minimum]": "1", diff --git a/telemetry-worker/test/stripe-setup-country.test.ts b/telemetry-worker/test/stripe-setup-private.test.ts similarity index 74% rename from telemetry-worker/test/stripe-setup-country.test.ts rename to telemetry-worker/test/stripe-setup-private.test.ts index 15e517f3..f0b9bdc2 100644 --- a/telemetry-worker/test/stripe-setup-country.test.ts +++ b/telemetry-worker/test/stripe-setup-private.test.ts @@ -1,18 +1,29 @@ import { fileURLToPath } from "node:url"; import { beforeAll, describe, expect, it } from "vitest"; -import { planForPrice } from "../src/plans.js"; +import { planForPrice, usePrivatePlans } from "../src/plans.js"; -// scripts/stripe-setup.mjs on the real billing/plans.json, whose Pro has a price by country (2026-11-16: US$50 a -// developer a month, US$15 in Canada). Each price is on its own product, both named GenClass Pro with metadata -// genclass_plan team (the Billing Portal's seat changes allow one monthly price a product): Canada's on the plan's -// main product genclass_team under the key it was sold under before, everyone else's on genclass_team_world, which -// plans.json names (stripe_product). A run against an account that already has them changes nothing. +// scripts/stripe-setup.mjs on the real billing/plans.json plus private prices (GENCLASS_PLANS_PRIVATE, the JSON of the +// Worker secret PLANS_PRIVATE; made-up values here). Each price is on its own product, all named after the plan with +// metadata genclass_plan (the Billing Portal's seat changes allow one monthly price a product): the plan's own price on +// the product the secret names for it, the country price on the plan's main product genclass_. A run against an +// account that already has them changes nothing. +const PRIVATE = { + plans: { + team: { + stripe_product: "genclass_team_alt", + country_prices: [{ countries: ["ZZ"], name: "Zedland", price_usd_cents: { monthly: 2000, yearly: null }, stripe_lookup_keys: { monthly: "genclass_team_zz_monthly", yearly: null } }], + }, + }, +}; // eslint-disable-next-line @typescript-eslint/no-explicit-any let setup: any; beforeAll(async () => { process.env.GENCLASS_PLANS_FILE = fileURLToPath(new URL("../../billing/plans.json", import.meta.url)); + process.env.GENCLASS_PLANS_PRIVATE = JSON.stringify(PRIVATE); setup = await import("../../scripts/stripe-setup.mjs"); + delete process.env.GENCLASS_PLANS_PRIVATE; + usePrivatePlans(JSON.stringify(PRIVATE)); }); type Obj = Record; @@ -97,26 +108,23 @@ async function run(a: ReturnType) { return a.calls.slice(from).filter((c) => c.method !== "GET"); } -describe("scripts/stripe-setup.mjs: prices by country (billing/plans.json country_prices)", () => { - it("Pro: Canada's US$15 on genclass_team, everyone else's US$50 on genclass_team_world, both seat-changeable in the portal", async () => { +describe("scripts/stripe-setup.mjs: private prices (GENCLASS_PLANS_PRIVATE)", () => { + it("the plan's own price on the product the secret names, the country price on the main product, both seat-changeable", async () => { const a = account(); await run(a); expect([...a.products.values()].map((x) => [x.id, x.name, x.metadata.genclass_plan, x.tax_code])).toEqual([ - ["genclass_team_world", "GenClass Pro", "team", "txcd_10103001"], + ["genclass_team_alt", "GenClass Pro", "team", "txcd_10103001"], ["genclass_team", "GenClass Pro", "team", "txcd_10103001"], ]); - const made = [...a.prices.values()].map((x) => [x.lookup_key, x.product, x.unit_amount, x.currency, x.recurring.interval, x.nickname]); - expect(made).toEqual([ - ["genclass_team_world_monthly", "genclass_team_world", 5000, "usd", "month", "Pro monthly"], - ["genclass_team_monthly", "genclass_team", 1500, "usd", "month", "Pro monthly (Canada)"], + expect([...a.prices.values()].map((x) => [x.lookup_key, x.product, x.unit_amount, x.currency, x.recurring.interval, x.nickname])).toEqual([ + ["genclass_team_monthly", "genclass_team_alt", 5000, "usd", "month", "Pro monthly"], + ["genclass_team_zz_monthly", "genclass_team", 2000, "usd", "month", "Pro monthly (Zedland)"], ]); - // the worker reads both as Pro for (const x of a.prices.values()) expect(planForPrice({ ...x, product: a.products.get(x.product) })?.id).toBe("team"); - // the portal: one product per price, each its own price only const ours = [...a.portal.values()].find((c) => c.metadata.genclass === "1")!; const form = new URLSearchParams(Object.entries(ours.form as Obj).flatMap(([k, v]) => (Array.isArray(v) ? v.map((x) => [k, x]) : [[k, v]])) as [string, string][]); const products = [...form.entries()].filter(([k]) => /^features\[subscription_update\]\[products\]\[\d+\]\[product\]$/.test(k)).map(([, v]) => v); - expect(products).toEqual(["genclass_team_world", "genclass_team"]); + expect(products).toEqual(["genclass_team_alt", "genclass_team"]); }); it("a second run changes no product or price", async () => { @@ -126,17 +134,16 @@ describe("scripts/stripe-setup.mjs: prices by country (billing/plans.json countr expect(again.filter((c) => c.url.pathname.startsWith("/v1/products") || c.url.pathname.startsWith("/v1/prices"))).toEqual([]); }); - it("a product the plans name is found by its id only: an earlier product of the plan is never taken for it", async () => { + it("a product the secret names is found by its id only: an earlier product of the plan is never taken for it", async () => { const a = account(); - // an earlier run's product of Pro with an id Stripe chose (found by the metadata search) holds Canada's price a.products.set("prod_earlier00001", { id: "prod_earlier00001", object: "product", active: true, name: "GenClass Pro", description: "Everything for up to 3 apps, per developer.", statement_descriptor: "GENCLASS", tax_code: "txcd_10103001", metadata: { genclass: "1", genclass_plan: "team" } }); - a.prices.set("price_earlier0001", { id: "price_earlier0001", object: "price", product: "prod_earlier00001", unit_amount: 1500, currency: "usd", recurring: { interval: "month" }, lookup_key: "genclass_team_monthly", active: true, metadata: { genclass: "1", genclass_plan: "team" } }); + a.prices.set("price_earlier0001", { id: "price_earlier0001", object: "price", product: "prod_earlier00001", unit_amount: 2000, currency: "usd", recurring: { interval: "month" }, lookup_key: "genclass_team_zz_monthly", active: true, metadata: { genclass: "1", genclass_plan: "team" } }); await run(a); expect(a.products.has("genclass_team")).toBe(false); - expect(a.products.get("genclass_team_world")?.metadata.genclass_plan).toBe("team"); + expect(a.products.get("genclass_team_alt")?.metadata.genclass_plan).toBe("team"); expect([...a.prices.values()].filter((x) => x.active).map((x) => [x.lookup_key, x.product])).toEqual([ - ["genclass_team_monthly", "prod_earlier00001"], - ["genclass_team_world_monthly", "genclass_team_world"], + ["genclass_team_zz_monthly", "prod_earlier00001"], + ["genclass_team_monthly", "genclass_team_alt"], ]); }); });