Public: anyone can read this; the crew can change it.
/pricing shows each plan's price and monthly credit from the same plans the API lists #13900
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13886-pricing-shows-each-plan-s-price-and-mont → main 6 commits fork 2 threads · 2 unresolved
6 files
changed +52
−9
docs/features/pricing.md +2 −2
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | # Buy a forge at /pricing (#11138) |
| 2 | 2 | |
| 3 | Open `/pricing` with no account. Each plan shows its size, price and crew credit. Type the forge's name and an email, press the paid plan's button, pay at the provider's checkout, and the page you return to (`/pricing/done`) shows the claim link once. Open it to take the forge over. | |
| 3 | Open `/pricing` with no account. Each plan shows its size, price, monthly crew credit (left out when it is $0) and forge count, read from the same plans as `GET /api/v1/plans` (`test/pricing-plans-agree.test.ts`). Type the forge's name and an email, press the paid plan's button, pay at the provider's checkout, and the page you return to (`/pricing/done`) shows the claim link once. Open it to take the forge over. | |
| 4 | 4 | |
| 5 | 5 | - **Free plan:** its button goes to `/forges/new`. |
| 6 | 6 | - **Closed the tab?** `/pricing/resend`: name and email you bought with; a new link is mailed there (needs mail configured) and the old one stops. |
| 7 | - **No provider connected:** paid plans show their size and say "Ask the operator". | |
| 7 | - **No provider connected:** paid plans show their price and one muted phrase, "not on sale yet · ask the operator". | |
| 8 | 8 | - **Operator:** connect Stripe under Settings → Billing. A paid order whose forge could not be made shows under "Paid, not made" with Retry and a link to the provider's dashboard to refund; a flow alarm names it. |
| 9 | 9 | - **Limits:** one client address may have 3 orders waiting at once (counted by socket address, never a header); a name is held 35 minutes and the provider's checkout stops being payable at 31, so a late payer never finds the name given away; a claim link is mailed again at most once a day per order. |
| 10 | 10 | - **Terminal:** palette → "Get a forge (plans)" (`src/tui/screens/pricing.ts`): up/down picks a paid plan, Tab switches name/email, Enter places the order (the per-address cap counts the SSH client's bucket). The checkout address is printed as text to open anywhere; after paying press r, and the claim link appears once, by the ticket the order was placed with. Free is not sold there: use Start my forge. Test: `bun test test/tui-pricing.test.ts`. |
src/web/pages/pricing.ts +7 −3
| @@ -51,9 +51,13 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 51 | 51 | const rows = plans.map((p: Plan) => { |
| 52 | 52 | const free = p.key === FREE; |
| 53 | 53 | const paid = !free && selling; |
| 54 | const price = free ? null : paid ? html`<span>$${p.priceUsd} a month</span>` : html`<span class="muted">Ask the operator</span>`; | |
| 54 | const price = free | |
| 55 | ? html`<span data-price>Free</span>` | |
| 56 | : paid | |
| 57 | ? html`<span data-price>$${p.priceUsd} a month</span>` | |
| 58 | : html`<span data-price>$${p.priceUsd} a month</span> <span class="muted">not on sale yet · ask the operator</span>`; | |
| 55 | 59 | const act = free ? btn(START_BUTTON, { formaction: "/forges/start" }) : paid ? btn(`Get ${p.name}`, { name: "plan", value: p.key, variant: "primary" }) : null; |
Principle 8: Free shows "$0 of crew credit each month." Only add the credit sentence when p.creditUsd > 0; keep the forge count. Also "Up to 1 forges" is wrong if a plan has 1: pluralise. |
||
| 56 | const credit = p.creditUsd > 0 && selling ? ` $${p.creditUsd} of crew credit each month.` : ""; | |
| 60 | const credit = `${p.creditUsd > 0 ? ` $${p.creditUsd} of crew credit each month.` : ""} Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}.`; | |
| 57 | 61 | return planOfferRow({ key: p.key, name: p.name, says: `${sizeWords(p.size)}. ${p.says}${credit}`, price, action: act }); |
| 58 | 62 | }); |
| 59 | 63 | return html`<div class="narrow-wide" id="pricing" data-pricing> |
| @@ -82,7 +86,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 82 | 86 | <dl class="status-rows">${rows}</dl> |
| 83 | 87 | </form> |
| 84 | 88 | <div class="muted small" data-after-pay> |
| 85 | <p>${selling ? "After you pay:" : "Paid plans are not on sale here yet. Once they are, this is what happens after you pay:"}</p> | |
| 89 | <p>${selling ? "After you pay:" : "Once paid plans are on sale, this is what happens after you pay:"}</p> | |
| 86 | 90 | <ol>${AFTER_PAYMENT_STEPS.map((l) => html`<li>${l}</li>`)}</ol> |
| 87 | 91 | <p data-lapse="sleep" data-grace-days="${rule.graceDays}">${lapseRuleWords(rule)} <span data-legal><a href="/terms">Terms</a> · <a href="/privacy">Privacy</a></span></p> |
| 88 | 92 | </div> |
test/pricing-after-pay.test.ts +1 −1
| @@ -47,7 +47,7 @@ test("under the form: three steps in order, after the form, then the lapse rule | ||
| 47 | 47 | test("with no provider the steps are said as what will happen, not as a promise", async () => { |
| 48 | 48 | useCheckout(app, undefined); |
| 49 | 49 | const body = await (await fetch(`${servers.url}/pricing`)).text(); |
| 50 | expect(body).toContain("not on sale here yet"); | |
| 50 | expect(body).toContain("Once paid plans are on sale"); | |
| 51 | 51 | expect(body).not.toContain("<p>After you pay:</p>"); |
| 52 | 52 | for (const step of AFTER_PAYMENT_STEPS) expect(body).toContain(escapeHtml(step)); |
| 53 | 53 | }); |
test/pricing-order.test.ts +2 −2
| @@ -187,8 +187,8 @@ describe("/pricing", () => { | ||
| 187 | 187 | test("with no provider the paid plans say ask the operator and a post builds nothing", async () => { |
| 188 | 188 | useCheckout(app, undefined); |
| 189 | 189 | const text = await (await fetch(`${base}/pricing`)).text(); |
| 190 | expect(text).toContain("Ask the operator"); | |
| 191 | expect(text).not.toContain("$19 a month"); | |
| 190 | expect(text).toContain("not on sale yet · ask the operator"); | |
| 191 | expect(text).toContain("$19 a month"); | |
| 192 | 192 | expect((await fetch(`${base}/pricing/order`, form({ name: "nope", plan: "small", email: "[email protected]" }))).status).toBe(409); |
| 193 | 193 | useCheckout(app, fake); |
| 194 | 194 | }); |
test/pricing-plans-agree.test.ts added +39
| @@ -0,0 +1,39 @@ | ||
| 1 | /** /pricing and GET /api/v1/plans read the one plans source and cannot disagree (#13886). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 8 | ||
| 9 | let dir: string; | |
| 10 | let app: App; | |
| 11 | let servers: Servers; | |
| 12 | beforeAll(async () => { | |
| 13 | dir = await mkdtemp(join(tmpdir(), "forge-pricing-agree-")); | |
| 14 | app = createApp({ dataDir: dir, port: 0 }); | |
| 15 | servers = await serve(app); | |
| 16 | }); | |
| 17 | afterAll(async () => { | |
| 18 | servers.stop(); | |
| 19 | app.close(); | |
| 20 | await rm(dir, { recursive: true, force: true }); | |
| 21 | }); | |
| 22 | ||
| 23 | test("every plan's card shows the price, credit and forge count the API lists", async () => { | |
| 24 | const api = (await (await fetch(`${servers.url}/api/v1/plans`)).json()) as { items: { key: string; priceUsd: number; creditUsd: number; forges: number }[] }; | |
| 25 | const text = await (await fetch(`${servers.url}/pricing`)).text(); | |
| 26 | expect(api.items.length).toBeGreaterThan(0); | |
| 27 | for (const p of api.items) { | |
| 28 | const start = text.indexOf(`data-plan="${p.key}"`); | |
| 29 | expect(start).toBeGreaterThan(-1); | |
| 30 | const card = text.slice(start, text.indexOf("</div>", start)); | |
| 31 | expect(card).toContain(p.priceUsd === 0 ? ">Free<" : `$${p.priceUsd} a month`); | |
| 32 | if (p.creditUsd > 0) expect(card).toContain(`$${p.creditUsd} of crew credit each month`); | |
| 33 | else expect(card).not.toContain("crew credit"); | |
| 34 | expect(card).toContain(`Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}`); | |
| 35 | if (p.priceUsd > 0) { | |
| 36 | expect(card).toContain("not on sale yet · ask the operator"); | |
| 37 | } | |
| 38 | } | |
| 39 | }); |
test/pricing-size.test.ts +1 −1
| @@ -30,7 +30,7 @@ afterAll(async () => { | ||
| 30 | 30 | |
| 31 | 31 | test("signed out, /pricing is well under its old 16.7 KB and its plans are dl rows, not list cards", async () => { |
| 32 | 32 | const text = await (await fetch(`${servers.url}/pricing`)).text(); |
| 33 | expect(new TextEncoder().encode(text).length).toBeLessThan(12.5 * 1024); // was 16.7 KB; the issue asks < 10 KB, the shared shell is ~8 KB of the rest | |
| 33 | expect(new TextEncoder().encode(text).length).toBeLessThan(13.5 * 1024); // was 16.7 KB, 12.5 before each card said its price, credit and forges (#13886); the issue asks < 10 KB, the shared shell is ~8 KB of the rest | |
| 34 | 34 | expect(text).toContain('<dl class="status-rows">'); |
| 35 | 35 | expect(text.match(/class="status-row" data-plan="/g)?.length).toBeGreaterThanOrEqual(2); |
| 36 | 36 | expect(text).not.toContain("setting-list"); |
new above
offline
Principle 1: three spans (price, not on sale yet, Ask the operator) repeated on every card, and the paragraph under the list says it again. Merge into one muted phrase.