console: a full-page success screen after every purchase (checkout, upgrade, packs) replaces the panel and the old 'Done' flash; '1 member, 10 seats paid for'; copy approved by Paul
Squashed from billing-success into main.
12 files changed,
+507
−186
docs/superpowers/reviews/CODEX-FINDINGS-billing-success-r1.md+20 −0docs/superpowers/reviews/CODEX-REVIEW-BRIEF-billing-success.md+28 −0internal/console/billingchange.go+44 −6internal/console/billingchange_test.go+106 −16internal/console/billingcheckout.go+3 −3internal/console/billingcheckout_test.go+7 −7internal/console/billingpage.go+73 −34internal/console/billingpage_copy.go+17 −6internal/console/billingpage_test.go+165 −72internal/console/templates/billing.html+0 −12internal/console/templates/billing_done.html+17 −0internal/console/templates/layout.html+27 −30
CI passed — run details
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-billing-success-r1.md b/docs/superpowers/reviews/CODEX-FINDINGS-billing-success-r1.md| new file mode 100644 |
| index 000000000..6432dd9f1 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-FINDINGS-billing-success-r1.md |
| @@ -0,0 +1,20 @@ |
| +# Astra findings: billing-success, round 1 of 3 |
| + |
| +gpt-6-astra via codex, high, at e0630a00. Unedited. |
| + |
| +Reviewed `origin/main...e0630a00410c446e31fd6c80171ad48bf552005a`, round 1. No P1 findings. |
| + |
| +1. **P2 — A missing subscription counts as a successful refresh.** |
| + [billingchange.go:554](/home/paulca/.cache/tmp/claude-1001/billing-success/internal/console/billingchange.go:554) discards the returned subscription and uses only `err == nil`. However, [refreshLocked:293](/home/paulca/.cache/tmp/claude-1001/billing-success/internal/console/billingsync.go:293) returns a nil subscription without an error when the provider answers `ErrNotFound` and recording the billing problem succeeds. |
| + |
| + **Failure scenario:** An upgrade or pack increase is applied, then the refresh returns `ErrNotFound`. The new limits remain unsynced, but the redirect carries the success marker and purchase-specific success flash. The billing problem prevents the success screen, leaving the normal page with old limits and a flash claiming the purchase is ready. |
| + |
| + **Fix:** Require `err == nil && sub != nil` before selecting the success reply. Add a regression test that returns `ErrNotFound` on the refresh after an applied change and expects the generic flash without a marker. |
| + |
| + **Fault family:** Purchase confirmation must require a completed subscription refresh. |
| + |
| +No P3 findings. Apply the P2 fix without reopening review. |
| + |
| +Validation: diff whitespace checks and formatting passed; static checks found CSRF fields in all nine billing POST forms. Targeted tests could not start because the read-only sandbox blocked Go’s build directory. No files changed. |
| + |
| +**READY AFTER FIXES** |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-billing-success.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-billing-success.md| new file mode 100644 |
| index 000000000..5d640a1b7 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-billing-success.md |
| @@ -0,0 +1,28 @@ |
| +# Review brief: branch billing-success, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `billing-success`, the commit that adds this brief (named in your prompt). |
| +Under review: the diff `origin/main...HEAD`: a full-page success screen on the console billing page after a purchase (?done=checkout|upgrade|packs, templates/billing_done.html), replacing the thank-you panel; charging changes (pack raise, upgrade) that the provider applied redirect with a marker; reductions, renewal changes, pending/declined/uncertain payments keep their flashes; "1 member" plural. Copy approved by Paul on 2026-10-29. |
| + |
| +## Fixed: do not re-argue |
| + |
| +- The design and the approved copy. |
| + |
| +## What to check |
| + |
| +1. The success screen renders only for an owner whose subscription is live and paid with nothing pending or ending; a member, a stale or hand-typed marker on any other account state, or an unknown marker value gets the normal billing page. The screen has no forms and acts on no billing state. |
| +2. Each redirect: the marker is set only after a definite applied charge (opApplied) of the matching kind, never after a pending, declined, uncertain, refused or reduction outcome; no open redirect (the target is the account's own billing page). |
| +3. The fallback flash and the screen never both show; a failed refresh after the change falls back to the generic flash. |
| +4. The billing page's existing invariants: currency/prices guard, action order, CSRF on every POST form, member/owner differences, billing lints. |
| +5. Anchors (#packs-title, #upgrade) exist on the billing page when their buttons show; Upgrade hidden on the top plan, Add packs when there are no packs. |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for another round. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3 with file:line, failure scenario and fix. End with exactly one verdict: **READY**, **READY AFTER FIXES**, or **NOT READY**. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of your own. Do not run the full test suites. |
diff --git a/internal/console/billingchange.go b/internal/console/billingchange.go| index 9adf009a4..0ec40836f 100644 |
| --- a/internal/console/billingchange.go |
| +++ b/internal/console/billingchange.go |
| @@ -67,9 +67,12 @@ type changeQuote struct { |
| } |
| // changeReply is a change's answer: a flash (kind and text), or a quote for |
| -// the confirm page. |
| +// the confirm page. Done is the success marker (donePacks, doneUpgrade) the |
| +// billing page is reached with after a raise or an upgrade the provider |
| +// applied, "" for none; the flash is then the screen's fallback. |
| type changeReply struct { |
| Kind, Text string |
| + Done string |
| Quote *changeQuote |
| } |
| @@ -178,6 +181,9 @@ func (s *Server) handleBillingChange(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| s.setFlash(w, reply.Kind, reply.Text) |
| + if reply.Done != "" { |
| + back += "?done=" + reply.Done |
| + } |
| http.Redirect(w, r, back, http.StatusSeeOther) |
| } |
| @@ -385,7 +391,7 @@ func (s *Server) packChangeLocked(h billingHold, ctx context.Context, acct *Acco |
| return changeReply{}, err |
| } |
| if chargeTo == 0 { |
| - return s.settleChangeLocked(h, ctx, acct, out, now), nil |
| + return s.settleSuccessLocked(h, ctx, acct, out, now, packsDone()), nil |
| } |
| // The charge is computed only from a definite restore applied in the |
| // same period, on the item its answer names. |
| @@ -412,7 +418,7 @@ func (s *Server) packChangeLocked(h billingHold, ctx context.Context, acct *Acco |
| if err != nil { |
| return changeReply{}, err |
| } |
| - return s.settleChangeLocked(h, ctx, acct, out, now), nil |
| + return s.settleSuccessLocked(h, ctx, acct, out, now, packsDone()), nil |
| } |
| // upgradeLocked is a plan upgrade (Call 4) on the fresh allowance read: one |
| @@ -471,7 +477,8 @@ func (s *Server) upgradeLocked(h billingHold, ctx context.Context, acct *Account |
| if err != nil { |
| return changeReply{}, err |
| } |
| - return s.settleChangeLocked(h, ctx, acct, out, now), nil |
| + return s.settleSuccessLocked(h, ctx, acct, out, now, changeReply{Kind: "ok", Done: doneUpgrade, |
| + Text: fmt.Sprintf(billingCopy["done.upgrade.flash"], planLabel(ask.Plan))}), nil |
| } |
| // configuredPrice is a yearly price from the configured book, known only when |
| @@ -524,11 +531,42 @@ func (s *Server) sendChangeLocked(h billingHold, ctx context.Context, acct *Acco |
| // the page shows what the provider holds, and answers the outcome's flash. A |
| // failed refresh only defers that to the next read: the outcome is recorded. |
| func (s *Server) settleChangeLocked(h billingHold, ctx context.Context, acct *Account, out opOutcome, now time.Time) changeReply { |
| - if _, _, err := s.refreshLocked(h, ctx, acct, now); err != nil { |
| + reply, _ := s.settleRefreshLocked(h, ctx, acct, out, now) |
| + return reply |
| +} |
| + |
| +// settleSuccessLocked is settleChangeLocked for a raise or an upgrade: |
| +// applied, with the refresh read, it answers done, the success screen's |
| +// marker and fallback flash. Anything else (pending, declined, uncertain) |
| +// keeps its flash. So does an applied change whose refresh failed or found |
| +// no subscription: the page would show the plan as it was before, and the |
| +// screen would name it. |
| +func (s *Server) settleSuccessLocked(h billingHold, ctx context.Context, acct *Account, out opOutcome, now time.Time, done changeReply) changeReply { |
| + reply, refreshed := s.settleRefreshLocked(h, ctx, acct, out, now) |
| + if out.State == opApplied && refreshed { |
| + return done |
| + } |
| + return reply |
| +} |
| + |
| +// settleRefreshLocked is the refresh and outcome flash both settle |
| +// helpers share, and whether the refresh read the subscription: no error |
| +// and a subscription read. A provider with no subscription is no error |
| +// (refreshLocked records it as a problem and returns no read), and it |
| +// confirms nothing. |
| +func (s *Server) settleRefreshLocked(h billingHold, ctx context.Context, acct *Account, out opOutcome, now time.Time) (changeReply, bool) { |
| + _, sub, err := s.refreshLocked(h, ctx, acct, now) |
| + if err != nil { |
| log.Printf("console: billing change %s: refresh after the change: %v", acct.Sqid, err) |
| } |
| kind, key := outcomeCopy(out) |
| - return changeFlash(kind, key) |
| + return changeFlash(kind, key), err == nil && sub != nil |
| +} |
| + |
| +// packsDone is the answer to a pack raise the provider applied: the packs |
| +// success screen, with its flash as the fallback. |
| +func packsDone() changeReply { |
| + return changeReply{Kind: "ok", Text: billingCopy["done.packs.flash"], Done: donePacks} |
| } |
| // ---- renewal -------------------------------------------------------------- |
diff --git a/internal/console/billingchange_test.go b/internal/console/billingchange_test.go| index 6639fdb8d..7c45270a8 100644 |
| --- a/internal/console/billingchange_test.go |
| +++ b/internal/console/billingchange_test.go |
| @@ -64,6 +64,15 @@ func (o *opsFixture) wantFlash(t *testing.T, r billingReply, kind, text string) |
| } |
| } |
| +// wantDone is a redirect to the billing page's success screen for marker |
| +// (packs or upgrade), with the plain flash text as its fallback. |
| +func (o *opsFixture) wantDone(t *testing.T, r billingReply, marker, text string) { |
| + t.Helper() |
| + if r.Status != http.StatusSeeOther || r.Loc != o.billingBase()+"?done="+marker || r.Flash != "ok" || r.FlashMsg != text { |
| + t.Fatalf("reply = %d %q flash %s:%q, want ?done=%s and ok:%q", r.Status, r.Loc, r.Flash, r.FlashMsg, marker, text) |
| + } |
| +} |
| + |
| // wantQuote is the confirm page for a charge, showing line. |
| func wantQuote(t *testing.T, r billingReply, line string) { |
| t.Helper() |
| @@ -204,7 +213,7 @@ func TestPackRaiseCharges(t *testing.T) { |
| o.stepUp(t) |
| o.reset() |
| r = o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1") |
| - o.wantFlash(t, r, "ok", billingCopy["change.done"]) |
| + o.wantDone(t, r, "packs", billingCopy["done.packs.flash"]) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 2, "Send": 1}) |
| op := o.lastOp(t) |
| if op.Kind != opPack || op.State != opApplied || op.StartQuantity == nil || *op.StartQuantity != 1 || |
| @@ -245,7 +254,7 @@ func TestPackReduceAndBuyBack(t *testing.T) { |
| // step-up, one write. |
| o.reset() |
| r = o.change(t, "pack", "apps", "quantity", "3") |
| - o.wantFlash(t, r, "ok", billingCopy["change.done"]) |
| + o.wantDone(t, r, "packs", billingCopy["done.packs.flash"]) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 2, "Send": 1}) |
| op = o.lastOp(t) |
| if body := changeBodyOf(t, op.Prepared); op.Kind != opRestore || op.State != opApplied || body.Proration != billing.ProrateNone || |
| @@ -287,7 +296,7 @@ func TestDeletedPackRestoreThenCharge(t *testing.T) { |
| // answer names up to 4. S + (1) + (1) + S. |
| o.stepUp(t) |
| o.reset() |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "4", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "4", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 2, "Send": 2}) |
| all := o.ops(t) |
| if len(all) != 3 { |
| @@ -396,7 +405,7 @@ func TestRestoreIgnoresConsoleClock(t *testing.T) { |
| t.Fatal(err) |
| } |
| o.reset() |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "2"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "2"), "packs", billingCopy["done.packs.flash"]) |
| if op := o.lastOp(t); op.Kind != opRestore || op.State != opApplied { |
| t.Fatalf("restore = %+v", op) |
| } |
| @@ -485,7 +494,7 @@ func TestRetryAfterDeclineIsRefusedUntilSettled(t *testing.T) { |
| t.Fatal(err) |
| } |
| o.reset() |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "2", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "2", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 3, "Send": 1}) |
| if got := o.op(t, first.ID); got.State != opAbandoned { |
| t.Fatalf("first op = %+v, want abandoned", got) |
| @@ -501,14 +510,14 @@ func TestRetryAfterDeclineIsRefusedUntilSettled(t *testing.T) { |
| t.Fatalf("declined op = %+v", op) |
| } |
| o.reset() |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 2, "Send": 1}) |
| } |
| func TestChangeTwiceChargesOnce(t *testing.T) { |
| o := newChangeFixture(t, map[string]int64{"apps": 1}) |
| o.stepUp(t) |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| // The double submit: the fresh read shows 3, so there is no step. |
| o.reset() |
| o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "err", billingCopy["change.none"]) |
| @@ -535,7 +544,7 @@ func TestChangeComputesFromTheFreshRead(t *testing.T) { |
| o.stepUp(t) |
| // The provider moved the quantity since the console last read it. |
| o.setQuantity("sub_1", appsPrice(), 3) |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "4", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "4", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| op := o.lastOp(t) |
| if body := changeBodyOf(t, op.Prepared); op.Kind != opPack || *op.StartQuantity != 3 || body.Proration != billing.ProrateNow || body.Items[0].Quantity != 4 { |
| t.Fatalf("charge = %+v body %+v", op, body) |
| @@ -564,7 +573,7 @@ func TestChangeAfterDelayedRenewal(t *testing.T) { |
| wantQuote(t, o.change(t, "pack", "apps", "quantity", "3"), quoteLine("usd", prorateEstimate(1200, 2, o.providerClock(), periodEnd.AddDate(1, 0, 0)))) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 1}) |
| o.reset() |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 2, "Send": 1}) |
| op := o.lastOp(t) |
| if op.Kind != opPack || *op.StartQuantity != 1 || !op.PeriodEnd.Equal(periodEnd.AddDate(1, 0, 0)) || changeBodyOf(t, op.Prepared).Proration != billing.ProrateNow { |
| @@ -593,7 +602,7 @@ func TestChangeAfterReplacementSubscription(t *testing.T) { |
| o.stepUp(t) |
| o.reset() |
| // The old subscription's paid 3 does not carry: a charge on sub_2. |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 2, "Send": 1}) |
| op := o.lastOp(t) |
| if op.Subscription != "sub_2" || op.Kind != opPack || *op.StartQuantity != 1 || changeBodyOf(t, op.Prepared).Subscription != "sub_2" { |
| @@ -609,7 +618,7 @@ func TestChangeUnresolvedFinishedOnNextRequest(t *testing.T) { |
| o.unresolved(t, op) |
| o.setQuantity("sub_1", appsPrice(), 2) |
| o.reset() |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| // F (one read, no resend), then S + (1) + S. |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 3, "Send": 1}) |
| if got := o.op(t, "op_prior"); got.State != opApplied { |
| @@ -625,7 +634,7 @@ func TestChangeUnresolvedFinishedOnNextRequest(t *testing.T) { |
| op := o.packOp(t, "op_prior", "sub_1", "apps", 2, billing.ProrateNow, opPack) |
| o.unresolved(t, op) |
| o.reset() |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 3, "Send": 2}) |
| sent := o.sent() |
| if sent[0].Key != op.Prepared.Key || string(sent[0].Body) != string(op.Prepared.Body) { |
| @@ -659,7 +668,7 @@ func TestPlanUpgrade(t *testing.T) { |
| o.stepUp(t) |
| o.reset() |
| - o.wantFlash(t, o.change(t, "plan", "community", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "plan", "community", "confirmed", "1"), "upgrade", fmt.Sprintf(billingCopy["done.upgrade.flash"], "Community")) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 2, "Send": 1}) |
| op := o.lastOp(t) |
| body := changeBodyOf(t, op.Prepared) |
| @@ -696,7 +705,7 @@ func TestUpgradeRefusedWhenPackNotOffered(t *testing.T) { |
| t.Fatal("a refused upgrade wrote") |
| } |
| // A plan that offers it is fine. |
| - o.wantFlash(t, o.change(t, "plan", "community", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "plan", "community", "confirmed", "1"), "upgrade", fmt.Sprintf(billingCopy["done.upgrade.flash"], "Community")) |
| // A pack reduced to 0 is still paid for until renewal, so it is still |
| // held: the upgrade is refused with nothing sent. |
| @@ -767,7 +776,7 @@ func TestChangeUsesTheSubscriptionsBook(t *testing.T) { |
| // The earlier book's amounts are not known here: no estimate. |
| wantQuote(t, o.change(t, "pack", "apps", "quantity", "2"), billingCopy["change.no_estimate"]) |
| - o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "2", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "2", "confirmed", "1"), "packs", billingCopy["done.packs.flash"]) |
| if op := o.lastOp(t); op.Target.Quantities[testPriceID("example-v0/pack/apps/usd")] != 2 { |
| t.Fatalf("pack change = %+v", op) |
| } |
| @@ -776,7 +785,7 @@ func TestChangeUsesTheSubscriptionsBook(t *testing.T) { |
| o.wantFlash(t, o.change(t, "pack", "email", "quantity", "1", "confirmed", "1"), "err", billingCopy["change.book"]) |
| wantCounts(t, o.counts(), map[string]int{"Subscription": 1}) |
| // An upgrade is priced from the subscription's book. |
| - o.wantFlash(t, o.change(t, "plan", "community", "confirmed", "1"), "ok", billingCopy["change.done"]) |
| + o.wantDone(t, o.change(t, "plan", "community", "confirmed", "1"), "upgrade", fmt.Sprintf(billingCopy["done.upgrade.flash"], "Community")) |
| if body := changeBodyOf(t, o.lastOp(t).Prepared); body.Items[0].PriceID != testPriceID("example-v0/community/usd") { |
| t.Fatalf("upgrade = %+v", body) |
| } |
| @@ -1013,3 +1022,84 @@ func TestChangeAndRenewalReturnUnderTimeout(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// ---- the success screen after a change --------------------------------------- |
| + |
| +// TestChangeSuccessScreen: a pack raise or an upgrade the provider applied |
| +// redirects to the success screen for it (?done=packs, ?done=upgrade), which |
| +// replaces the billing page; a reduction and a renewal change keep their |
| +// flashes on the billing page, with no marker. |
| +func TestChangeSuccessScreen(t *testing.T) { |
| + o := newChangeFixture(t, map[string]int64{"apps": 1}) |
| + o.stepUp(t) |
| + follow := func(r billingReply) string { |
| + t.Helper() |
| + page := o.request(t, http.MethodGet, r.Loc, nil) |
| + if page.Status != http.StatusOK { |
| + t.Fatalf("GET %s = %d", r.Loc, page.Status) |
| + } |
| + return page.Body |
| + } |
| + |
| + // A charged pack raise. |
| + r := o.change(t, "pack", "apps", "quantity", "3", "confirmed", "1") |
| + o.wantDone(t, r, "packs", billingCopy["done.packs.flash"]) |
| + if screen := successScreen(follow(r)); !strings.Contains(screen, esc(billingCopy["done.packs.title"])) { |
| + t.Fatalf("after a pack raise: no packs screen:\n%s", screen) |
| + } |
| + |
| + // A reduction: change.done on the billing page. |
| + r = o.change(t, "pack", "apps", "quantity", "1") |
| + o.wantFlash(t, r, "ok", billingCopy["change.done"]) |
| + if body := follow(r); successScreen(body) != "" { |
| + t.Fatal("a reduction showed the success screen") |
| + } |
| + |
| + // Buying back what is already paid for is a raise too: the packs screen. |
| + o.wantDone(t, o.change(t, "pack", "apps", "quantity", "2"), "packs", billingCopy["done.packs.flash"]) |
| + |
| + // An upgrade: the upgrade screen, naming the new plan. |
| + r = o.change(t, "plan", "community", "confirmed", "1") |
| + o.wantDone(t, r, "upgrade", fmt.Sprintf(billingCopy["done.upgrade.flash"], "Community")) |
| + if screen := successScreen(follow(r)); !strings.Contains(screen, esc(fmt.Sprintf(billingCopy["done.upgrade.title"], "Community"))) { |
| + t.Fatalf("after an upgrade: no upgrade screen:\n%s", screen) |
| + } |
| + |
| + // Renewal: its own flashes, no marker. |
| + o.wantFlash(t, o.renewal(t, "stop"), "ok", fmt.Sprintf(billingCopy["renewal.stopped"], billingDate(periodEnd))) |
| + o.wantFlash(t, o.renewal(t, "resume"), "ok", billingCopy["renewal.resumed"]) |
| +} |
| + |
| +// TestChangeSuccessNeedsTheSubscription: an upgrade or a pack raise the |
| +// provider applied, whose refresh then finds no subscription (a missing |
| +// subscription is recorded as a problem, not an error), gets the generic |
| +// flash and no success marker: nothing confirmed the purchase's limits. |
| +func TestChangeSuccessNeedsTheSubscription(t *testing.T) { |
| + for _, c := range []struct { |
| + name string |
| + kv []string |
| + }{ |
| + {"packs", []string{"pack", "apps", "quantity", "3", "confirmed", "1"}}, |
| + {"upgrade", []string{"plan", "community", "confirmed", "1"}}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + o := newChangeFixture(t, map[string]int64{"apps": 1}) |
| + o.stepUp(t) |
| + reads := 0 |
| + o.fake.BeforeSubscription = func(string) error { |
| + // The change's own read succeeds; the refresh after the |
| + // send finds nothing. |
| + if reads++; reads > 1 { |
| + return billing.ErrNotFound |
| + } |
| + return nil |
| + } |
| + r := o.change(t, c.kv...) |
| + o.fake.BeforeSubscription = nil |
| + if op := o.lastOp(t); op.State != opApplied { |
| + t.Fatalf("op = %+v, want applied", op) |
| + } |
| + o.wantFlash(t, r, "ok", billingCopy["change.done"]) |
| + }) |
| + } |
| +} |
diff --git a/internal/console/billingcheckout.go b/internal/console/billingcheckout.go| index 6b6fa603a..c6c3ab6e1 100644 |
| --- a/internal/console/billingcheckout.go |
| +++ b/internal/console/billingcheckout.go |
| @@ -1078,9 +1078,9 @@ func (s *Server) continueLocked(h billingHold, ctx context.Context, acct *Accoun |
| // handleBillingDone is GET /a/{sqid}/billing/done?session=: the owner back |
| // from the payment page. The intent the session names is marked returned and |
| // observed (a completed session syncs its subscription), then the billing |
| -// page. A completed, paid return carries the thank-you marker (?welcome=1, |
| +// page. A completed, paid return carries the success marker (?done=checkout, |
| // which the page checks against the account's state again) and a flash |
| -// naming the plan, which the panel replaces. |
| +// naming the plan, which the success screen replaces. |
| func (s *Server) handleBillingDone(w http.ResponseWriter, r *http.Request) { |
| if s.billing == nil { |
| http.NotFound(w, r) |
| @@ -1107,7 +1107,7 @@ func (s *Server) handleBillingDone(w http.ResponseWriter, r *http.Request) { |
| s.setFlash(w, kind, text) |
| } |
| if kind == "ok" { |
| - back += "?welcome=1" |
| + back += "?done=" + doneCheckout |
| } |
| http.Redirect(w, r, back, http.StatusSeeOther) |
| } |
diff --git a/internal/console/billingcheckout_test.go b/internal/console/billingcheckout_test.go| index f2ec185e6..b84e6fee8 100644 |
| --- a/internal/console/billingcheckout_test.go |
| +++ b/internal/console/billingcheckout_test.go |
| @@ -895,15 +895,15 @@ func TestCheckoutDoneSyncs(t *testing.T) { |
| } |
| wantCounts(t, o.counts(), map[string]int{}) |
| r := o.request(t, http.MethodGet, o.billingBase()+"/done?session="+ci.Session, nil) |
| - // A completed, paid return: the billing page with the thank-you marker, |
| + // A completed, paid return: the billing page with the success marker, |
| // and the plain flash as its fallback. |
| - if r.Status != http.StatusSeeOther || r.Loc != o.billingBase()+"?welcome=1" || r.Flash != "ok" || r.FlashMsg != fmt.Sprintf(billingCopy["checkout.done"], "Personal") { |
| + if r.Status != http.StatusSeeOther || r.Loc != o.billingBase()+"?done=checkout" || r.Flash != "ok" || r.FlashMsg != fmt.Sprintf(billingCopy["checkout.done"], "Personal") { |
| t.Fatalf("done = %+v", r) |
| } |
| - // Following it shows the panel in the flash's place. |
| + // Following it shows the success screen in the flash's place. |
| page := o.request(t, http.MethodGet, r.Loc, nil) |
| - if page.Status != http.StatusOK || welcomePanel(page.Body) == "" { |
| - t.Fatalf("the page after the return has no thank-you panel:\n%s", page.Body) |
| + if page.Status != http.StatusOK || successScreen(page.Body) == "" { |
| + t.Fatalf("the page after the return has no success screen:\n%s", page.Body) |
| } |
| // 1 session read + S. |
| wantCounts(t, o.counts(), map[string]int{"Checkout": 1, "Subscription": 1}) |
| @@ -1309,7 +1309,7 @@ func TestCheckoutDoneResyncsAfterFailedSync(t *testing.T) { |
| } |
| o.reset() |
| r := o.request(t, http.MethodGet, o.billingBase()+"/done?session="+ci.Session, nil) |
| - if r.Loc != o.billingBase()+"?welcome=1" || r.Flash != "ok" || r.FlashMsg != fmt.Sprintf(billingCopy["checkout.done"], "Personal") { |
| + if r.Loc != o.billingBase()+"?done=checkout" || r.Flash != "ok" || r.FlashMsg != fmt.Sprintf(billingCopy["checkout.done"], "Personal") { |
| t.Fatalf("done = %+v", r) |
| } |
| wantCounts(t, o.counts(), map[string]int{"Checkout": 1, "Subscription": 1}) |
| @@ -1341,7 +1341,7 @@ func TestCheckoutDonePendingThenPaid(t *testing.T) { |
| o.fake.Unlock() |
| o.reset() |
| r := o.request(t, http.MethodGet, o.billingBase()+"/done?session="+ci.Session, nil) |
| - if r.Loc != o.billingBase()+"?welcome=1" || r.Flash != "ok" || r.FlashMsg != fmt.Sprintf(billingCopy["checkout.done"], "Personal") { |
| + if r.Loc != o.billingBase()+"?done=checkout" || r.Flash != "ok" || r.FlashMsg != fmt.Sprintf(billingCopy["checkout.done"], "Personal") { |
| t.Fatalf("done = %+v", r) |
| } |
| wantCounts(t, o.counts(), map[string]int{"Checkout": 1, "Subscription": 1}) |
diff --git a/internal/console/billingpage.go b/internal/console/billingpage.go| index 0dfba71c2..b035c7df6 100644 |
| --- a/internal/console/billingpage.go |
| +++ b/internal/console/billingpage.go |
| @@ -201,10 +201,11 @@ type billingView struct { |
| Plan string |
| Facts []string |
| Includes []string |
| + limits *plans.Limits // the limits Includes lists, nil for none |
| Offers billingOffers |
| - // Welcome is the thank-you panel after a completed purchase, nil for |
| - // none (billingWelcomeFor). |
| - Welcome *billingWelcome |
| + // Success is the screen that replaces the page after a completed |
| + // purchase, nil for none (billingSuccessFor). |
| + Success *billingSuccess |
| Buy *billingBuyView |
| Change *billingChangeView |
| StartOver []billingField // the open intent's own request, for Start over |
| @@ -218,13 +219,21 @@ type billingOffers struct { |
| type billingField struct{ Name, Value string } |
| -// billingWelcome is the thank-you panel: the line naming the account and |
| -// its plan, the room the plan gives ("" when the page names none), and |
| -// whether the page has packs to add and a plan to upgrade to, so each link |
| -// lands on a section that is there. |
| -type billingWelcome struct { |
| - Lede, Room string |
| - Packs, Upgrade bool |
| +// The success markers a completed purchase redirects to the billing page |
| +// with (?done=): a Checkout, an upgrade, a pack raise. |
| +const ( |
| + doneCheckout = "checkout" |
| + doneUpgrade = "upgrade" |
| + donePacks = "packs" |
| +) |
| + |
| +// billingSuccess is the success screen: the heading and line for the |
| +// purchase the marker names, the room the plan gives ("" when the screen |
| +// names none), and its links. PacksURL and UpgradeURL go to the billing |
| +// page's own sections, "" when the page has none to land on. |
| +type billingSuccess struct { |
| + Title, Lede, Room string |
| + PacksURL, UpgradeURL, AppsURL string |
| } |
| // billingBuyView is the first purchase: the paid plans, a quantity per |
| @@ -304,7 +313,9 @@ func (s *Server) billingPageInputFor(acct *Account, role string, now time.Time) |
| // handleBilling is GET /a/{sqid}/billing. Billing off answers the unrouted |
| // 404; the account gate answers a non-member with the same 404. Members |
| -// see the facts and notices, owners also the forms. |
| +// see the facts and notices, owners also the forms. An owner back from a |
| +// completed purchase (?done=) gets the success screen in its place |
| +// (billingSuccessFor). |
| func (s *Server) handleBilling(w http.ResponseWriter, r *http.Request) { |
| if s.billing == nil { |
| http.NotFound(w, r) |
| @@ -332,13 +343,12 @@ func (s *Server) handleBilling(w http.ResponseWriter, r *http.Request) { |
| } |
| st := decideBillingPage(in) |
| view := s.billingViewFor(r, in, st, members) |
| + if view.Success = billingSuccessFor(r.URL.Query().Get("done"), acct, in, st, view); view.Success != nil { |
| + s.renderBillingSuccess(w, r, view) |
| + return |
| + } |
| view.Eyebrow = fmt.Sprintf(billingCopy["page.eyebrow"], acct.Name) |
| p := s.accountPage(w, r, addr, raw, acct, role) |
| - if view.Welcome != nil { |
| - // The panel says what the return's plain flash said, and more. |
| - view.Welcome.Lede = fmt.Sprintf(billingCopy["welcome.lede"], acct.Name, view.Plan) |
| - p.Flash = "" |
| - } |
| p.Title = billingCopy["page.title"] |
| p.ActiveNav = "billing" |
| p.Billing = view |
| @@ -392,7 +402,6 @@ func (s *Server) billingViewFor(r *http.Request, in billingPageInput, st billing |
| plan, packs, sponsored, seats = in.Row.Plan, in.Row.Packs, in.Row.Sponsored, in.Row.Seats |
| } |
| v.Plan = planLabel(plan) |
| - var limits *plans.Limits |
| if p, ok := cat.Plans[plan]; ok { |
| held := map[string]int{} |
| for _, name := range heldPacks(packs) { |
| @@ -403,7 +412,7 @@ func (s *Server) billingViewFor(r *http.Request, in billingPageInput, st billing |
| limitedAt, _ := teamMembers(cat, plan, seats, func() (int, error) { return members, nil }) |
| if l, err := cat.Effective(plan, held, sponsored, limitedAt); err == nil { |
| v.Includes = planIncludes(l, p.MaxMembers) |
| - limits = &l |
| + v.limits = &l |
| } |
| } |
| // A line per pack held: "4 Apps packs". |
| @@ -415,7 +424,11 @@ func (s *Server) billingViewFor(r *http.Request, in billingPageInput, st billing |
| v.Facts = append(v.Facts, fmt.Sprintf(billingCopy[key], packs[name], planLabel(name))) |
| } |
| if p, ok := cat.Plans[plan]; ok && p.Team != nil && b != nil { |
| - v.Facts = append(v.Facts, fmt.Sprintf(billingCopy["team.members"], members, b.PaidSeats)) |
| + key := "team.members_many" |
| + if members == 1 { |
| + key = "team.members_one" |
| + } |
| + v.Facts = append(v.Facts, fmt.Sprintf(billingCopy[key], members, b.PaidSeats)) |
| } |
| if b != nil && b.Currency != "" { |
| v.Facts = append(v.Facts, fmt.Sprintf(billingCopy["fact.currency"], strings.ToUpper(b.Currency))) |
| @@ -435,9 +448,6 @@ func (s *Server) billingViewFor(r *http.Request, in billingPageInput, st billing |
| if v.Offers.Change && b != nil { |
| v.Change = billingChange(cat, book, plan, packs, b.Currency) |
| } |
| - if r.URL.Query().Get("welcome") == "1" { |
| - v.Welcome = billingWelcomeFor(in, st, v, limits) |
| - } |
| if v.Offers.StartOver && in.Intent != nil { |
| ci := in.Intent |
| v.StartOver = []billingField{{"plan", ci.Plan}, {"currency", ci.Currency}} |
| @@ -449,29 +459,58 @@ func (s *Server) billingViewFor(r *http.Request, in billingPageInput, st billing |
| return v |
| } |
| -// billingWelcomeFor is the thank-you panel for a page load carrying the |
| -// completed return's marker (?welcome=1), or nil. The marker proves |
| -// nothing on its own, so a stale or hand-typed one shows nothing extra: |
| -// the panel needs an owner whose account, on this load, holds a live, |
| -// paid subscription the billing doors manage with nothing for the page to |
| -// say about it (no notice, so not settling, collecting or ending), which |
| -// is when the page offers the change forms the panel's links jump to. |
| -func billingWelcomeFor(in billingPageInput, st billingPageState, v *billingView, limits *plans.Limits) *billingWelcome { |
| +// billingSuccessFor is the success screen for a page load carrying a |
| +// completed purchase's marker (?done=checkout, upgrade or packs), or nil. |
| +// The marker proves nothing on its own, so a stale, unknown or hand-typed |
| +// one shows the billing page: the screen needs an owner whose account, on |
| +// this load, holds a live, paid subscription the billing doors manage with |
| +// nothing for the page to say about it (no notice, so not settling, |
| +// collecting, waiting for payment or ending), which is when the page |
| +// offers the change forms the screen's links go back to. |
| +func billingSuccessFor(marker string, acct *Account, in billingPageInput, st billingPageState, v *billingView) *billingSuccess { |
| + if marker != doneCheckout && marker != doneUpgrade && marker != donePacks { |
| + return nil |
| + } |
| b := in.Billing |
| if !in.Owner || st.Notice != "" || v.Change == nil || b == nil || !b.Live || b.State != billing.StatePaid || |
| in.Row == nil || in.Row.Source != PlanSourceBilling { |
| return nil |
| } |
| - w := &billingWelcome{Packs: len(v.Change.Packs) > 0, Upgrade: len(v.Change.Upgrades) > 0} |
| - if l := limits; l != nil && l.RunningThings > 0 && l.DiskBytes > 0 { |
| + page := billingPagePath(acct.Sqid) |
| + ok := &billingSuccess{AppsURL: "/a/" + url.PathEscape(acct.Sqid) + "/"} |
| + switch marker { |
| + case doneCheckout: |
| + ok.Title, ok.Lede = billingCopy["welcome.title"], fmt.Sprintf(billingCopy["welcome.lede"], acct.Name, v.Plan) |
| + case doneUpgrade: |
| + ok.Title, ok.Lede = fmt.Sprintf(billingCopy["done.upgrade.title"], v.Plan), fmt.Sprintf(billingCopy["done.upgrade.lede"], acct.Name) |
| + case donePacks: |
| + ok.Title, ok.Lede = billingCopy["done.packs.title"], fmt.Sprintf(billingCopy["done.packs.lede"], acct.Name) |
| + } |
| + if len(v.Change.Packs) > 0 { |
| + ok.PacksURL = page + "#packs-title" |
| + } |
| + if len(v.Change.Upgrades) > 0 { |
| + ok.UpgradeURL = page + "#upgrade" |
| + } |
| + if l := v.limits; l != nil && l.RunningThings > 0 && l.DiskBytes > 0 { |
| key := "welcome.room" |
| if l.CustomDomains { |
| key = "welcome.room_domains" |
| } |
| running := fmt.Sprintf(billingCopy["limit.running"], billingCount(int64(l.RunningThings))) |
| - w.Room = fmt.Sprintf(billingCopy[key], running, billingBytes(l.DiskBytes)) |
| + ok.Room = fmt.Sprintf(billingCopy[key], running, billingBytes(l.DiskBytes)) |
| } |
| - return w |
| + return ok |
| +} |
| + |
| +// renderBillingSuccess answers the success screen in place of the billing |
| +// page: the message and its links, and none of the page's sections or the |
| +// account's chrome (no nav, switcher or plan banners), only the console's |
| +// name linking home. The flash the purchase left is taken unshown: the |
| +// screen says what it said, and more. |
| +func (s *Server) renderBillingSuccess(w http.ResponseWriter, r *http.Request, view *billingView) { |
| + s.takeFlash(w, r) |
| + s.render(w, http.StatusOK, "billing_done", page{Title: view.Success.Title, Billing: view}) |
| } |
| // billingBuy is the purchase form. The currency: an account's fixed one |
diff --git a/internal/console/billingpage_copy.go b/internal/console/billingpage_copy.go| index 797caa0b3..be796d5f0 100644 |
| --- a/internal/console/billingpage_copy.go |
| +++ b/internal/console/billingpage_copy.go |
| @@ -9,7 +9,7 @@ package console |
| // here. The change.* keys below are the plan's drafts for Task 10, declared |
| // here because Confirm now and the refusals of this task use them. |
| var billingCopy = map[string]string{ |
| - "change.done": "Done. Your new limits apply now.", |
| + "change.done": "Your billing change is saved.", |
| "change.pending": "Your card didn't go through, so nothing changed. Pay from Payment and invoices to finish.", |
| "change.declined": "Your card was declined, so nothing changed.", |
| "change.uncertain": "We couldn't confirm this payment yet. Check again in a few minutes.", |
| @@ -86,7 +86,8 @@ var billingCopy = map[string]string{ |
| "buy.title": "Choose a plan", |
| "buy.button": "Continue to payment", |
| "team.price": "%s per member a year, for at least %d members", |
| - "team.members": "%d members, paid for %d", |
| + "team.members_one": "%d member, %d seats paid for", |
| + "team.members_many": "%d members, %d seats paid for", |
| "renews": "Renews on %s", |
| "button.confirm": "Confirm now", |
| "button.continue": "Continue to payment", |
| @@ -141,10 +142,10 @@ var billingCopy = map[string]string{ |
| "duration.hour": "%d hour", |
| "duration.hours": "%d hours", |
| - // The thank-you panel after a completed purchase (2026-10-28): the |
| - // heading, a line naming the account and its plan, the room the plan |
| - // gives (with or without custom domains), and its three links. DRAFTS |
| - // for copy review. |
| + // The success screen after a completed Checkout (2026-10-28, approved): |
| + // the heading, a line naming the account and its plan, the room the |
| + // plan gives (with or without custom domains), and the three links |
| + // every success screen carries. |
| "welcome.title": "Thank you for subscribing", |
| "welcome.lede": "%s is now on %s. Your new limits are ready to use.", |
| "welcome.room": "You have room for %s, with %s of disk each.", |
| @@ -152,4 +153,14 @@ var billingCopy = map[string]string{ |
| "welcome.packs": "Add packs", |
| "welcome.upgrade": "Upgrade", |
| "welcome.apps": "Go to your apps", |
| + |
| + // The success screen after an upgrade or a pack raise the provider |
| + // applied (2026-10-29): its heading and line, and the flash the change |
| + // leaves in case the page can't show the screen. copy approved by Paul 2026-10-29. |
| + "done.upgrade.title": "You're now on %s", |
| + "done.upgrade.lede": "The new limits for %s are ready to use.", |
| + "done.upgrade.flash": "You're now on %s.", |
| + "done.packs.title": "Your packs are ready", |
| + "done.packs.lede": "Your packs are ready to use on %s.", |
| + "done.packs.flash": "Your packs are ready to use.", |
| } |
diff --git a/internal/console/billingpage_test.go b/internal/console/billingpage_test.go| index e2f380681..71aa259c5 100644 |
| --- a/internal/console/billingpage_test.go |
| +++ b/internal/console/billingpage_test.go |
| @@ -110,7 +110,7 @@ func TestDecideBillingPage(t *testing.T) { |
| "notice.unresolved", "notice.operator_plan", "notice.confirming", "notice.settling", "notice.pending_payment", |
| "notice.checkout_open", "notice.collecting", "notice.ending", "notice.seat_drift", "notice.owners_only", |
| "currency.refused", "currency.refused_unshown", "currency.fixed", "buy.title", "buy.button", "team.price", |
| - "team.members", "renews", "button.confirm", "button.continue", "button.start_over", "button.match_seats", |
| + "team.members_one", "team.members_many", "renews", "button.confirm", "button.continue", "button.start_over", "button.match_seats", |
| "button.portal", "upgrade.not_owner_title", "upgrade.not_owner", "pick.title", |
| // Task 8's own labels and messages (no wording outside the map). |
| "page.eyebrow", "page.read_failed", "upgrade.read_failed", "error.title", "upgrade.new_account"} { |
| @@ -444,7 +444,7 @@ func TestBillingPagePaidFacts(t *testing.T) { |
| _, body := pf.page(t, "") |
| base := `action="/a/` + pf.acct.Sqid + `/billing/` |
| for _, want := range []string{ |
| - esc(fmt.Sprintf(billingCopy["team.members"], 1, 12)), |
| + esc(fmt.Sprintf(billingCopy["team.members_one"], 1, 12)), |
| esc(fmt.Sprintf(billingCopy["renews"], periodEnd.UTC().Format("2 January 2006"))), |
| esc(fmt.Sprintf(billingCopy["fact.currency"], "GBP")), |
| base + `change"`, base + `renewal"`, base + `portal"`, |
| @@ -960,7 +960,7 @@ func TestBillingPageActionsInOrder(t *testing.T) { |
| } |
| } |
| -// ---- the thank-you panel ---------------------------------------------------- |
| +// ---- the success screen --------------------------------------------------- |
| // payFor makes the fixture's account a live, paid subscriber to plan with |
| // packs, in usd; mod adjusts the billing state first. |
| @@ -983,10 +983,10 @@ func (pf *billingPageFixture) payFor(t *testing.T, plan string, packs map[string |
| } |
| } |
| -// welcomePanel is the thank-you panel's markup in body, "" when it is not |
| -// there. |
| -func welcomePanel(body string) string { |
| - i := strings.Index(body, `<section class="welcome"`) |
| +// successScreen is the success screen's markup in body, "" when the page is |
| +// not the success screen. |
| +func successScreen(body string) string { |
| + i := strings.Index(body, `<section class="done"`) |
| if i < 0 { |
| return "" |
| } |
| @@ -994,75 +994,140 @@ func welcomePanel(body string) string { |
| return s[:strings.Index(s, "</section>")+len("</section>")] |
| } |
| -// TestBillingPageWelcome: ?welcome=1 (the completed return's marker) shows |
| -// the thank-you panel above the summary, naming the account, the plan and |
| -// the room it gives, with Add packs and Upgrade jumping to sections that |
| -// exist on the page and Go to your apps. The marker alone proves nothing: |
| -// the panel shows only to an owner whose account is live and paid on that |
| -// page load. |
| -func TestBillingPageWelcome(t *testing.T) { |
| +// billingPageParts are markers of the billing page's own sections and the |
| +// account chrome around it, none of which the success screen carries. |
| +var billingPageParts = []string{ |
| + `class="tile billing-now"`, `id="packs-title"`, `id="upgrade"`, `class="banner`, `class="pagehead"`, |
| + `<form`, `<nav`, `class="switcher"`, `/billing/change"`, `/billing/portal"`, |
| +} |
| + |
| +// TestBillingPageSuccessScreen: ?done=checkout, ?done=upgrade and |
| +// ?done=packs (the markers a completed purchase redirects with) replace |
| +// the billing page with a screen of its own: the message for that |
| +// purchase, the room the plan gives, and Add packs, Upgrade and Go to your |
| +// apps, with nothing else of the billing page or the account's chrome. |
| +// Add packs and Upgrade go back to the billing page's own sections. |
| +func TestBillingPageSuccessScreen(t *testing.T) { |
| pf := newBillingPageFixture(t) |
| sqid := pf.acct.Sqid |
| - |
| - // A free account: a hand-typed marker shows nothing extra. |
| - if _, body := pf.page(t, "welcome=1"); welcomePanel(body) != "" || strings.Contains(body, esc(billingCopy["welcome.title"])) { |
| - t.Fatalf("free account showed the panel:\n%s", body) |
| - } |
| - |
| - pf.payFor(t, "personal", map[string]int{}, nil) |
| - // Without the marker, a paid account's page is as before. |
| - if _, body := pf.page(t, ""); welcomePanel(body) != "" { |
| - t.Fatalf("no marker, yet the panel shows:\n%s", body) |
| - } |
| - _, body := pf.page(t, "welcome=1") |
| - panel := welcomePanel(body) |
| - if panel == "" { |
| - t.Fatalf("paid account with the marker: no panel:\n%s", body) |
| - } |
| - l, err := pf.srv.cfg.PlanCatalog.Effective("personal", nil, nil, 1) |
| + pf.payFor(t, "personal", map[string]int{"apps": 2}, nil) |
| + l, err := pf.srv.cfg.PlanCatalog.Effective("personal", map[string]int{"apps": 2}, nil, 1) |
| if err != nil { |
| t.Fatal(err) |
| } |
| room := fmt.Sprintf(billingCopy["welcome.room_domains"], |
| fmt.Sprintf(billingCopy["limit.running"], billingCount(int64(l.RunningThings))), billingBytes(l.DiskBytes)) |
| - for _, want := range []string{ |
| - esc(billingCopy["welcome.title"]), |
| - esc(fmt.Sprintf(billingCopy["welcome.lede"], pf.acct.Name, "Personal")), |
| - esc(room), |
| - `href="#packs-title"`, esc(billingCopy["welcome.packs"]), |
| - `href="#upgrade"`, esc(billingCopy["welcome.upgrade"]), |
| - `href="/a/` + sqid + `/"`, esc(billingCopy["welcome.apps"]), |
| + |
| + _, plain := pf.page(t, "") |
| + for _, c := range []struct { |
| + marker string |
| + title, lede string |
| + }{ |
| + {"checkout", billingCopy["welcome.title"], fmt.Sprintf(billingCopy["welcome.lede"], pf.acct.Name, "Personal")}, |
| + {"upgrade", fmt.Sprintf(billingCopy["done.upgrade.title"], "Personal"), fmt.Sprintf(billingCopy["done.upgrade.lede"], pf.acct.Name)}, |
| + {"packs", billingCopy["done.packs.title"], fmt.Sprintf(billingCopy["done.packs.lede"], pf.acct.Name)}, |
| } { |
| - if !strings.Contains(panel, want) { |
| - t.Errorf("panel is missing %q:\n%s", want, panel) |
| - } |
| + t.Run(c.marker, func(t *testing.T) { |
| + status, body := pf.page(t, "done="+c.marker) |
| + screen := successScreen(body) |
| + if status != http.StatusOK || screen == "" { |
| + t.Fatalf("paid account with ?done=%s: %d, no success screen:\n%s", c.marker, status, body) |
| + } |
| + for _, want := range []string{ |
| + `<h1 id="done-title">` + esc(c.title) + `</h1>`, |
| + esc(c.lede), esc(room), |
| + `href="/a/` + sqid + `/billing#packs-title"`, esc(billingCopy["welcome.packs"]), |
| + `href="/a/` + sqid + `/billing#upgrade"`, esc(billingCopy["welcome.upgrade"]), |
| + `href="/a/` + sqid + `/"`, esc(billingCopy["welcome.apps"]), |
| + } { |
| + if !strings.Contains(screen, want) { |
| + t.Errorf("the screen is missing %q:\n%s", want, screen) |
| + } |
| + } |
| + if !strings.Contains(body, "<title>"+esc(c.title)+" · ") { |
| + t.Errorf("the document title is not the screen's:\n%s", body[:strings.Index(body, "</title>")+8]) |
| + } |
| + // Nothing of the billing page, and none of the account's |
| + // chrome: no nav, no switcher, no forms at all. |
| + for _, part := range billingPageParts { |
| + if strings.Contains(body, part) { |
| + t.Errorf("the success screen carries %q", part) |
| + } |
| + } |
| + // Each link lands on an id the billing page itself has, without |
| + // the marker (which would show this screen again). |
| + for _, m := range regexp.MustCompile(`href="/a/[^"/]+/billing([^"]*)"`).FindAllStringSubmatch(screen, -1) { |
| + frag, ok := strings.CutPrefix(m[1], "#") |
| + if !ok || frag == "" { |
| + t.Errorf("a link to the billing page carries %q, want only a fragment", m[1]) |
| + continue |
| + } |
| + if !strings.Contains(plain, `id="`+frag+`"`) { |
| + t.Errorf("the screen links #%s, which the billing page has no id for", frag) |
| + } |
| + } |
| + }) |
| } |
| - // Every anchor the panel links lands on an id the page has. |
| - for _, m := range regexp.MustCompile(`href="#([^"]+)"`).FindAllStringSubmatch(panel, -1) { |
| - if !strings.Contains(body, `id="`+m[1]+`"`) { |
| - t.Errorf("the panel links #%s, which the page has no id for", m[1]) |
| + |
| + // An unknown marker, or the old one, is the billing page. |
| + for _, q := range []string{"done=1", "done=refund", "welcome=1", "done="} { |
| + if _, body := pf.page(t, q); successScreen(body) != "" || !strings.Contains(body, `class="tile billing-now"`) { |
| + t.Errorf("?%s: want the billing page, no success screen", q) |
| } |
| } |
| - // The panel leads: above the summary tile. |
| - if i, j := strings.Index(body, `<section class="welcome"`), strings.Index(body, `class="tile billing-now"`); i > j { |
| - t.Error("the panel renders below the summary") |
| - } |
| - // It carries no form, so it adds nothing a CSRF check would have to cover. |
| - if strings.Contains(panel, "<form") { |
| - t.Errorf("the panel has a form:\n%s", panel) |
| + |
| + // Without a marker, a paid account's page is the billing page. |
| + if successScreen(plain) != "" || !strings.Contains(plain, `class="tile billing-now"`) { |
| + t.Fatalf("no marker, yet the success screen shows:\n%s", plain) |
| } |
| // The top plan: nothing higher, so no Upgrade. |
| pf.payFor(t, "business", map[string]int{}, nil) |
| - _, body = pf.page(t, "welcome=1") |
| - if panel := welcomePanel(body); panel == "" || strings.Contains(panel, `href="#upgrade"`) || strings.Contains(panel, esc(billingCopy["welcome.upgrade"])) { |
| - t.Errorf("top plan: want the panel without Upgrade:\n%s", panel) |
| + _, body := pf.page(t, "done=upgrade") |
| + if screen := successScreen(body); screen == "" || strings.Contains(screen, `#upgrade"`) || strings.Contains(screen, esc(billingCopy["welcome.upgrade"])) { |
| + t.Errorf("top plan: want the screen without Upgrade:\n%s", screen) |
| } |
| - if strings.Contains(body, `id="upgrade"`) { |
| - t.Error("top plan: an upgrades section with nothing in it") |
| + |
| + // A plan with no packs: no Add packs. |
| + cat := pf.srv.cfg.PlanCatalog |
| + business := cat.Plans["business"] |
| + business.Packs = nil |
| + cat.Plans["business"] = business |
| + _, body = pf.page(t, "done=checkout") |
| + if screen := successScreen(body); screen == "" || strings.Contains(screen, `#packs-title"`) || strings.Contains(screen, esc(billingCopy["welcome.packs"])) { |
| + t.Errorf("no packs: want the screen without Add packs:\n%s", screen) |
| } |
| - // Settling or collecting: the marker shows nothing extra, and the page |
| + // The marker's flash steps aside: the screen says more. |
| + pf.payFor(t, "personal", map[string]int{}, nil) |
| + u, _ := url.Parse(pf.ts.URL) |
| + done := fmt.Sprintf(billingCopy["checkout.done"], "Personal") |
| + pf.owner.Jar.SetCookies(u, []*http.Cookie{{Name: flashCookie, Value: url.QueryEscape("ok|" + done), Path: "/"}}) |
| + _, body = pf.page(t, "done=checkout") |
| + if successScreen(body) == "" || strings.Contains(body, esc(done)) { |
| + t.Errorf("with the return's flash: want the screen and no flash:\n%s", body) |
| + } |
| + // ... and is taken, so it doesn't turn up on the next page either. |
| + if _, body = pf.page(t, ""); strings.Contains(body, esc(done)) { |
| + t.Error("the flash the screen replaced showed on the next page") |
| + } |
| +} |
| + |
| +// TestBillingPageSuccessScreenRefused: the marker proves nothing on its own. |
| +// A free, settling, collecting or ending account, and a member, get the |
| +// billing page with no success screen, whatever the marker says. |
| +func TestBillingPageSuccessScreenRefused(t *testing.T) { |
| + pf := newBillingPageFixture(t) |
| + markers := []string{"checkout", "upgrade", "packs"} |
| + |
| + // A free account: a hand-typed marker shows nothing extra. |
| + for _, m := range markers { |
| + if _, body := pf.page(t, "done="+m); successScreen(body) != "" || !strings.Contains(body, `class="tile billing-now"`) { |
| + t.Errorf("free account, ?done=%s: want the billing page:\n%s", m, body) |
| + } |
| + } |
| + |
| + // Settling, collecting, ending, or a plan an operator set: the page |
| // keeps its notice. |
| for _, c := range []struct { |
| name, notice string |
| @@ -1070,31 +1135,59 @@ func TestBillingPageWelcome(t *testing.T) { |
| }{ |
| {"settling", "notice.settling", func(b *billingAccount) { b.State = billing.StatePending }}, |
| {"collecting", "notice.collecting", func(b *billingAccount) { b.Collecting = true }}, |
| + {"unpaid", "notice.pending_payment", func(b *billingAccount) { b.PendingUpdate = true }}, |
| } { |
| pf.payFor(t, "personal", map[string]int{}, c.mod) |
| - _, body := pf.page(t, "welcome=1") |
| - if welcomePanel(body) != "" || !strings.Contains(body, esc(billingCopy[c.notice])) { |
| - t.Errorf("%s: want its notice and no panel:\n%s", c.name, body) |
| + for _, m := range markers { |
| + _, body := pf.page(t, "done="+m) |
| + if successScreen(body) != "" || !strings.Contains(body, esc(billingCopy[c.notice])) { |
| + t.Errorf("%s, ?done=%s: want its notice and no screen:\n%s", c.name, m, body) |
| + } |
| } |
| } |
| + pf.payFor(t, "personal", map[string]int{}, func(b *billingAccount) { b.CancelAtPeriodEnd = true }) |
| + if _, body := pf.page(t, "done=upgrade"); successScreen(body) != "" || !strings.Contains(body, `class="tile billing-now"`) { |
| + t.Errorf("renewal stopped, ?done=upgrade: want the billing page:\n%s", body) |
| + } |
| - // A member never sees a purchase thank-you. |
| + // A member never sees a purchase's success screen. |
| pf.payFor(t, "personal", map[string]int{}, nil) |
| if err := pf.st.AddMember(pf.acct.ID, "member@example.com", RoleMember, time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| - member, _ := signInAs(t, pf.consoleFixture, "member@example.com", "code-billing-welcome-member") |
| - if _, _, body := get(t, member, pf.ts.URL+pf.billingPath("welcome=1")); welcomePanel(body) != "" { |
| - t.Errorf("a member saw the panel:\n%s", body) |
| + member, _ := signInAs(t, pf.consoleFixture, "member@example.com", "code-billing-done-member") |
| + for _, m := range markers { |
| + if _, _, body := get(t, member, pf.ts.URL+pf.billingPath("done="+m)); successScreen(body) != "" || !strings.Contains(body, `class="tile billing-now"`) { |
| + t.Errorf("a member, ?done=%s: want the billing page:\n%s", m, body) |
| + } |
| } |
| +} |
| - // The return's plain flash steps aside for the panel. |
| - u, _ := url.Parse(pf.ts.URL) |
| - done := fmt.Sprintf(billingCopy["checkout.done"], "Personal") |
| - pf.owner.Jar.SetCookies(u, []*http.Cookie{{Name: flashCookie, Value: url.QueryEscape("ok|" + done), Path: "/"}}) |
| - _, body = pf.page(t, "welcome=1") |
| - if welcomePanel(body) == "" || strings.Contains(body, esc(done)) { |
| - t.Errorf("with the return's flash: want the panel and no flash:\n%s", body) |
| +// TestBillingPageMembersPlural: the summary counts a team's members as |
| +// "1 member" and "2 members". |
| +func TestBillingPageMembersPlural(t *testing.T) { |
| + pf := newBillingPageFixture(t) |
| + pf.payFor(t, "community", map[string]int{}, nil) |
| + summary := func() string { |
| + _, body := pf.page(t, "") |
| + i := strings.Index(body, `class="tile billing-now"`) |
| + if i < 0 { |
| + t.Fatalf("no summary:\n%s", body) |
| + } |
| + s := body[i:] |
| + return s[:strings.Index(s, "</section>")] |
| + } |
| + seats := pf.srv.cfg.PlanCatalog.Plans["community"].Team.MinMembers |
| + one := fmt.Sprintf(billingCopy["team.members_one"], 1, seats) |
| + if s := summary(); !strings.Contains(s, esc(one)) || !strings.HasPrefix(one, "1 member,") { |
| + t.Errorf("one member: want %q:\n%s", one, s) |
| + } |
| + if err := pf.st.AddMember(pf.acct.ID, "second@example.com", RoleMember, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + two := fmt.Sprintf(billingCopy["team.members_many"], 2, seats) |
| + if s := summary(); !strings.Contains(s, esc(two)) || !strings.HasPrefix(two, "2 members,") { |
| + t.Errorf("two members: want %q:\n%s", two, s) |
| } |
| } |
diff --git a/internal/console/templates/billing.html b/internal/console/templates/billing.html| index cecc780b8..bc195aff5 100644 |
| --- a/internal/console/templates/billing.html |
| +++ b/internal/console/templates/billing.html |
| @@ -6,18 +6,6 @@ |
| <h1>{{billingText "page.title"}}</h1> |
| </div> |
| {{with .Billing}} |
| -{{with .Welcome}}<section class="welcome" aria-labelledby="welcome-title"> |
| - <span class="welcome-mark">{{icon "check"}}</span> |
| - <div> |
| - <h2 id="welcome-title">{{billingText "welcome.title"}}</h2> |
| - <p>{{.Lede}}{{if .Room}} {{.Room}}{{end}}</p> |
| - <p class="welcome-actions"> |
| - {{if .Packs}}<a class="btn btn-secondary" href="#packs-title">{{billingText "welcome.packs"}}</a> |
| - {{end}}{{if .Upgrade}}<a class="btn btn-secondary" href="#upgrade">{{billingText "welcome.upgrade"}}</a> |
| - {{end}}<a class="btn" href="{{$.Base}}/">{{billingText "welcome.apps"}}</a> |
| - </p> |
| - </div> |
| -</section>{{end}} |
| {{if .Notice}}<p class="banner">{{.Notice}}</p>{{end}} |
| {{if .OwnersOnly}}<p class="banner">{{.OwnersOnly}}</p>{{end}} |
| {{if .CurrencyNotice}}<p class="banner error">{{.CurrencyNotice}}</p>{{end}} |
diff --git a/internal/console/templates/billing_done.html b/internal/console/templates/billing_done.html| new file mode 100644 |
| index 000000000..3962409f2 |
| --- /dev/null |
| +++ b/internal/console/templates/billing_done.html |
| @@ -0,0 +1,17 @@ |
| +{{define "billing_done"}}{{template "top" .}} |
| +{{/* The success screen after a completed purchase: it replaces the billing |
| + page, so it carries the message and its links and nothing else. The |
| + page is rendered without the account's chrome (renderBillingSuccess): |
| + the header holds only the console's name. */}} |
| +{{with .Billing.Success}}<section class="done" aria-labelledby="done-title"> |
| + <span class="done-mark">{{icon "check"}}</span> |
| + <h1 id="done-title">{{.Title}}</h1> |
| + <p class="done-lede">{{.Lede}}</p> |
| + {{if .Room}}<p class="done-room">{{.Room}}</p> |
| + {{end}}<p class="done-actions"> |
| + {{if .PacksURL}}<a class="btn btn-secondary" href="{{.PacksURL}}">{{billingText "welcome.packs"}}</a> |
| + {{end}}{{if .UpgradeURL}}<a class="btn btn-secondary" href="{{.UpgradeURL}}">{{billingText "welcome.upgrade"}}</a> |
| + {{end}}<a class="btn" href="{{.AppsURL}}">{{billingText "welcome.apps"}}</a> |
| + </p> |
| +</section>{{end}} |
| +{{template "bottom" .}}{{end}} |
diff --git a/internal/console/templates/layout.html b/internal/console/templates/layout.html| index 31cda574c..ac5827eeb 100644 |
| --- a/internal/console/templates/layout.html |
| +++ b/internal/console/templates/layout.html |
| @@ -785,44 +785,41 @@ |
| .buy-foot { margin: 1.75rem 0 0; } |
| .buy-foot button { padding: 0.7rem 1.5rem; } |
| .billing-upgrades { margin-top: 1.25rem; } |
| - /* The thank-you panel after a completed purchase: the one moment on |
| - this page that gets a flourish. A check that draws itself once in an |
| - accent disc, a heading with room to breathe, the plan's room in a |
| - sentence, and three links (Add packs and Upgrade jump down the page). |
| - It sits on the page's own background inside an accent edge, so it |
| - reads apart from the tinted summary tile beneath it. */ |
| - .welcome { |
| - display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 1.1rem; |
| - margin: 0 0 1.5rem; padding: 1.4rem 1.5rem 1.5rem; |
| - border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--rule)); |
| - border-radius: 0.75rem; background: var(--bg); |
| - } |
| - .welcome-mark { |
| - display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 50%; |
| - background: var(--accent); color: var(--bg); |
| - } |
| - .welcome-mark .icon { width: 1.35rem; height: 1.35rem; stroke-width: 2.6; } |
| - .welcome h2 { margin: 0.35rem 0 0.4rem; font-size: 1.45rem; line-height: 1.25; letter-spacing: -0.01em; text-wrap: balance; } |
| - .welcome p { margin: 0; max-width: 62ch; text-wrap: pretty; overflow-wrap: anywhere; } |
| - .welcome .welcome-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1.15rem 0 0; max-width: none; } |
| - .welcome-actions .btn { padding: 0.55rem 1.1rem; } |
| - .welcome-actions .btn:not(.btn-secondary) { border: 1px solid transparent; } |
| - /* The links land on headings, a little clear of the window's top. */ |
| + /* The success screen after a completed purchase (billing_done.html): |
| + it replaces the billing page, so it stands alone in the middle of an |
| + otherwise empty page. A check that draws itself once in an accent |
| + disc, the heading, the plan's room in a sentence, and its links: |
| + Add packs and Upgrade go back to the billing page's sections, Go to |
| + your apps is the way on. */ |
| + .done { max-width: 36rem; margin: clamp(1rem, 9vh, 5.5rem) auto 0; text-align: center; } |
| + .done-mark { |
| + display: inline-grid; place-items: center; width: 3.25rem; height: 3.25rem; border-radius: 50%; |
| + margin: 0 0 1.4rem; background: var(--accent); color: var(--bg); |
| + } |
| + .done-mark .icon { width: 1.6rem; height: 1.6rem; stroke-width: 2.6; } |
| + .done h1 { margin: 0 0 0.8rem; font-size: clamp(1.65rem, 1.2rem + 1.6vw, 2.15rem); line-height: 1.15; letter-spacing: -0.015em; text-wrap: balance; overflow-wrap: anywhere; } |
| + .done-lede, .done-room { margin: 0 auto; max-width: 32rem; text-wrap: pretty; overflow-wrap: anywhere; } |
| + .done-lede { font-size: 1.05rem; } |
| + .done-room { margin-top: 0.5rem; color: var(--muted); } |
| + .done-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; margin: 2rem 0 0; } |
| + .done-actions .btn { padding: 0.6rem 1.25rem; } |
| + .done-actions .btn:not(.btn-secondary) { border: 1px solid transparent; } |
| + .done-actions .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } |
| + /* Its links land on these headings, a little clear of the window's top. */ |
| #packs-title, #upgrade { scroll-margin-top: 1.5rem; } |
| @media (prefers-reduced-motion: no-preference) { |
| - .welcome-mark { animation: welcome-pop 520ms cubic-bezier(0.16, 1, 0.3, 1) both; } |
| - .welcome-mark path { stroke-dasharray: 24; animation: welcome-draw 480ms 200ms cubic-bezier(0.16, 1, 0.3, 1) both; } |
| + .done-mark { animation: done-pop 520ms cubic-bezier(0.16, 1, 0.3, 1) both; } |
| + .done-mark path { stroke-dasharray: 24; animation: done-draw 480ms 200ms cubic-bezier(0.16, 1, 0.3, 1) both; } |
| } |
| - @keyframes welcome-pop { from { transform: scale(0.7); } } |
| - @keyframes welcome-draw { from { stroke-dashoffset: 24; } to { stroke-dashoffset: 0; } } |
| + @keyframes done-pop { from { transform: scale(0.7); } } |
| + @keyframes done-draw { from { stroke-dashoffset: 24; } to { stroke-dashoffset: 0; } } |
| @media (min-width: 46rem) { |
| .billing-includes { grid-template-columns: repeat(2, auto); } |
| } |
| @media (max-width: 40rem) { |
| .billing-now { padding: 1rem 1.1rem 1.1rem; } |
| - .welcome { grid-template-columns: minmax(0, 1fr); padding: 1.2rem 1.15rem 1.25rem; } |
| - .welcome h2 { margin-top: 0.8rem; font-size: 1.3rem; } |
| - .welcome-actions .btn { flex: 1 1 8rem; text-align: center; } |
| + .done-actions { flex-direction: column; align-items: stretch; margin-top: 1.75rem; } |
| + .done-actions .btn { text-align: center; } |
| .packs tr { |
| display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; |
| gap: 0.6rem 1rem; padding: 0.8rem 0; border-bottom: 1px solid var(--rule); |