From de3d5102a72edca29cad7c162ce4e989ee2b316f Mon Sep 17 00:00:00 2001 From: Christian Galo Date: Wed, 28 Oct 2026 02:55:33 -0500 Subject: [PATCH] Title a displaced subscription paused once Stripe confirms its collection pause MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fifth section of #269's change. The operator's Not delivering badge now reads the pause Stripe confirmed: a displaced subscription whose recorded pause_collection behavior is set, and whose every holder is a grant, is titled "Billing paused while a grant holds {ladders}." ("grants hold" when several grant provisions hold them). An organization with several subscriptions reads "Billing paused on {k} of {n} subscriptions while ...", followed, when some are not paused, by the existing "Billing continues on {m} while ..." sentence. The record decides "paused", never the rule: a subscription whose pause Stripe has not confirmed keeps the existing title. The organization page and the subscriptions list both read the column section 2 added. The Issue grant warning reads "Products marked ⚠ would supersede a tier a subscription pays for; its billing pauses until the grant ends." docs/stripe.md and docs/plan-management.md name the paused title and the existing one while the pause is unconfirmed. Tests: TestDisplacementTitle rows for the paused, mixed and holder forms, the mixed form in both input orders; TestDisplacedOnPage rows for a recorded pause, a Dashboard pause and a pause under a subscription holder; TestSubscriptionTitlesFor's paused row; TestSubscriptionsListMarksAPausedSubscription; the golden state grant-over-subscription-paused, which differs from grant-over-subscription only in the badge's title. The three goldens that show the warning change only in its sentence. The Dashboard-pause row records mark_uncollectible rather than the test kit's void, because displacedOnPage sees only the behavior and a void row would repeat the recorded-pause row. Review: no blocker or major. Three minors and five nits applied: five comments that still said a displaced subscription bills, a row that could not test a recorded pause under a purchase, the second input order, and a narrower failure text for the warning's break. Breaks: 9 of 9 caught. Full suite on reset databases: 4783 pass, 14 skip. make screens: no change beyond the three captures every run since section 2 redraws. The tasks expected the Issue grant captures to change; none shows the warning, because the captured organization's one subscription holds no tier, so item 5.9 now says so. --- docs/plan-management.md | 4 +- docs/stripe.md | 2 +- .../partials/operator_subscriptions.html | 2 +- internal/server/anatomy.go | 5 +- internal/server/operator_billing.go | 2 +- internal/server/operator_enrollment.go | 144 +++-- internal/server/operator_enrollment_forms.go | 8 +- .../operator_enrollment_golden_db_test.go | 7 + .../server/operator_enrollment_render_test.go | 84 ++- ...ator_subscriptions_displacement_db_test.go | 22 + .../grant-over-subscription-paused.html | 523 ++++++++++++++++++ .../grant-over-subscription-paused.json | 278 ++++++++++ .../org_enrollment/rich-history-search.html | 2 +- .../server/testdata/org_enrollment/rich.html | 2 +- .../suspended-subscription.html | 2 +- .../tasks.md | 18 +- 16 files changed, 1040 insertions(+), 65 deletions(-) create mode 100644 internal/server/testdata/org_enrollment/grant-over-subscription-paused.html create mode 100644 internal/server/testdata/org_enrollment/grant-over-subscription-paused.json diff --git a/docs/plan-management.md b/docs/plan-management.md index 4078a01c..e3c2b5f7 100644 --- a/docs/plan-management.md +++ b/docs/plan-management.md @@ -154,14 +154,14 @@ An operator can issue a grant to move a pool to a specific tier: 1. Open the organization's page from the **Organizations** list. 2. In the **Grants** section, click **Issue grant**. The panel opens with a stacked form: one field per row, each label above its field. -3. Choose a **Product**, optionally a **Quantity** and a **Valid until** timestamp, choose a **Reason**, and optionally add a **Note**. A product whose grant would supersede a tier a subscription holds, active or suspended, is marked ⚠ in the **Product** list, and the form's warning says that the subscription keeps billing and delivers nothing on that ladder until the grant ends. +3. Choose a **Product**, optionally a **Quantity** and a **Valid until** timestamp, choose a **Reason**, and optionally add a **Note**. A product whose grant would supersede a tier a subscription holds, active or suspended, is marked ⚠ in the **Product** list, and the form's warning says that the subscription's billing pauses until the grant ends. 4. Tick **Resumes**, whose label sits above its box, when the grant should deliver again after a plan bought or granted over it ends (see [Grants that resume](#grants-that-resume)). It starts unticked, and it is offered for every product, including the organization type's default product. 5. Click **Issue grant**. The system: - Creates a grant with the chosen reason and the resumption mark, then calls the conferral boundary (`internal/entitlements/conferral.go`) through the operator handler in `internal/server/operator_enrollment.go`: it writes the grant decree, confers the position onto the organization's default pool, then materializes the organization's effective entitlements - Registers a **Temporal workflow** to expire the grant at `valid_until` when one is set -- Keeps the ladder for a grant that supersedes a tier a subscription pays for: the subscription delivers nothing there while the grant lasts, and the console pauses its collection at Stripe, and the organization page's Billing card and the subscription's row in the operator's subscriptions list carry a **Not delivering** badge whose title reads "Billing continues while a grant holds {ladder}."; the subscription delivers again at its next reconcile after the grant ends +- Keeps the ladder for a grant that supersedes a tier a subscription pays for: the subscription delivers nothing there while the grant lasts, and the console pauses its collection at Stripe, and the organization page's Billing card and the subscription's row in the operator's subscriptions list carry a **Not delivering** badge whose title reads "Billing paused while a grant holds {ladder}." once Stripe confirms the pause ("grants hold" when several grants hold the ladders) and "Billing continues while a grant holds {ladder}." until it does; the subscription delivers again at its next reconcile after the grant ends While Temporal is not connected, which on a deployment without `temporal-host` is always, a grant with **Valid until** is refused before diff --git a/docs/stripe.md b/docs/stripe.md index 3d23dfbc..7a6862f8 100644 --- a/docs/stripe.md +++ b/docs/stripe.md @@ -211,7 +211,7 @@ A member moves between the paid tiers of a plan ladder on the Products page, and - **Cancellation.** Every paid plan offers **Cancel plan** on its card. Access continues until the end of the paid period (`cancel_at_period_end`), after which the organization moves to its type's default plan, when one is configured, or leaves the ladder. - **Taking a scheduled move back.** While a downgrade or a cancellation is scheduled, the plan's card offers **Keep plan**, which releases the schedule or clears `cancel_at_period_end` at no charge. While a downgrade is scheduled, **Cancel plan** follows it and replaces the downgrade; while a cancellation is scheduled, **Keep plan** is the only control. - **A plan whose payment is due.** A subscription Stripe holds as `past_due` or `unpaid` keeps its card on the Products page, shown as the current plan with its state, while its entitlements are suspended. No switch is offered in either direction and a posted one is refused before any Stripe call, because a switch would invoice while the failed invoice is still open. **Keep plan** and **Cancel plan** at the period end work as on an active plan. A posted immediate cancellation is refused, because Stripe's immediate cancellation stops automatic collection of the customer's finalized invoices, and a **Keep plan** over a downgrade that Stripe has already applied is refused, because there is nothing left to take back. The unpaid invoice stays due after a cancellation: once the cancellation takes effect, Stripe stops retrying that subscription's open invoice and leaves the customer's other subscriptions collecting, so the member pays it through the invoice's **Pay invoice**. A paused subscription shows its state and is refused every act; only a subscription made outside the console reaches `paused`, which follows a trial that ends without a payment method, because the console's Checkout creates no trial. -- **A grant over a paid plan.** An operator's grant over a tier a subscription pays for keeps the ladder until it ends or is revoked, and the subscription delivers nothing there. The console pauses the subscription's collection at Stripe (`pause_collection` with `behavior=void`, and the marker `member_console_collection=paused_for_grant` in the subscription's metadata) within seconds, through the outbox, and sets no `resumes_at`. Each renewal Stripe makes while the grant holds is a draft for about an hour and is then voided, so nothing is charged. When the grant ends, the console clears the pause and the marker, and the tier is delivered again; no money moves at either edge. While the grant holds the ladder, the organization page's Billing card and the subscription's row in the operator's subscriptions list carry a **Not delivering** badge, whose title reads "Billing continues while a grant holds {ladder}." Once only the organization type's default holds the ladder, or nothing does, the subscription's next reconcile delivers its tier again. A new purchase over a grant still replaces the grant. What this accepts until the exact money rule (#280): the renewal date decides which way a grant that is not whole periods falls, because a period's renewal is voided or charged whole; a pause landing after a renewal's finalization lets that renewal be charged, and a clear landing before the finalization of a renewal made while paused lets it be charged; a pause or clear that lands late moves a whole period one way or the other, and a void cannot be undone; the first charge after a grant can come without Stripe's upcoming-renewal reminder. A subscription item with no entitlement set, such as a donation line added in the Dashboard, stops billing with the tier beside it while the pause holds. An invoice open before the grant stays due: Stripe keeps retrying it, and the account's dunning setting can cancel the paused subscription. +- **A grant over a paid plan.** An operator's grant over a tier a subscription pays for keeps the ladder until it ends or is revoked, and the subscription delivers nothing there. The console pauses the subscription's collection at Stripe (`pause_collection` with `behavior=void`, and the marker `member_console_collection=paused_for_grant` in the subscription's metadata) within seconds, through the outbox, and sets no `resumes_at`. Each renewal Stripe makes while the grant holds is a draft for about an hour and is then voided, so nothing is charged. When the grant ends, the console clears the pause and the marker, and the tier is delivered again; no money moves at either edge. While the grant holds the ladder, the organization page's Billing card and the subscription's row in the operator's subscriptions list carry a **Not delivering** badge. Once Stripe confirms the pause, which the subscription row records, its title reads "Billing paused while a grant holds {ladder}." ("grants hold" when several grants hold the ladders); until it does, and while the pause has failed, it reads "Billing continues while a grant holds {ladder}." Once only the organization type's default holds the ladder, or nothing does, the subscription's next reconcile delivers its tier again. A new purchase over a grant still replaces the grant. What this accepts until the exact money rule (#280): the renewal date decides which way a grant that is not whole periods falls, because a period's renewal is voided or charged whole; a pause landing after a renewal's finalization lets that renewal be charged, and a clear landing before the finalization of a renewal made while paused lets it be charged; a pause or clear that lands late moves a whole period one way or the other, and a void cannot be undone; the first charge after a grant can come without Stripe's upcoming-renewal reminder. A subscription item with no entitlement set, such as a donation line added in the Dashboard, stops billing with the tier beside it while the pause holds. An invoice open before the grant stays due: Stripe keeps retrying it, and the account's dunning setting can cancel the paused subscription. - **Pay invoice.** The card of a plan whose payment is due, and the detail of an open invoice, link to Stripe's hosted invoice page. The console reads the page's URL from Stripe when the member opens the link and redirects there; it never stores or logs the URL, which is a bearer link, and it needs no key permission beyond the reads of subscriptions and invoices that the reconciles already make. Paying there makes the new card the customer's default for invoices but leaves the subscription's own default on the card that failed, which Stripe charges first, so the next renewal charges the failed card again. Stripe's page still takes payment for an invoice Stripe has marked uncollectible, which the console shows as open until the invoice sweep reads it again. A restricted key needs permission for the calls these moves make, beyond those the console already uses: `POST /v1/subscription_schedules`, `POST /v1/subscription_schedules/{id}`, `POST /v1/subscription_schedules/{id}/release` and `POST /v1/invoices/{id}/void`. The console also updates a subscription with `POST /v1/subscriptions/{id}` to set `pause_collection` while a grant holds its ladder and to clear it when the grant no longer does, which is the Subscriptions write the plan moves already need. Stripe names the missing permission in the error a key without it receives. diff --git a/internal/embeds/templates/partials/operator_subscriptions.html b/internal/embeds/templates/partials/operator_subscriptions.html index 76f584b4..b5a5a3f2 100644 --- a/internal/embeds/templates/partials/operator_subscriptions.html +++ b/internal/embeds/templates/partials/operator_subscriptions.html @@ -8,7 +8,7 @@ The organization is the row's subject and leads as the row header (chrome-conventions); cancel-at-period-end is an exception marker beside the status, and so is the Not delivering badge of a subscription - that bills while another plan holds its ladder (DisplacementTitle); one + that delivers nothing while another plan holds its ladder (DisplacementTitle); one danger line above the table says the read for it failed (DisplacementError); the always-"Default" billing account name and the truncated ID column are retired (maintainer, 2026-08-30); a diff --git a/internal/server/anatomy.go b/internal/server/anatomy.go index ca33c72b..f5fffaef 100644 --- a/internal/server/anatomy.go +++ b/internal/server/anatomy.go @@ -190,8 +190,9 @@ var badgeMap = map[string]Badge{ "trialing": {Label: "Trialing", Tone: "info"}, "past_due": {Label: "Past due", Tone: "danger"}, "paused": {Label: "Paused", Tone: "secondary"}, - // A subscription that keeps billing while another plan holds one of its - // ladders (displaced-subscription-waits D4); its title says which. + // A subscription that delivers nothing while another plan holds one of its + // ladders (displaced-subscription-waits D4); its title says which, and + // whether its billing is paused (grant-pauses-subscription-billing D16). "not_delivering": {Label: "Not delivering", Tone: "warning"}, // The subscription's own unpaid state, as loud as its past-due state. "subscription_unpaid": {Label: "Unpaid", Tone: "danger"}, diff --git a/internal/server/operator_billing.go b/internal/server/operator_billing.go index bb257062..a9bfaf24 100644 --- a/internal/server/operator_billing.go +++ b/internal/server/operator_billing.go @@ -642,7 +642,7 @@ func (h *OperatorPartialsHandler) subscriptionDisplacementTitles(ctx context.Con func subscriptionTitlesFor(subs []billing.ListSubscriptionsPageRow, items []billing.ListCurrentSubscriptionItemsBySubscriptionIDsRow, shapes []entitlements.ListConferralShapesRow, rows []entitlements.ListSubscriptionDisplacementsBySubscriptionIDsRow) map[string]string { refs := make([]subscriptionRef, len(subs)) for i, s := range subs { - refs[i] = subscriptionRef{ID: s.SubscriptionID, Status: s.Status} + refs[i] = subscriptionRef{ID: s.SubscriptionID, Status: s.Status, PauseBehavior: s.PauseCollectionBehavior.String} } converted := make([]entitlements.ListAccountSubscriptionDisplacementsRow, len(rows)) for i, r := range rows { diff --git a/internal/server/operator_enrollment.go b/internal/server/operator_enrollment.go index 3ff9645a..9370550f 100644 --- a/internal/server/operator_enrollment.go +++ b/internal/server/operator_enrollment.go @@ -309,8 +309,8 @@ var grantReasonDomain = []string{"manual", "evaluation", "promotional", "complim // IssuanceProductOption is one selectable product on the single issuance form // (Doc 41: one form over all published products). Internal wrap products // (is_public=false) render with an "internal" badge; SupersedesSubscription -// flags a product whose position would displace a subscription-held rung (the -// subscription keeps billing — §11.2 residue), surfaced as a non-blocking +// flags a product whose position would displace a subscription-held rung (its +// billing pauses until the grant ends, Copy row W), surfaced as a non-blocking // advisory. type IssuanceProductOption struct { ProductID string @@ -480,20 +480,28 @@ type displacedHolder struct { } // displacedSubscription is one subscription's displaced ladders and the -// positions that hold them. +// positions that hold them. Paused is true when the subscription's recorded +// state has a collection pause and every position that holds one of its +// displaced ladders is a grant (design D16). type displacedSubscription struct { Ladders []displacedLadder Holders []displacedHolder + Paused bool } // displacedOnPage applies the reconcile's rule to a subscription's current // products: every product is taken as missing (a product with a live // provision is on no displaced ladder, design D2), and the ladder of each // displacement the rule picks is named. A displacement whose ladder no -// current product names produces nothing. It reads no row. -func displacedOnPage(products []string, rungs map[string][]entitlements.Rung, displacements []entitlements.Displacement) displacedSubscription { +// current product names produces nothing. pauseBehavior is the subscription +// row's recorded pause behavior, empty when none is recorded; the subscription +// reads as paused when it is set and every displacement picked is held by a +// grant. The record decides "paused", never the rule: a pause Stripe has not +// confirmed does not read as one. It reads no row. +func displacedOnPage(products []string, rungs map[string][]entitlements.Rung, displacements []entitlements.Displacement, pauseBehavior string) displacedSubscription { left := entitlements.DisplacedProducts(products, rungs, displacements) var out displacedSubscription + grantsOnly := true for _, p := range products { d, ok := left[p] if !ok { @@ -501,58 +509,125 @@ func displacedOnPage(products []string, rungs map[string][]entitlements.Rung, di } out.Ladders = append(out.Ladders, displacedLadder{ID: d.LadderID, Name: d.LadderName}) out.Holders = append(out.Holders, displacedHolder{ProvisionID: d.HolderProvisionID, Source: d.HolderSource}) + grantsOnly = grantsOnly && d.HolderSource == "grant" } + out.Paused = len(out.Ladders) > 0 && pauseBehavior != "" && grantsOnly return out } -// displacementTitle builds the Not delivering badge's title (Copy row O2): "" -// when nothing is displaced, "Billing continues while ." for -// an account of one subscription, and "Billing continues on of -// subscriptions while ." otherwise. The ladders are the -// distinct displaced ladders by id, sorted by name, whatever order they -// arrive in; the holder is worded by source when one provision holds every -// ladder. It reads no row. -func displacementTitle(subscriptions int, displaced []displacedSubscription) string { - var ladders []displacedLadder - var holders []displacedHolder +// titleGroup is the distinct ladders and holders of the displaced +// subscriptions of one kind, with how many subscriptions there are. +type titleGroup struct { + count int + ladders []displacedLadder + holders []displacedHolder +} + +// groupDisplaced collects the displaced subscriptions whose Paused equals +// paused. The ladders are distinct by id and sorted by name, then id. +func groupDisplaced(displaced []displacedSubscription, paused bool) titleGroup { + var g titleGroup seenLadder := make(map[string]bool) seenHolder := make(map[string]bool) - count := 0 for _, d := range displaced { - if len(d.Ladders) == 0 { + if len(d.Ladders) == 0 || d.Paused != paused { continue } - count++ + g.count++ for _, l := range d.Ladders { if !seenLadder[l.ID] { seenLadder[l.ID] = true - ladders = append(ladders, l) + g.ladders = append(g.ladders, l) } } for _, h := range d.Holders { if !seenHolder[h.ProvisionID] { seenHolder[h.ProvisionID] = true - holders = append(holders, h) + g.holders = append(g.holders, h) } } } - if count == 0 { - return "" - } - slices.SortFunc(ladders, func(a, b displacedLadder) int { + slices.SortFunc(g.ladders, func(a, b displacedLadder) int { if c := strings.Compare(a.Name, b.Name); c != 0 { return c } return strings.Compare(a.ID, b.ID) }) - names := make([]string, len(ladders)) - for i, l := range ladders { + return g +} + +// names returns the group's ladder names, joined for a sentence. +func (g titleGroup) names() string { + names := make([]string, len(g.ladders)) + for i, l := range g.ladders { names[i] = l.Name } + return joinWithAnd(names) +} + +// pausedSentence is the sentence of Copy rows O0 and O1 for the group; +// subscriptions is the account's count. +func (g titleGroup) pausedSentence(subscriptions int) string { + holder := pausedHolder(g.holders) if subscriptions == 1 { - return "Billing continues while " + displacementHolder(holders) + " " + joinWithAnd(names) + "." + return "Billing paused while " + holder + " " + g.names() + "." } - return fmt.Sprintf("Billing continues on %d of %d subscriptions while %s %s.", count, subscriptions, displacementHolder(holders), joinWithAnd(names)) + return fmt.Sprintf("Billing paused on %d of %d subscriptions while %s %s.", g.count, subscriptions, holder, g.names()) +} + +// continuingSentence is the existing sentence for the group that keeps +// billing: alone it is the whole title, after a paused sentence (Copy row O2) +// it counts only its own subscriptions. +func (g titleGroup) continuingSentence(subscriptions int, afterPaused bool) string { + holder := displacementHolder(g.holders) + switch { + case subscriptions == 1: + return "Billing continues while " + holder + " " + g.names() + "." + case afterPaused: + return fmt.Sprintf("Billing continues on %d while %s %s.", g.count, holder, g.names()) + } + return fmt.Sprintf("Billing continues on %d of %d subscriptions while %s %s.", g.count, subscriptions, holder, g.names()) +} + +// displacementTitle builds the Not delivering badge's title (Copy rows O0 to +// O2 and the existing forms): "" when nothing is displaced. It splits the +// displaced subscriptions into paused and not, builds each part's ladders and +// holder, and joins the paused sentence and the continuing sentence with one +// space. The three forms, for an account of one subscription ("while" without +// a count) and of several: +// +// Billing paused while . +// Billing paused on of subscriptions while . +// Billing paused on of subscriptions while . Billing continues on while . +// +// and, with nothing paused, the existing "Billing continues while +// ." and "Billing continues on of subscriptions while +// .". A paused sentence's holder is "a grant holds" when one +// grant provision holds every ladder it names and "grants hold" when several +// do, counted by provision (displacementHolder counts the same way). The +// recorded pause, never the rule, decides "paused" (displacedOnPage). It reads +// no row. +func displacementTitle(subscriptions int, displaced []displacedSubscription) string { + paused := groupDisplaced(displaced, true) + continuing := groupDisplaced(displaced, false) + var sentences []string + if paused.count > 0 { + sentences = append(sentences, paused.pausedSentence(subscriptions)) + } + if continuing.count > 0 { + sentences = append(sentences, continuing.continuingSentence(subscriptions, paused.count > 0)) + } + return strings.Join(sentences, " ") +} + +// pausedHolder words the holders of a paused subscription's displaced +// ladders, which are all grants: "a grant holds" for one provision, "grants +// hold" for several. +func pausedHolder(holders []displacedHolder) string { + if len(holders) == 1 { + return "a grant holds" + } + return "grants hold" } // displacementHolder words the holders of the displaced ladders: by source @@ -1801,6 +1876,9 @@ func (h *OperatorPartialsHandler) accountDisplacementTitle(r *http.Request, acco type subscriptionRef struct { ID string Status string + // PauseBehavior is the row's recorded collection pause behavior, empty + // when Stripe reported none. + PauseBehavior string } // displacedByID applies the reconcile's rule to each subscription whose @@ -1814,7 +1892,7 @@ func displacedByID(subs []subscriptionRef, products map[string][]string, rungs m if !subscriptionMayBeDisplaced(s.Status) { continue } - if d := displacedOnPage(products[s.ID], rungs, displacements[s.ID]); len(d.Ladders) > 0 { + if d := displacedOnPage(products[s.ID], rungs, displacements[s.ID], s.PauseBehavior); len(d.Ladders) > 0 { out[s.ID] = d } } @@ -1860,7 +1938,7 @@ func productsBySubscription[R itemRow](items []R) map[string][]string { func displacementTitleFor(subs []billing.Subscription, items []billing.ListCurrentSubscriptionItemsByBillingAccountIDRow, shapes []entitlements.ListConferralShapesRow, rows []entitlements.ListAccountSubscriptionDisplacementsRow) string { refs := make([]subscriptionRef, len(subs)) for i, s := range subs { - refs[i] = subscriptionRef{ID: s.SubscriptionID, Status: s.Status} + refs[i] = subscriptionRef{ID: s.SubscriptionID, Status: s.Status, PauseBehavior: s.PauseCollectionBehavior.String} } byID := displacedByID(refs, productsBySubscription(items), entitlements.RungsByProduct(shapes), displacementsBySubscription(rows)) var displaced []displacedSubscription @@ -2077,11 +2155,9 @@ func (h *OperatorPartialsHandler) productsOnLadders(r *http.Request, ladders map // subscriptionHeldLadders returns the set of plan ladders currently occupied by // a subscription-sourced provision, active or suspended, on any of the org's // pools. The issuance form uses it to advise (non-blocking) when a grant would -// supersede a subscription-held rung — the subscription keeps billing (§11.2 -// residue). Pure read; best-effort: a pool whose positions fail to read is +// supersede a subscription-held rung. Pure read; best-effort: a pool whose positions fail to read is // skipped, not surfaced. A suspended position is held: core.confer supersedes -// it as it does an active one, and the subscription keeps billing in Stripe, -// or bills again once a paused one resumes. +// it as it does an active one. func (h *OperatorPartialsHandler) subscriptionHeldLadders(r *http.Request, pools []entitlements.ResourcePool) map[string]bool { held := map[string]bool{} for _, pool := range pools { diff --git a/internal/server/operator_enrollment_forms.go b/internal/server/operator_enrollment_forms.go index 9ee7c8ab..5e77a685 100644 --- a/internal/server/operator_enrollment_forms.go +++ b/internal/server/operator_enrollment_forms.go @@ -130,8 +130,12 @@ const issueGrantLead = "A tier product moves the pool to that tier, up or down." // issueGrantSupersedeWarning follows the lead when a product the select // offers is marked with the supersession marker. The sentence states what the // grant does to the subscription and names no view, because the operator's -// billing views only read (displaced-subscription-waits D4, Copy row O5). -const issueGrantSupersedeWarning = "Products marked ⚠ would supersede a tier a subscription pays for; the subscription keeps billing and delivers nothing on that ladder until the grant ends." +// billing views only read (displaced-subscription-waits D4). The sentence is +// grant-pauses-subscription-billing Copy row W. The grant pauses the subscription's +// billing because the console pauses collection at Stripe while a grant holds +// every ladder the subscription pays for, so the subscription is not charged +// for a period the grant covers. +const issueGrantSupersedeWarning = "Products marked ⚠ would supersede a tier a subscription pays for; its billing pauses until the grant ends." // manageGrantForm is the declaration for Manage (grant-resumption D15): // everything about a grant that can change after issue, with the fields the diff --git a/internal/server/operator_enrollment_golden_db_test.go b/internal/server/operator_enrollment_golden_db_test.go index 31406f06..600c886f 100644 --- a/internal/server/operator_enrollment_golden_db_test.go +++ b/internal/server/operator_enrollment_golden_db_test.go @@ -222,6 +222,13 @@ func newEnrollmentFixture(t *testing.T) *enrollmentFixture { f.grant("Small2", w.Issue(o, small2, world.IssueOpts{})) add("grant-over-subscription", o.ID, "") + o = f.org("grant-over-subscription-paused", plain) + sub = w.Subscribe(o, world.SubOpts{PeriodEnd: noon(2099, time.January, 15)}, small2) + f.norm.Name("subscription", "grant-over-paused", sub.ID) + w.PauseCollection(sub) + f.grant("Small2", w.Issue(o, small2, world.IssueOpts{})) + add("grant-over-subscription-paused", o.ID, "") + lite2 := f.product("Lite2") f.ladder("Cycle", lite2) o = f.org("many-changes", plain) diff --git a/internal/server/operator_enrollment_render_test.go b/internal/server/operator_enrollment_render_test.go index 771d6049..8d8d6582 100644 --- a/internal/server/operator_enrollment_render_test.go +++ b/internal/server/operator_enrollment_render_test.go @@ -501,6 +501,10 @@ func TestOrgEnrollmentIssueGrantPanel_TerseCopy(t *testing.T) { } } +// supersedeWarningCopy is Copy row W of grant-pauses-subscription-billing, the +// whole sentence the Issue grant form's warning reads. +const supersedeWarningCopy = "Products marked ⚠ would supersede a tier a subscription pays for; its billing pauses until the grant ends." + // TestOrgEnrollmentIssueGrantPanel_Stacked covers grant-resumption D21: // Issue grant is a stacked form in its panel, the form part's own box at the // readable measure, one field per row with its label above, the lead above @@ -549,8 +553,9 @@ func TestOrgEnrollmentIssueGrantPanel_Stacked(t *testing.T) { data.IssuanceProducts = append(data.IssuanceProducts, IssuanceProductOption{ProductID: "prod-pro", Name: "Pro", SupersedesSubscription: true}) data.IssueGrantForm = issueGrantFormView(data.OrgID, data.IssuanceProducts, forms.ModeRecord, forms.NewValues(), nil, "") warned := renderOrgEnrollment(t, data) - if !strings.Contains(warned, `A tier product moves the pool to that tier, up or down.`) { - t.Errorf("the supersession warning does not follow the lead:\n%s", warned) + wantWarning := `A tier product moves the pool to that tier, up or down.` + if !strings.Contains(warned, wantWarning) { + t.Errorf("the stacked Issue grant panel lacks %q:\n%s", wantWarning, warned) } } @@ -700,8 +705,8 @@ func TestOrgEnrollmentProductsSection(t *testing.T) { if !strings.Contains(out, "Standard Plan ⚠") { t.Error("expected the ⚠ marker on superseding product options") } - if !strings.Contains(out, "supersede a tier a subscription pays for") { - t.Error("expected the supersession advisory when a ⚠ option is present") + if !strings.Contains(out, ">"+supersedeWarningCopy+"<") { + t.Errorf("the products section lacks the supersession warning %q when a ⚠ option is present", supersedeWarningCopy) } }) } @@ -1292,6 +1297,13 @@ func displacedOn(holder displacedHolder, ladders ...displacedLadder) displacedSu return d } +// pausedOn is displacedOn for a subscription whose pause is recorded. +func pausedOn(holder displacedHolder, ladders ...displacedLadder) displacedSubscription { + d := displacedOn(holder, ladders...) + d.Paused = true + return d +} + type displacementTitleRow struct { name string subscriptions int @@ -1303,6 +1315,8 @@ func displacementTitleRows() []displacementTitleRow { hosting := displacedLadder{ID: "l-hosting", Name: "Hosting"} support := displacedLadder{ID: "l-support", Name: "Support"} docs := displacedLadder{ID: "l-docs", Name: "Docs"} + wiki := displacedLadder{ID: "l-wiki", Name: "Wiki"} + demoLadder := displacedLadder{ID: "l-demo", Name: "Demo Ladder"} grant := displacedHolder{ProvisionID: "p-grant", Source: "grant"} other := displacedHolder{ProvisionID: "p-other", Source: "grant"} sub := displacedHolder{ProvisionID: "p-sub", Source: "subscription"} @@ -1326,11 +1340,36 @@ func displacementTitleRows() []displacementTitleRow { displacedOn(grant, hosting), displacedOn(grant, hosting), }, "Billing continues on 2 of 3 subscriptions while a grant holds Hosting."}, {"nothing displaced", 2, nil, ""}, + {"one subscription, paused", 1, []displacedSubscription{pausedOn(grant, demoLadder)}, "Billing paused while a grant holds Demo Ladder."}, + {"one subscription, pause not confirmed", 1, []displacedSubscription{displacedOn(grant, demoLadder)}, "Billing continues while a grant holds Demo Ladder."}, + {"three subscriptions, two paused", 3, []displacedSubscription{ + pausedOn(grant, hosting), pausedOn(grant, hosting), + }, "Billing paused on 2 of 3 subscriptions while a grant holds Hosting."}, + {"three subscriptions, one paused, one continuing under another subscription", 3, []displacedSubscription{ + pausedOn(grant, hosting), displacedOn(sub, wiki), + }, "Billing paused on 1 of 3 subscriptions while a grant holds Hosting. Billing continues on 1 while another subscription holds Wiki."}, + {"three subscriptions, the continuing one listed first", 3, []displacedSubscription{ + displacedOn(sub, wiki), pausedOn(grant, hosting), + }, "Billing paused on 1 of 3 subscriptions while a grant holds Hosting. Billing continues on 1 while another subscription holds Wiki."}, + {"one subscription, paused under two grants", 1, []displacedSubscription{{ + Ladders: []displacedLadder{hosting, wiki}, + Holders: []displacedHolder{grant, other}, + Paused: true, + }}, "Billing paused while grants hold Hosting and Wiki."}, + {"one subscription, paused under one bundle grant on two ladders", 1, []displacedSubscription{pausedOn(grant, hosting, wiki)}, "Billing paused while a grant holds Hosting and Wiki."}, + {"three subscriptions, two paused under two grants", 3, []displacedSubscription{ + pausedOn(grant, hosting), pausedOn(other, wiki), + }, "Billing paused on 2 of 3 subscriptions while grants hold Hosting and Wiki."}, + {"paused but held by a purchase", 1, []displacedSubscription{displacedOnPage([]string{"tier"}, + map[string][]entitlements.Rung{"tier": {{LadderID: "l-hosting", Rank: 1}}}, + []entitlements.Displacement{{LadderID: "l-hosting", LadderName: "Hosting", HolderProvisionID: "p-purchase", HolderSource: "purchase"}}, + "void")}, "Billing continues while another plan holds Hosting."}, } } // TestDisplacementTitle compares every form of the Not delivering badge's -// title (displaced-subscription-waits, Copy row O2) with its whole sentence. +// title (displaced-subscription-waits Copy row O2, grant-pauses-subscription-billing +// Copy rows O0 to O2) with its whole sentence. func TestDisplacementTitle(t *testing.T) { for _, tc := range displacementTitleRows() { t.Run(tc.name, func(t *testing.T) { @@ -1343,6 +1382,7 @@ func TestDisplacementTitle(t *testing.T) { type displacedOnPageRow struct { name string + behavior string products []string rungs map[string][]entitlements.Rung displacements []entitlements.Displacement @@ -1356,22 +1396,34 @@ func displacedOnPageRows() []displacedOnPageRow { hosting := displacedLadder{ID: "l-hosting", Name: "Hosting"} grant := displacedHolder{ProvisionID: "p-grant", Source: "grant"} return []displacedOnPageRow{ - {"a displacement on a ladder a current product names", + {"a displacement on a ladder a current product names", "", []string{"tier"}, map[string][]entitlements.Rung{"tier": {{LadderID: "l-hosting", Rank: 1}}}, []entitlements.Displacement{held("l-hosting", "Hosting")}, displacedSubscription{Ladders: []displacedLadder{hosting}, Holders: []displacedHolder{grant}}}, - {"the item moved off the ladder", + {"the item moved off the ladder", "", []string{"other"}, map[string][]entitlements.Rung{"other": {{LadderID: "l-support", Rank: 1}}}, []entitlements.Displacement{held("l-hosting", "Hosting")}, displacedSubscription{}}, - {"the item removed", + {"the item removed", "", nil, map[string][]entitlements.Rung{"tier": {{LadderID: "l-hosting", Rank: 1}}}, []entitlements.Displacement{held("l-hosting", "Hosting")}, displacedSubscription{}}, - {"a bundle displaced on one ladder", + {"a bundle displaced on one ladder", "", []string{"bundle"}, map[string][]entitlements.Rung{"bundle": {{LadderID: "l-hosting", Rank: 1}, {LadderID: "l-support", Rank: 1}}}, []entitlements.Displacement{held("l-support", "Support")}, displacedSubscription{Ladders: []displacedLadder{{ID: "l-support", Name: "Support"}}, Holders: []displacedHolder{grant}}}, + {"a recorded pause under grants", "void", + []string{"tier"}, map[string][]entitlements.Rung{"tier": {{LadderID: "l-hosting", Rank: 1}}}, + []entitlements.Displacement{held("l-hosting", "Hosting")}, + displacedSubscription{Ladders: []displacedLadder{hosting}, Holders: []displacedHolder{grant}, Paused: true}}, + {"a recorded foreign pause under grants", "mark_uncollectible", + []string{"tier"}, map[string][]entitlements.Rung{"tier": {{LadderID: "l-hosting", Rank: 1}}}, + []entitlements.Displacement{held("l-hosting", "Hosting")}, + displacedSubscription{Ladders: []displacedLadder{hosting}, Holders: []displacedHolder{grant}, Paused: true}}, + {"a recorded pause under a subscription", "void", + []string{"tier"}, map[string][]entitlements.Rung{"tier": {{LadderID: "l-hosting", Rank: 1}}}, + []entitlements.Displacement{{LadderID: "l-hosting", LadderName: "Hosting", HolderProvisionID: "p-sub", HolderSource: "subscription"}}, + displacedSubscription{Ladders: []displacedLadder{hosting}, Holders: []displacedHolder{{ProvisionID: "p-sub", Source: "subscription"}}}}, } } @@ -1381,7 +1433,7 @@ func displacedOnPageRows() []displacedOnPageRow { func TestDisplacedOnPage(t *testing.T) { for _, tc := range displacedOnPageRows() { t.Run(tc.name, func(t *testing.T) { - if got := displacedOnPage(tc.products, tc.rungs, tc.displacements); !reflect.DeepEqual(got, tc.want) { + if got := displacedOnPage(tc.products, tc.rungs, tc.displacements, tc.behavior); !reflect.DeepEqual(got, tc.want) { t.Errorf("displacedOnPage(%s) = %+v, want %+v", tc.name, got, tc.want) } }) @@ -1480,6 +1532,11 @@ func subscriptionTitlesRows() []subscriptionTitlesRow { sub := func(id, status string) billing.ListSubscriptionsPageRow { return billing.ListSubscriptionsPageRow{SubscriptionID: id, Status: status} } + paused := func(id string) billing.ListSubscriptionsPageRow { + row := sub(id, "active") + row.PauseCollectionBehavior = sql.NullString{String: "void", Valid: true} + return row + } hosting, docs := displacementTitleForLadder, displacementTitleForLadder2 return []subscriptionTitlesRow{ {"a canceled subscription has no badge", []billing.ListSubscriptionsPageRow{sub("s1", "canceled")}, @@ -1491,6 +1548,13 @@ func subscriptionTitlesRows() []subscriptionTitlesRow { "s1": "Billing continues while a grant holds Hosting.", "s2": "Billing continues while another subscription holds Docs.", }}, + {"a paused row", []billing.ListSubscriptionsPageRow{paused("s1"), sub("s2", "active")}, + []entitlements.ListSubscriptionDisplacementsBySubscriptionIDsRow{ + displaced("s1", hosting, "Hosting", "grant"), displaced("s2", docs, "Docs", "grant"), + }, map[string]string{ + "s1": "Billing paused while a grant holds Hosting.", + "s2": "Billing continues while a grant holds Docs.", + }}, {"a delivering row has no badge", []billing.ListSubscriptionsPageRow{sub("s1", "active"), sub("s2", "active")}, []entitlements.ListSubscriptionDisplacementsBySubscriptionIDsRow{displaced("s1", hosting, "Hosting", "grant")}, map[string]string{"s1": "Billing continues while a grant holds Hosting."}}, diff --git a/internal/server/operator_subscriptions_displacement_db_test.go b/internal/server/operator_subscriptions_displacement_db_test.go index 2c980752..b17de7f5 100644 --- a/internal/server/operator_subscriptions_displacement_db_test.go +++ b/internal/server/operator_subscriptions_displacement_db_test.go @@ -21,6 +21,7 @@ type displacedListFixture struct { orgA, orgB world.Org subA, subB world.Subscription title string + ladder string } // newDisplacedListFixture builds the state the grant-over-subscription @@ -39,6 +40,7 @@ func newDisplacedListFixture(t *testing.T) displacedListFixture { f.subA = w.Subscribe(f.orgA, world.SubOpts{}, small) w.MapSubscription(f.subA) w.Issue(f.orgA, small, world.IssueOpts{}) + f.ladder = box.Name f.title = "Billing continues while a grant holds " + box.Name + "." f.orgB = w.Org("Delivering", w.OrgType("boxb"), w.Person("Owner B")) @@ -100,6 +102,26 @@ func TestSubscriptionsListMarksADisplacedSubscription(t *testing.T) { } } +// TestSubscriptionsListMarksAPausedSubscription pins that a displaced +// subscription whose row records a collection pause reads Copy row O0 in the +// list, and one without the record keeps the existing title. +func TestSubscriptionsListMarksAPausedSubscription(t *testing.T) { + f := newDisplacedListFixture(t) + wantContinuing := f.title + wantPaused := "Billing paused while a grant holds " + f.ladder + "." + + before, _ := f.list(t, catalogReadsConfig(f.w)) + if got, _ := titleOf(before, f.subA.ID); got != wantContinuing { + t.Errorf("subscriptions list title = %q, want %q", got, wantContinuing) + } + + f.w.PauseCollection(f.subA) + after, _ := f.list(t, catalogReadsConfig(f.w)) + if got, _ := titleOf(after, f.subA.ID); got != wantPaused { + t.Errorf("subscriptions list title = %q, want %q", got, wantPaused) + } +} + type subscriptionsListReadFailure struct { name, querier, method string } diff --git a/internal/server/testdata/org_enrollment/grant-over-subscription-paused.html b/internal/server/testdata/org_enrollment/grant-over-subscription-paused.html new file mode 100644 index 00000000..51e3e857 --- /dev/null +++ b/internal/server/testdata/org_enrollment/grant-over-subscription-paused.html @@ -0,0 +1,523 @@ + + +
+
+ +

grant-over-subscription-paused

+ +
+ + +
+ + +
+
+
+
Owner
+
+ + Ann + +
+ + +
+
+
+ + +
+

Billing

+ + Full billing +
+
+
+ + +
+ +
+
Outstanding balance
+ +
0.00
+ +
+
+
Subscriptions
+ +
+ Active + Not delivering, Billing paused while a grant holds Box. + 1 subscription + + · renews Jan 15, 2099 + +
+ +
+
+
Latest invoice
+ +
No invoices issued
+ +
+
+ +
+
+ + +
+

Pools

+ + +
+ + +
+
+
+
+

+ Default Active +

+ + +
+
+ + +
+

Small2

+

+ Box, rank 0 +

+
+ + +
+
+ + + + + + +
+

Grants

+ + +
+ +
+
+
+ + + +
+ + + + +
+
+
+ + +
+ + +
+
+ + +
A tier product moves the pool to that tier, up or down.
+ + + +
+
+ + + + + + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + +
+ + + + + + +
+
+
+ + + + + + + +
+ +
+
+ + +
+ + +
+ + + + + + + + + + +
+ + +
+ + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ProductReasonIssuance Delivery Resumes Granted byQtyActivatedValid untilActions
Small2complimentaryActiveLiveNoAnn1— + +
+
+ + + + + + +
+ + +
+ + + +
+

Showing 1–1 of 1

+ +

Per page: + + 10 + + 25 + + 50 + +

+ + +
+ + + +
+
+
+ + +
+

Members

+ + +
+
+
+ + + + +
+

No members.

+ + +
+ + + +
+
+ + + +
+

Entitlement changes

+ + +
+ +
+
+
+ + + + +
+

No entitlement changes recorded yet.

+ + +
+ + + +
+
+
+ + + +
+

Tier changes

+ + +
+ +
+
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LadderChangeFromToByReasonWhen
BoxTransferred, Same tier, different funding source: another grant or subscription took over this placement.Small2Small2 + Ann + Complimentary
BoxStarted—Small2 + webhook + test fixture
+
+ + +
+

Showing 1–2 of 2

+ +

Per page: + + 10 + + 25 + + 50 + +

+ + +
+ + + +
+
+
+ + + + diff --git a/internal/server/testdata/org_enrollment/grant-over-subscription-paused.json b/internal/server/testdata/org_enrollment/grant-over-subscription-paused.json new file mode 100644 index 00000000..b96a615f --- /dev/null +++ b/internal/server/testdata/org_enrollment/grant-over-subscription-paused.json @@ -0,0 +1,278 @@ +{ + "ActionError": "", + "BillingSummary": { + "HasAccount": true, + "BillingAccountID": "", + "AccountStatus": "active", + "SubscriptionCount": 1, + "SubscriptionState": "active", + "SubscriptionNote": "renews Jan 15, 2099", + "DisplacementTitle": "Billing paused while a grant holds Box.", + "DisplacementError": "", + "HasInvoice": false, + "LatestInvoiceID": "", + "LatestInvoiceNumber": "", + "LatestInvoiceDate": "", + "InvoiceState": "", + "OutstandingBalance": 0, + "OutstandingBalanceFormatted": "0.00", + "Currency": "" + }, + "EntitlementChanges": [], + "EntitlementChangesError": "", + "EntitlementChangesNav": { + "BasePath": "/operator/organizations/", + "SearchPlaceholder": "", + "FacetParam": "", + "FacetOptions": null, + "Q": "", + "Facet": "", + "Page": 1, + "Total": 0, + "ParamPrefix": "ec_", + "Extra": {}, + "PerPage": 10, + "DefaultPerPage": 10, + "PerPageOptions": [ + 10, + 25, + 50 + ], + "Target": "#entitlement-changes-panel", + "SyncSelect": "#plan-grants-panel,#tier-changes-panel" + }, + "EntitlementChangesTotal": 0, + "Error": "", + "GrantsError": "", + "GrantsListQuery": "", + "GrantsNav": { + "BasePath": "/operator/organizations/", + "SearchPlaceholder": "Product or reason", + "FacetParam": "tab", + "FacetOptions": [ + { + "Value": "", + "Label": "Active" + }, + { + "Value": "history", + "Label": "History" + } + ], + "Q": "", + "Facet": "", + "Page": 1, + "Total": 1, + "ParamPrefix": "", + "Extra": {}, + "PerPage": 10, + "DefaultPerPage": 10, + "PerPageOptions": [ + 10, + 25, + 50 + ], + "Target": "#plan-grants-panel", + "SyncSelect": "#tier-changes-panel,#entitlement-changes-panel" + }, + "GrantsTotal": 1, + "IssuanceProducts": [ + { + "ProductID": "", + "Name": "Basic", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Forum", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Forum2", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Large", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Lite", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Lite2", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Mid", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Plus", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Pro", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Small", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Small2", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Starter", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Starter2", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + }, + { + "ProductID": "", + "Name": "Top", + "IsInternal": false, + "DisplayCategory": "", + "SupersedesSubscription": false + } + ], + "Members": [], + "MembersCapped": false, + "MembersError": "", + "MembersTotal": 0, + "OrgID": "", + "OrgKey": "", + "OrgName": "grant-over-subscription-paused", + "OrgOwnerName": "Ann", + "OrgOwnerPersonID": "", + "PoolMissing": false, + "Pools": [ + { + "PoolID": "", + "PoolName": "Default", + "PoolType": "default", + "Status": "active", + "Deliveries": [ + { + "ProvisionID": "", + "ProductName": "Small2", + "ProductID": "", + "Rungs": [ + { + "LadderName": "Box", + "Rank": 0, + "ActivatedAt": " " + } + ], + "Suspended": false + } + ], + "Usage": null, + "HasAttachment": true + } + ], + "ProductsError": "", + "TierChangesNav": { + "BasePath": "/operator/organizations/", + "SearchPlaceholder": "", + "FacetParam": "", + "FacetOptions": null, + "Q": "", + "Facet": "", + "Page": 1, + "Total": 2, + "ParamPrefix": "tc_", + "Extra": {}, + "PerPage": 10, + "DefaultPerPage": 10, + "PerPageOptions": [ + 10, + 25, + 50 + ], + "Target": "#tier-changes-panel", + "SyncSelect": "#plan-grants-panel,#entitlement-changes-panel" + }, + "Transitions": [ + { + "TransitionID": "", + "TransitionType": "transfer", + "LadderName": "Box", + "ChangeLabel": "Transferred", + "ChangeTooltip": "Same tier, different funding source: another grant or subscription took over this placement.", + "ChangeKind": "", + "FromLabel": "Small2", + "ToLabel": "Small2", + "ActorType": "operator", + "ActorName": "Ann", + "ReasonLabel": "Complimentary", + "ReasonNote": "", + "ReasonRaw": "test fixture", + "EffectiveAt": { + "Date": "", + "Time": "" + } + }, + { + "TransitionID": "", + "TransitionType": "initiate", + "LadderName": "Box", + "ChangeLabel": "Started", + "ChangeTooltip": "", + "ChangeKind": "", + "FromLabel": "—", + "ToLabel": "Small2", + "ActorType": "webhook", + "ActorName": "", + "ReasonLabel": "test fixture", + "ReasonNote": "", + "ReasonRaw": "test fixture", + "EffectiveAt": { + "Date": "", + "Time": "" + } + } + ], + "TransitionsError": "", + "TransitionsTotal": 2 +} diff --git a/internal/server/testdata/org_enrollment/rich-history-search.html b/internal/server/testdata/org_enrollment/rich-history-search.html index ccbd970a..6875afea 100644 --- a/internal/server/testdata/org_enrollment/rich-history-search.html +++ b/internal/server/testdata/org_enrollment/rich-history-search.html @@ -185,7 +185,7 @@
-
A tier product moves the pool to that tier, up or down.
+
A tier product moves the pool to that tier, up or down.
diff --git a/internal/server/testdata/org_enrollment/rich.html b/internal/server/testdata/org_enrollment/rich.html index c472f8bf..cf2a1579 100644 --- a/internal/server/testdata/org_enrollment/rich.html +++ b/internal/server/testdata/org_enrollment/rich.html @@ -185,7 +185,7 @@ -
A tier product moves the pool to that tier, up or down.
+
A tier product moves the pool to that tier, up or down.
diff --git a/internal/server/testdata/org_enrollment/suspended-subscription.html b/internal/server/testdata/org_enrollment/suspended-subscription.html index 4292ac1e..0da4d73a 100644 --- a/internal/server/testdata/org_enrollment/suspended-subscription.html +++ b/internal/server/testdata/org_enrollment/suspended-subscription.html @@ -140,7 +140,7 @@ -
A tier product moves the pool to that tier, up or down.
+
A tier product moves the pool to that tier, up or down.
diff --git a/openspec/changes/grant-pauses-subscription-billing/tasks.md b/openspec/changes/grant-pauses-subscription-billing/tasks.md index 88945511..cd141ff6 100644 --- a/openspec/changes/grant-pauses-subscription-billing/tasks.md +++ b/openspec/changes/grant-pauses-subscription-billing/tasks.md @@ -102,11 +102,11 @@ Sections 1 to 12 are one commit each, and their items are that commit's parts; s ## 5. The operator reads the confirmed pause -- [ ] 5.1 `internal/server/operator_enrollment.go` (design D16): `subscriptionRef` gains `PauseBehavior string` from the row; `displacedSubscription` gains `Paused bool`; `displacedOnPage` (`operator_enrollment.go:495`, whose signature gains the behavior) sets it when the ref's behavior is set and every displacement it picked has `HolderSource == "grant"`. The organization page's subscription read and `ListSubscriptionsPage` carry the behavior (section 2's column). -- [ ] 5.2 `displacementTitle(subscriptions int, displaced []displacedSubscription) string` builds the titles of Copy O0, O1, O2 and the existing forms: it splits the displaced subscriptions into paused and not, builds each part's ladders and holder as today, and joins the paused sentence and the continuing sentence with one space; one subscription on the account gives the one-subscription forms. The paused sentence's holder is "a grant holds" when one grant provision holds every ladder it names and "grants hold" when several do, counted by provision as `displacementHolder` counts (design D16). Its doc comment states the three forms, the two holder forms, and that the record, never the rule, decides "paused". -- [ ] 5.3 `subscriptionTitlesFor` (`internal/server/operator_billing.go:643`) passes the row's behavior, so a row reads O0 or the existing one-subscription form. -- [ ] 5.4 `internal/server/operator_enrollment_forms.go:130-134`: `issueGrantSupersedeWarning` reads Copy W, and its comment says why the grant pauses the subscription's billing. -- [ ] 5.5 Tests: +- [x] 5.1 `internal/server/operator_enrollment.go` (design D16): `subscriptionRef` gains `PauseBehavior string` from the row; `displacedSubscription` gains `Paused bool`; `displacedOnPage` (`operator_enrollment.go:495`, whose signature gains the behavior) sets it when the ref's behavior is set and every displacement it picked has `HolderSource == "grant"`. The organization page's subscription read and `ListSubscriptionsPage` carry the behavior (section 2's column). +- [x] 5.2 `displacementTitle(subscriptions int, displaced []displacedSubscription) string` builds the titles of Copy O0, O1, O2 and the existing forms: it splits the displaced subscriptions into paused and not, builds each part's ladders and holder as today, and joins the paused sentence and the continuing sentence with one space; one subscription on the account gives the one-subscription forms. The paused sentence's holder is "a grant holds" when one grant provision holds every ladder it names and "grants hold" when several do, counted by provision as `displacementHolder` counts (design D16). Its doc comment states the three forms, the two holder forms, and that the record, never the rule, decides "paused". +- [x] 5.3 `subscriptionTitlesFor` (`internal/server/operator_billing.go:643`) passes the row's behavior, so a row reads O0 or the existing one-subscription form. +- [x] 5.4 `internal/server/operator_enrollment_forms.go:130-134`: `issueGrantSupersedeWarning` reads Copy W, and its comment says why the grant pauses the subscription's billing. +- [x] 5.5 Tests: - `TestDisplacementTitle` (`internal/server/operator_enrollment_render_test.go:1335`), rows added to `displacementTitleRows`: `one subscription, paused` (O0, "Billing paused while a grant holds Demo Ladder."); `one subscription, pause not confirmed` (the existing form); `three subscriptions, two paused` (O1); `three subscriptions, one paused, one continuing under another subscription` (O2, "Billing paused on 1 of 3 subscriptions while a grant holds Hosting. Billing continues on 1 while another subscription holds Wiki."); `one subscription, paused under two grants` (O0, "Billing paused while grants hold Hosting and Wiki."); `one subscription, paused under one bundle grant on two ladders` (O0, "Billing paused while a grant holds Hosting and Wiki."); `three subscriptions, two paused under two grants` (O1, "Billing paused on 2 of 3 subscriptions while grants hold Hosting and Wiki."); `paused but held by a purchase` (the existing form). Failure text unchanged: `displacementTitle(%s) = %q, want %q`. - `TestDisplacedOnPage` rows: `a recorded pause under grants` (Paused true), `a recorded foreign pause under grants` (the behavior set by `ForeignPause`, Paused true), `a recorded pause under a subscription` (Paused false). Failure text unchanged. - `TestSubscriptionTitlesFor` rows: `a paused row` reads O0. Failure text unchanged. @@ -115,9 +115,9 @@ Sections 1 to 12 are one commit each, and their items are that commit's parts; s - `TestOrgEnrollmentGolden`: the three states whose Issue grant panel shows the warning, `internal/server/testdata/org_enrollment/rich.html`, `rich-history-search.html` and `suspended-subscription.html`, rewritten with `-update` and read: each changes only in the warning's sentence, which reads Copy W. Their `.json` files do not change, because the view model does not carry the warning's text. - `TestSubscriptionsListMarksAPausedSubscription` (`internal/server/operator_subscriptions_displacement_db_test.go`): a displaced subscription from the kit with `PauseCollection` titles O0, and one without it the existing title. Failure text: `subscriptions list title = %q, want %q`. - `TestOperatorPagesReadAFixedNumberOfTimes` passes unedited. -- [ ] 5.6 No other golden changes: the subscriptions page's goldens (`internal/server/testdata/operator_billing/subscriptions-all.json` and `subscriptions-default.json`) serialize `SubscriptionViewModel` (`internal/server/operator_billing.go:431`), which gains no field, and their fixture holds no paused subscription; no other organization page state records a pause. Any other change is a stop. -- [ ] 5.7 Docs: `docs/stripe.md`'s grant bullet names the badge's paused title, "Billing paused while a grant holds {ladder}." ("grants hold" when several grants hold the ladders), once Stripe confirms the pause, and the existing title while it does not; `docs/plan-management.md:157` and `:164` (the grant over a paid plan and the badge) read the same. -- [ ] 5.8 Breaks: +- [x] 5.6 No other golden changes: the subscriptions page's goldens (`internal/server/testdata/operator_billing/subscriptions-all.json` and `subscriptions-default.json`) serialize `SubscriptionViewModel` (`internal/server/operator_billing.go:431`), which gains no field, and their fixture holds no paused subscription; no other organization page state records a pause. Any other change is a stop. +- [x] 5.7 Docs: `docs/stripe.md`'s grant bullet names the badge's paused title, "Billing paused while a grant holds {ladder}." ("grants hold" when several grants hold the ladders), once Stripe confirms the pause, and the existing title while it does not; `docs/plan-management.md:157` and `:164` (the grant over a paid plan and the badge) read the same. +- [x] 5.8 Breaks: - the record ignored (`Paused` forced false in `displacedOnPage`): caught by `TestDisplacedOnPage`, `want_new` `displacedOnPage(a recorded pause under grants) =`, and by `TestOrgEnrollmentGolden/grant-over-subscription-paused`, `want_new` `testdata/org_enrollment/grant-over-subscription-paused.html differs from what the code produced`; - the holder test dropped (a pause under a subscription reads paused): caught by `TestDisplacedOnPage`, `want_new` `displacedOnPage(a recorded pause under a subscription) =`; - the mixed form's second sentence dropped: caught by `TestDisplacementTitle`, `want_new` `displacementTitle(three subscriptions, one paused, one continuing under another subscription) =`; @@ -126,7 +126,7 @@ Sections 1 to 12 are one commit each, and their items are that commit's parts; s - the list row ignoring the behavior: caught by `TestSubscriptionTitlesFor`, `want_new` `subscriptionTitlesFor(a paused row) =`; - the warning's old text restored: caught by `TestOrgEnrollmentIssueGrantPanel_Stacked`, `want_new` `the stacked Issue grant panel lacks`; - the list's paused title not rendered: caught by `TestSubscriptionsListMarksAPausedSubscription`, `want_new` `subscriptions list title =`. -- [ ] 5.9 `make screens`: the Issue grant captures that show the warning change, at both widths. The paused title is an attribute no capture shows; the golden pins it. +- [x] 5.9 `make screens`: no change. No capture shows the warning: the captured organization's one subscription, Carlos's, holds no tier, so no product the Issue grant select offers carries the marker; the goldens of 5.5 pin the warning's text. The paused title is an attribute no capture shows; the golden pins it. ## 6. An hourly sweep asks again for a subscription whose pause disagrees with the rule