carlos / platform Public

console: a thank-you panel after a completed purchase, with Add packs, Upgrade and Go to your apps; readable packs and currency in the plan summary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev bfd2c63e4a7ae9430b256825c5f368023abbf8af parent 674fec4
7 files changed, +333 −29
  • internal/console/billingcheckout.go +6 −1
  • internal/console/billingcheckout_test.go +10 −3
  • internal/console/billingpage.go +64 −15
  • internal/console/billingpage_copy.go +17 −3
  • internal/console/billingpage_test.go +188 −4
  • internal/console/templates/billing.html +15 −3
  • internal/console/templates/layout.html +33 −0
diff --git a/internal/console/billingcheckout.go b/internal/console/billingcheckout.go
index 9a04fc335..6b6fa603a 100644
--- a/internal/console/billingcheckout.go
+++ b/internal/console/billingcheckout.go
@@ -1078,7 +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, saying which plan the account is on when it is paid.
+// page. A completed, paid return carries the thank-you marker (?welcome=1,
+// which the page checks against the account's state again) and a flash
+// naming the plan, which the panel replaces.
func (s *Server) handleBillingDone(w http.ResponseWriter, r *http.Request) {
if s.billing == nil {
http.NotFound(w, r)
@@ -1104,6 +1106,9 @@ func (s *Server) handleBillingDone(w http.ResponseWriter, r *http.Request) {
if text != "" {
s.setFlash(w, kind, text)
}
+ if kind == "ok" {
+ back += "?welcome=1"
+ }
http.Redirect(w, r, back, http.StatusSeeOther)
}
diff --git a/internal/console/billingcheckout_test.go b/internal/console/billingcheckout_test.go
index 12c3ab36c..f2ec185e6 100644
--- a/internal/console/billingcheckout_test.go
+++ b/internal/console/billingcheckout_test.go
@@ -895,9 +895,16 @@ 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)
- if r.Status != http.StatusSeeOther || r.Loc != o.billingBase() || r.Flash != "ok" || r.FlashMsg != fmt.Sprintf(billingCopy["checkout.done"], "Personal") {
+ // A completed, paid return: the billing page with the thank-you 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") {
t.Fatalf("done = %+v", r)
}
+ // Following it shows the panel 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)
+ }
// 1 session read + S.
wantCounts(t, o.counts(), map[string]int{"Checkout": 1, "Subscription": 1})
if got := o.intent(t); got.State != intentCompleted || got.ReturnedAt.IsZero() || o.plan(t) != "personal" {
@@ -1302,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.Flash != "ok" || r.FlashMsg != fmt.Sprintf(billingCopy["checkout.done"], "Personal") {
+ if r.Loc != o.billingBase()+"?welcome=1" || 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})
@@ -1334,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.Flash != "ok" || r.FlashMsg != fmt.Sprintf(billingCopy["checkout.done"], "Personal") {
+ if r.Loc != o.billingBase()+"?welcome=1" || 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 442ea9b52..0dfba71c2 100644
--- a/internal/console/billingpage.go
+++ b/internal/console/billingpage.go
@@ -198,10 +198,13 @@ type billingView struct {
// The summary: the current plan's label, its facts (packs held,
// members on a team plan, currency, renewal) and a few of the limits
// it gives the account today.
- Plan string
- Facts []string
- Includes []string
- Offers billingOffers
+ Plan string
+ Facts []string
+ Includes []string
+ Offers billingOffers
+ // Welcome is the thank-you panel after a completed purchase, nil for
+ // none (billingWelcomeFor).
+ Welcome *billingWelcome
Buy *billingBuyView
Change *billingChangeView
StartOver []billingField // the open intent's own request, for Start over
@@ -215,6 +218,15 @@ 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
+}
+
// billingBuyView is the first purchase: the paid plans, a quantity per
// offered pack, and the currency, all in one form. Every currency the form
// can submit has its prices on the page: with radios, each plan, team
@@ -227,6 +239,7 @@ type billingBuyView struct {
Packs []billingPackInput
Currencies []billingCurrencyOption
FixedCurrency string
+ FixedLabel string // FixedCurrency as a person reads it: "EUR"
}
// billingPrice is one price as the page shows it, in one currency.
@@ -251,8 +264,8 @@ type billingPackInput struct {
}
type billingCurrencyOption struct {
- Code string
- Checked bool
+ Code, Label string // Label: the code as a person reads it, "USD"
+ Checked bool
}
// billingChangeView is a paid account's changes: one form per pack, and an
@@ -321,6 +334,11 @@ func (s *Server) handleBilling(w http.ResponseWriter, r *http.Request) {
view := s.billingViewFor(r, in, st, members)
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
@@ -374,6 +392,7 @@ 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) {
@@ -384,20 +403,22 @@ 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
}
}
- if held := heldPacks(packs); len(held) > 0 {
- var parts []string
- for _, name := range held {
- parts = append(parts, fmt.Sprintf("%s %d", name, packs[name]))
+ // A line per pack held: "4 Apps packs".
+ for _, name := range heldPacks(packs) {
+ key := "fact.pack_many"
+ if packs[name] == 1 {
+ key = "fact.pack_one"
}
- v.Facts = append(v.Facts, fmt.Sprintf(billingCopy["fact.packs"], strings.Join(parts, ", ")))
+ 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))
}
if b != nil && b.Currency != "" {
- v.Facts = append(v.Facts, fmt.Sprintf(billingCopy["fact.currency"], b.Currency))
+ v.Facts = append(v.Facts, fmt.Sprintf(billingCopy["fact.currency"], strings.ToUpper(b.Currency)))
}
if b != nil && b.Live && !b.PeriodEnd.IsZero() {
switch {
@@ -414,6 +435,9 @@ 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}}
@@ -425,6 +449,31 @@ 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 {
+ 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 {
+ 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))
+ }
+ return w
+}
+
// billingBuy is the purchase form. The currency: an account's fixed one
// (Call 3) as text; else radios for the book's currencies, preselecting an
// explicit sold code, else the visitor's country's, else the book's
@@ -436,10 +485,10 @@ func (s *Server) billingBuy(r *http.Request, book *plans.PriceBook, b *billingAc
raw := r.URL.Query().Get("currency")
codes, order := book.Currencies, book.DefaultCurrency
if b != nil && b.Currency != "" {
- buy.FixedCurrency = b.Currency
+ buy.FixedCurrency, buy.FixedLabel = b.Currency, strings.ToUpper(b.Currency)
codes, order = []string{b.Currency}, b.Currency
if raw != "" && raw != b.Currency {
- *notice = fmt.Sprintf(billingCopy["currency.fixed"], b.Currency)
+ *notice = fmt.Sprintf(billingCopy["currency.fixed"], buy.FixedLabel)
}
} else {
chosen := ""
@@ -457,7 +506,7 @@ func (s *Server) billingBuy(r *http.Request, book *plans.PriceBook, b *billingAc
}
}
for _, c := range book.Currencies {
- buy.Currencies = append(buy.Currencies, billingCurrencyOption{Code: c, Checked: c == chosen})
+ buy.Currencies = append(buy.Currencies, billingCurrencyOption{Code: c, Label: strings.ToUpper(c), Checked: c == chosen})
}
}
diff --git a/internal/console/billingpage_copy.go b/internal/console/billingpage_copy.go
index b75ebd252..7b572ceab 100644
--- a/internal/console/billingpage_copy.go
+++ b/internal/console/billingpage_copy.go
@@ -80,8 +80,8 @@ var billingCopy = map[string]string{
"notice.ending": "Your plan ends on %s. After that the account moves to the free plan.",
"notice.seat_drift": "Your next renewal bills %d seats for %d members.",
"notice.owners_only": "Only an owner of this account can change its plan.",
- "currency.refused": "We don't sell in %q. Choose usd, eur or gbp.",
- "currency.refused_unshown": "We don't sell in that currency. Choose usd, eur or gbp.",
+ "currency.refused": "We don't sell in %q. Choose USD, EUR or GBP.",
+ "currency.refused_unshown": "We don't sell in that currency. Choose USD, EUR or GBP.",
"currency.fixed": "This account pays in %s. To change that, ask an operator.",
"buy.title": "Choose a plan",
"buy.button": "Continue to payment",
@@ -98,7 +98,9 @@ var billingCopy = map[string]string{
"pick.title": "Which account?",
// Task 8's own drafts, beyond the plan's list: labels the page needs.
- "fact.packs": "Packs: %s",
+ // The summary names each pack held on its own line (2026-10-28).
+ "fact.pack_one": "%d %s pack",
+ "fact.pack_many": "%d %s packs",
"fact.currency": "Pays in %s",
"plan.price": "%s a year",
"pack.price": "%s a year each",
@@ -138,4 +140,16 @@ var billingCopy = map[string]string{
"duration.minutes": "%d minutes",
"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.
+ "welcome.title": "Thank you for subscribing",
+ "welcome.lede": "%s is on %s now, and its new limits already apply.",
+ "welcome.room": "That's room for %s, with %s of disk each.",
+ "welcome.room_domains": "That's room for %s, with %s of disk each, and you can use your own domains.",
+ "welcome.packs": "Add packs",
+ "welcome.upgrade": "Upgrade",
+ "welcome.apps": "Go to your apps",
}
diff --git a/internal/console/billingpage_test.go b/internal/console/billingpage_test.go
index ce6d636b6..e2f380681 100644
--- a/internal/console/billingpage_test.go
+++ b/internal/console/billingpage_test.go
@@ -360,15 +360,15 @@ func TestBillingPageFixedCurrency(t *testing.T) {
if !strings.Contains(body, `type="hidden" name="currency" value="eur"`) || strings.Contains(body, `type="radio" name="currency"`) {
t.Fatalf("fixed currency: want a hidden eur and no radios:\n%s", body)
}
- if strings.Contains(body, esc(fmt.Sprintf(billingCopy["currency.fixed"], "eur"))) {
+ if strings.Contains(body, esc(fmt.Sprintf(billingCopy["currency.fixed"], "EUR"))) {
t.Error("no explicit currency, yet the fixed notice shows")
}
- if _, body := pf.page(t, "currency=eur"); strings.Contains(body, esc(fmt.Sprintf(billingCopy["currency.fixed"], "eur"))) {
+ if _, body := pf.page(t, "currency=eur"); strings.Contains(body, esc(fmt.Sprintf(billingCopy["currency.fixed"], "EUR"))) {
t.Error("the fixed currency itself showed the fixed notice")
}
for _, q := range []string{"usd", "jpy", "<script>"} {
_, body := pf.page(t, "currency="+url.QueryEscape(q))
- if !strings.Contains(body, esc(fmt.Sprintf(billingCopy["currency.fixed"], "eur"))) {
+ if !strings.Contains(body, esc(fmt.Sprintf(billingCopy["currency.fixed"], "EUR"))) {
t.Errorf("currency=%q on a eur account: no fixed notice", q)
}
if !strings.Contains(body, `type="hidden" name="currency" value="eur"`) {
@@ -446,7 +446,7 @@ func TestBillingPagePaidFacts(t *testing.T) {
for _, want := range []string{
esc(fmt.Sprintf(billingCopy["team.members"], 1, 12)),
esc(fmt.Sprintf(billingCopy["renews"], periodEnd.UTC().Format("2 January 2006"))),
- esc(fmt.Sprintf(billingCopy["fact.currency"], "gbp")),
+ esc(fmt.Sprintf(billingCopy["fact.currency"], "GBP")),
base + `change"`, base + `renewal"`, base + `portal"`,
`name="pack" value="apps"`, `name="quantity" value="2"`,
`name="plan" value="business"`, esc(fmt.Sprintf(billingCopy["button.upgrade"], "Business")),
@@ -959,3 +959,187 @@ func TestBillingPageActionsInOrder(t *testing.T) {
})
}
}
+
+// ---- the thank-you panel ----------------------------------------------------
+
+// payFor makes the fixture's account a live, paid subscriber to plan with
+// packs, in usd; mod adjusts the billing state first.
+func (pf *billingPageFixture) payFor(t *testing.T, plan string, packs map[string]int, mod func(b *billingAccount)) {
+ t.Helper()
+ seats := 0
+ if p := pf.srv.cfg.PlanCatalog.Plans[plan]; p.Team != nil {
+ seats = p.Team.MinMembers
+ }
+ if _, err := pf.st.SetAccountPlan(pf.acct.ID, plan, packs, seats, PlanSourceBilling, nil, "billing", "billing", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ b := billingAccount{AccountID: pf.acct.ID, Customer: "cus_1", Subscription: "sub_1", State: billing.StatePaid, Live: true,
+ Currency: "usd", PeriodEnd: periodEnd, Plan: plan, Seats: seats, PaidSeats: seats, PaidPacks: packs}
+ if mod != nil {
+ mod(&b)
+ }
+ if err := pf.st.PutBillingState(b); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// 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"`)
+ if i < 0 {
+ return ""
+ }
+ s := body[i:]
+ 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) {
+ 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)
+ 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"]),
+ } {
+ if !strings.Contains(panel, want) {
+ t.Errorf("panel is missing %q:\n%s", want, panel)
+ }
+ }
+ // 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])
+ }
+ }
+ // 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)
+ }
+
+ // 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)
+ }
+ if strings.Contains(body, `id="upgrade"`) {
+ t.Error("top plan: an upgrades section with nothing in it")
+ }
+
+ // Settling or collecting: the marker shows nothing extra, and the page
+ // keeps its notice.
+ for _, c := range []struct {
+ name, notice string
+ mod func(b *billingAccount)
+ }{
+ {"settling", "notice.settling", func(b *billingAccount) { b.State = billing.StatePending }},
+ {"collecting", "notice.collecting", func(b *billingAccount) { b.Collecting = 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)
+ }
+ }
+
+ // A member never sees a purchase thank-you.
+ 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)
+ }
+
+ // 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)
+ }
+}
+
+// TestBillingPageReadablePacksAndCurrency: the summary lists each pack held
+// as "4 Apps packs" (one line a pack) and names the currency in capitals,
+// as do the currency controls; the values they post stay the codes.
+func TestBillingPageReadablePacksAndCurrency(t *testing.T) {
+ pf := newBillingPageFixture(t)
+ pf.payFor(t, "personal", map[string]int{"apps": 4, "disk": 1}, func(b *billingAccount) { b.Currency = "gbp" })
+ _, body := pf.page(t, "")
+ i := strings.Index(body, `class="tile billing-now"`)
+ summary := body[i:]
+ summary = summary[:strings.Index(summary, "</section>")]
+ for _, want := range []string{
+ "<li>" + esc(fmt.Sprintf(billingCopy["fact.pack_many"], 4, "Apps")) + "</li>",
+ "<li>" + esc(fmt.Sprintf(billingCopy["fact.pack_one"], 1, "Disk")) + "</li>",
+ esc(fmt.Sprintf(billingCopy["fact.currency"], "GBP")),
+ } {
+ if !strings.Contains(summary, want) {
+ t.Errorf("summary is missing %q:\n%s", want, summary)
+ }
+ }
+ if strings.Contains(summary, "apps 4") || strings.Contains(summary, "gbp") {
+ t.Errorf("the summary still shows raw pack or currency codes:\n%s", summary)
+ }
+
+ // The radios' labels read in capitals; their values stay the codes.
+ free := newBillingPageFixture(t)
+ _, body = free.page(t, "")
+ for _, c := range free.srv.billing.cfg.Book.Currencies {
+ if !strings.Contains(body, `value="`+c+`"`) || !strings.Contains(body, "<span>"+strings.ToUpper(c)+"</span>") {
+ t.Errorf("currency %s: want value %q and label %q", c, c, strings.ToUpper(c))
+ }
+ }
+
+ // A fixed currency shows in capitals and still posts its code.
+ if err := free.st.PutBillingState(billingAccount{AccountID: free.acct.ID, Subscription: "sub_old", State: billing.StateEnded,
+ Currency: "eur", PaidPacks: map[string]int{}}); err != nil {
+ t.Fatal(err)
+ }
+ _, body = free.page(t, "currency=usd")
+ for _, want := range []string{`<span class="seg-fixed">EUR</span>`, `name="currency" value="eur"`,
+ esc(fmt.Sprintf(billingCopy["currency.fixed"], "EUR"))} {
+ if !strings.Contains(body, want) {
+ t.Errorf("fixed currency page is missing %q", want)
+ }
+ }
+}
diff --git a/internal/console/templates/billing.html b/internal/console/templates/billing.html
index 8c73923dc..2a1a82d8d 100644
--- a/internal/console/templates/billing.html
+++ b/internal/console/templates/billing.html
@@ -6,6 +6,18 @@
<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}}
@@ -58,11 +70,11 @@
<div class="sectionhead">
<h2 id="buy-title">{{billingText "buy.title"}}</h2>
{{if .FixedCurrency}}<p class="currency"><span class="small">{{billingText "currency.legend"}}</span>
- <span class="seg"><span class="seg-fixed">{{.FixedCurrency}}</span></span><input type="hidden" name="currency" value="{{.FixedCurrency}}"></p>
+ <span class="seg"><span class="seg-fixed">{{.FixedLabel}}</span></span><input type="hidden" name="currency" value="{{.FixedCurrency}}"></p>
{{else}}<fieldset class="currency">
<legend class="small">{{billingText "currency.legend"}}</legend>
<span class="seg">
- {{range .Currencies}}<label><input type="radio" name="currency" value="{{.Code}}"{{if .Checked}} checked{{end}} required><span>{{.Code}}</span></label>
+ {{range .Currencies}}<label><input type="radio" name="currency" value="{{.Code}}"{{if .Checked}} checked{{end}} required><span>{{.Label}}</span></label>
{{end}}</span>
</fieldset>{{end}}
</div>
@@ -116,7 +128,7 @@
{{end}}
</table>
</div>{{end}}
-{{if .Upgrades}}<div class="settings-row billing-upgrades">
+{{if .Upgrades}}<div class="settings-row billing-upgrades" id="upgrade">
{{range .Upgrades}}<form method="post" action="{{$.Base}}/billing/change">
<input type="hidden" name="csrf" value="{{$.CSRF}}">
<input type="hidden" name="plan" value="{{.Name}}">
diff --git a/internal/console/templates/layout.html b/internal/console/templates/layout.html
index de040377d..e4d508184 100644
--- a/internal/console/templates/layout.html
+++ b/internal/console/templates/layout.html
@@ -676,11 +676,44 @@
.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; }
+ .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. */
+ #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; }
+ }
+ @keyframes welcome-pop { from { transform: scale(0.7); } }
+ @keyframes welcome-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; }
.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);