carlos / platform Public

console: renewal is never refused on a billing problem (plans 6b task 10 review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev dd47cce5bf67ce84e3c841e1a174db46eb54cdd4 parent 2cdfb74
2 files changed, +57 −40
  • internal/console/billingchange.go +7 −7
  • internal/console/billingchange_test.go +50 −33

CI cancelled — superseded by a newer push — run details

diff --git a/internal/console/billingchange.go b/internal/console/billingchange.go
index 16fea112b..9adf009a4 100644
--- a/internal/console/billingchange.go
+++ b/internal/console/billingchange.go
@@ -239,7 +239,9 @@ func (s *Server) changeRefusalsLocked(h billingHold, acct *Account, now time.Tim
}
// refuseOnProblemLocked refuses (notice.problem) while the account has an
-// open billing problem: a local read, no provider request. A request checks
+// open billing problem: a local read, no provider request. It is for the
+// flows that can prepare a charge or a quantity raise (change, upgrade, seat
+// admission, Match seats, the invite confirm), never renewal. A request checks
// it before it starts and again after its own fresh reads (finishing an
// operation, the allowance or refresh), which can open a problem without
// failing (restore_after_renewal, an unrecognised read, a second
@@ -577,9 +579,10 @@ func renewalText(renew bool, periodEnd time.Time) changeReply {
// renewalLocked is stopping (renew false) or resuming renewal under the
// hold: refused while retiring; an outstanding operation is finished first;
-// then a refresh, refused if the account has an open problem by then, and
-// one renewal operation unless the subscription is already as asked; then the
-// subscription is refreshed again.
+// then a refresh, and one renewal operation unless the subscription is
+// already as asked; then the subscription is refreshed again. An open billing
+// problem never refuses it: renewal prepares no charge or quantity raise
+// (refuseOnProblemLocked is only for flows that can).
func (s *Server) renewalLocked(h billingHold, ctx context.Context, acct *Account, renew bool, now time.Time) (changeReply, error) {
if retiring, err := s.store.BillingRetiring(acct.ID, now); err != nil {
return changeReply{}, err
@@ -593,9 +596,6 @@ func (s *Server) renewalLocked(h billingHold, ctx context.Context, acct *Account
if err != nil {
return changeReply{}, err
}
- if err := s.refuseOnProblemLocked(h, acct); err != nil {
- return changeReply{}, err
- }
if sub == nil || !sub.Live {
return changeReply{}, errChangeFailed
}
diff --git a/internal/console/billingchange_test.go b/internal/console/billingchange_test.go
index 4fa8a4db8..6639fdb8d 100644
--- a/internal/console/billingchange_test.go
+++ b/internal/console/billingchange_test.go
@@ -882,41 +882,58 @@ func TestPackChangeRefusesOperatorPlanAndProblems(t *testing.T) {
// TestChangeStopsOnAProblemItsOwnReadFinds: the request's own fresh read
// (finishing a restore that applied after renewal) opens
-// restore_after_renewal, so nothing more is prepared or sent.
+// restore_after_renewal, so a change prepares and sends nothing more.
+// Renewal is never refused on a problem: it prepares no charge or raise.
func TestChangeStopsOnAProblemItsOwnReadFinds(t *testing.T) {
- for _, c := range []struct {
- name string
- do func(t *testing.T, o *opsFixture) billingReply
- }{
- {"change", func(t *testing.T, o *opsFixture) billingReply {
- return o.change(t, "pack", "apps", "quantity", "4", "confirmed", "1")
- }},
- {"renewal", func(t *testing.T, o *opsFixture) billingReply { return o.renewal(t, "stop") }},
- } {
- t.Run(c.name, func(t *testing.T) {
- o := newRestoreFixture(t)
- o.heldRestore(t, "op_1", "sub_1")
- if err := o.fake.Renew("sub_1"); err != nil { // the renewal bills 1, then the held restore applies
- t.Fatal(err)
- }
- if probs := o.openProblems(t); len(probs) != 0 {
- t.Fatalf("problems before the request = %v", probs)
- }
- o.signInOwner(t)
- o.stepUp(t)
- o.reset()
- o.wantFlash(t, c.do(t, o), "err", billingCopy["notice.problem"])
- if got := o.openProblems(t); len(got) != 1 || got[0] != problemRestoreAfterRenewal {
- t.Fatalf("problems = %v, want restore_after_renewal", got)
- }
- if n := o.counts()["Send"]; n != 0 {
- t.Fatalf("sends = %d, want 0", n)
- }
- if all := o.ops(t); len(all) != 1 || all[0].ID != "op_1" {
- t.Fatalf("ops = %+v, want only the restore", all)
- }
- })
+ setup := func(t *testing.T) *opsFixture {
+ o := newRestoreFixture(t)
+ o.heldRestore(t, "op_1", "sub_1")
+ if err := o.fake.Renew("sub_1"); err != nil { // the renewal bills 1, then the held restore applies
+ t.Fatal(err)
+ }
+ if probs := o.openProblems(t); len(probs) != 0 {
+ t.Fatalf("problems before the request = %v", probs)
+ }
+ o.signInOwner(t)
+ o.stepUp(t)
+ o.reset()
+ return o
+ }
+ wantFlagged := func(t *testing.T, o *opsFixture) {
+ t.Helper()
+ if got := o.openProblems(t); len(got) != 1 || got[0] != problemRestoreAfterRenewal {
+ t.Fatalf("problems = %v, want restore_after_renewal", got)
+ }
}
+ t.Run("change", func(t *testing.T) {
+ o := setup(t)
+ o.wantFlash(t, o.change(t, "pack", "apps", "quantity", "4", "confirmed", "1"), "err", billingCopy["notice.problem"])
+ wantFlagged(t, o)
+ if n := o.counts()["Send"]; n != 0 {
+ t.Fatalf("sends = %d, want 0", n)
+ }
+ if all := o.ops(t); len(all) != 1 || all[0].ID != "op_1" {
+ t.Fatalf("ops = %+v, want only the restore", all)
+ }
+ })
+ t.Run("renewal", func(t *testing.T) {
+ o := setup(t)
+ end := o.sub("sub_1").PeriodEnd
+ o.wantFlash(t, o.renewal(t, "stop"), "ok", fmt.Sprintf(billingCopy["renewal.stopped"], billingDate(end)))
+ wantFlagged(t, o)
+ if n := o.counts()["Send"]; n != 1 {
+ t.Fatalf("sends = %d, want the one renewal operation", n)
+ }
+ if op := o.lastOp(t); op.Kind != opRenewal || op.State != opApplied || !o.sub("sub_1").CancelAtPeriodEnd {
+ t.Fatalf("renewal op = %+v", op)
+ }
+ // With the problem still open, resuming is allowed too.
+ o.wantFlash(t, o.renewal(t, "resume"), "ok", billingCopy["renewal.resumed"])
+ wantFlagged(t, o)
+ if o.sub("sub_1").CancelAtPeriodEnd {
+ t.Fatal("renewal was not resumed")
+ }
+ })
}
// TestChangeCSRFRefusalCopy: the cross-site refusal's text is the copy map's.