From 738e31390bca18cbc21964377ef1fbe99b87db26 Mon Sep 17 00:00:00 2001 From: Dante Date: Fri, 23 Oct 2026 17:44:08 +0000 Subject: [PATCH] feat(billing): gate Cloud credit banners on is_active (#21709) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Cloud, Out of credits and Low credits should show only while the workspace plan is active. Local credit banners stay as they are. Turning `unified_billing_settings` off must restore the banners that ship today. The Billing tab credit banner reads `is_active` and, on Cloud, renders only when that fact is true and unified billing settings is on. Local ignores `is_active`. The shared Cloud notice banner keeps today's out-of-credits behavior when the flag is off, and hides it when the flag is on and `is_active` is false, including the past-due credit case. The Billing tab credit banner returned nothing on Cloud, and the shared notice still showed Out of credits from balance alone. DES-1234 says Cloud credit banners follow `is_active` on `GET /api/billing/status`. AS IS: Cloud Billing tab shows no Out of credits or Low credits banner. The older notice can still show Out of credits when the balance is empty, including when the plan is not active. TO BE: With unified billing settings on, Cloud shows those credit banners only while `is_active` is true. Local still shows them without reading `is_active`. With the flag off, the current notices stay. Screenshots from a running workspace are not attached yet. | Item | Ticket | PR | Status | | --- | --- | --- | --- | | Cloud credit banners on is_active | DES-1234 | this PR | **open** | | Plan checkout banners | FE-3527 | separate | open | | Credits refill date | — | separate | open | ```mermaid flowchart LR flag["unified billing settings"] --> credits["this PR"] active["is_active"] --> credits ``` (cherry picked from commit 174bd880787b177f408cb73752bccc1d2ca720cc) --- .../billing/BillingLocalCreditBanner.test.ts | 31 +++++++++++++--- .../billing/BillingLocalCreditBanner.vue | 3 +- .../composables/deriveBillingBanner.test.ts | 24 +++++++++++- .../deriveLocalCreditBanner.test.ts | 37 +++++++++++++++++++ .../composables/deriveLocalCreditBanner.ts | 3 ++ .../workspace/composables/useBillingBanner.ts | 15 +++++++- 6 files changed, 105 insertions(+), 8 deletions(-) diff --git a/src/platform/workspace/components/dialogs/settings/billing/BillingLocalCreditBanner.test.ts b/src/platform/workspace/components/dialogs/settings/billing/BillingLocalCreditBanner.test.ts index cbbb1207867..6f204217986 100644 --- a/src/platform/workspace/components/dialogs/settings/billing/BillingLocalCreditBanner.test.ts +++ b/src/platform/workspace/components/dialogs/settings/billing/BillingLocalCreditBanner.test.ts @@ -107,14 +107,13 @@ describe('BillingLocalCreditBanner', () => { ).not.toBeInTheDocument() }) - it('renders nothing on cloud', () => { + it('renders nothing on cloud without an active plan', () => { arrange({ isCloud: true, subscription: { ...personalSubscription, - hasFunds: false, - isCancelled: true, - endDate: '2026-08-01T00:00:00Z' + isActive: false, + hasFunds: false }, balance: { amountMicros: 500, currency: 'usd', lowBalance: true } }) @@ -122,7 +121,29 @@ describe('BillingLocalCreditBanner', () => { expect( screen.queryByTestId('billing-local-credit-banner') ).not.toBeInTheDocument() - expect(screen.queryByText('Subscription paused')).not.toBeInTheDocument() + }) + + it('shows out of credits on an active cloud plan', () => { + arrange({ + isCloud: true, + subscription: { ...personalSubscription, hasFunds: false }, + renewalDate: '2026-10-01T00:00:00Z' + }) + + expect(screen.getByTestId('billing-local-credit-banner')).toHaveTextContent( + 'Out of credits' + ) + }) + + it('shows low credits on an active cloud plan', () => { + arrange({ + isCloud: true, + balance: { amountMicros: 500, currency: 'usd', lowBalance: true } + }) + + expect(screen.getByTestId('billing-local-credit-banner')).toHaveTextContent( + 'Credits are low' + ) }) it.for([ diff --git a/src/platform/workspace/components/dialogs/settings/billing/BillingLocalCreditBanner.vue b/src/platform/workspace/components/dialogs/settings/billing/BillingLocalCreditBanner.vue index cc426e4a4eb..d66936fdf67 100644 --- a/src/platform/workspace/components/dialogs/settings/billing/BillingLocalCreditBanner.vue +++ b/src/platform/workspace/components/dialogs/settings/billing/BillingLocalCreditBanner.vue @@ -96,9 +96,10 @@ const balance = computed(() => billing.balance?.value ?? null) const isTeamPlan = computed(() => billing.isTeamPlan?.value ?? false) const kind = computed(() => { - if (isCloud) return null return deriveLocalCreditBanner({ unifiedBillingSettingsEnabled: flags.unifiedBillingSettingsEnabled, + isCloud, + isActive: subscription.value?.isActive === true, hasFunds: subscription.value?.hasFunds ?? null, lowBalance: balance.value?.lowBalance, outOfCreditsDismissed: outOfCreditsDismissed.value, diff --git a/src/platform/workspace/composables/deriveBillingBanner.test.ts b/src/platform/workspace/composables/deriveBillingBanner.test.ts index 469e29fdd40..c78c348a168 100644 --- a/src/platform/workspace/composables/deriveBillingBanner.test.ts +++ b/src/platform/workspace/composables/deriveBillingBanner.test.ts @@ -20,7 +20,9 @@ const funded: BillingBannerInputs = { planEndedDismissed: false, outOfCreditsDismissed: false, planChangeDismissed: false, - hasScheduledChange: false + hasScheduledChange: false, + unifiedBillingSettingsEnabled: false, + isActive: true } function derive(overrides: Partial, now?: number) { @@ -166,6 +168,26 @@ describe('deriveBillingBanner', () => { expect(derive({ hasFunds: false })).toBe('outOfCredits') }) + it('hides cloud credit banners when unified billing is on and the plan is not active', () => { + expect( + derive({ + unifiedBillingSettingsEnabled: true, + isActive: false, + hasFunds: false + }) + ).toBeNull() + }) + + it('keeps cloud credit banners when unified billing is on and the plan is active', () => { + expect( + derive({ + unifiedBillingSettingsEnabled: true, + isActive: true, + hasFunds: false + }) + ).toBe('outOfCredits') + }) + it('shows out of credits to members too', () => { expect(derive({ hasFunds: false, canManage: false })).toBe('outOfCredits') }) diff --git a/src/platform/workspace/composables/deriveLocalCreditBanner.test.ts b/src/platform/workspace/composables/deriveLocalCreditBanner.test.ts index 87ff83e33a0..e9613d6486e 100644 --- a/src/platform/workspace/composables/deriveLocalCreditBanner.test.ts +++ b/src/platform/workspace/composables/deriveLocalCreditBanner.test.ts @@ -5,6 +5,8 @@ import { deriveLocalCreditBanner } from './deriveLocalCreditBanner' const open: LocalCreditBannerInput = { unifiedBillingSettingsEnabled: true, + isCloud: false, + isActive: false, hasFunds: true, lowBalance: undefined, outOfCreditsDismissed: false, @@ -16,6 +18,35 @@ function derive(overrides: Partial) { } describe('deriveLocalCreditBanner', () => { + it('stays hidden on cloud until the served plan is active', () => { + expect( + derive({ + isCloud: true, + isActive: false, + hasFunds: false, + lowBalance: true + }) + ).toBeNull() + }) + + it.for([ + { + name: 'out of credits', + input: { isCloud: true, isActive: true, hasFunds: false }, + expected: 'outOfCredits' as const + }, + { + name: 'low credits', + input: { isCloud: true, isActive: true, lowBalance: true }, + expected: 'lowCredits' as const + } + ])( + 'shows the $name cloud banner when the served plan is active', + ({ input, expected }) => { + expect(derive(input)).toBe(expected) + } + ) + it('stays hidden when unified billing settings is off', () => { expect( derive({ @@ -26,6 +57,12 @@ describe('deriveLocalCreditBanner', () => { ).toBeNull() }) + it('keeps local credit banners when the plan is not active', () => { + expect(derive({ isCloud: false, isActive: false, hasFunds: false })).toBe( + 'outOfCredits' + ) + }) + it.for([ { lowBalance: undefined, kind: null }, { lowBalance: false, kind: null }, diff --git a/src/platform/workspace/composables/deriveLocalCreditBanner.ts b/src/platform/workspace/composables/deriveLocalCreditBanner.ts index bb50f22e595..5de50677ca9 100644 --- a/src/platform/workspace/composables/deriveLocalCreditBanner.ts +++ b/src/platform/workspace/composables/deriveLocalCreditBanner.ts @@ -2,6 +2,8 @@ export type LocalCreditBannerKind = 'outOfCredits' | 'lowCredits' export interface LocalCreditBannerInput { unifiedBillingSettingsEnabled: boolean + isCloud: boolean + isActive: boolean hasFunds: boolean | null lowBalance: boolean | undefined outOfCreditsDismissed: boolean @@ -12,6 +14,7 @@ export function deriveLocalCreditBanner( input: LocalCreditBannerInput ): LocalCreditBannerKind | null { if (!input.unifiedBillingSettingsEnabled) return null + if (input.isCloud && !input.isActive) return null if (input.hasFunds === false && !input.outOfCreditsDismissed) { return 'outOfCredits' } diff --git a/src/platform/workspace/composables/useBillingBanner.ts b/src/platform/workspace/composables/useBillingBanner.ts index 7e157981b18..62b681f9483 100644 --- a/src/platform/workspace/composables/useBillingBanner.ts +++ b/src/platform/workspace/composables/useBillingBanner.ts @@ -38,6 +38,8 @@ export interface BillingBannerInputs { outOfCreditsDismissed: boolean planChangeDismissed: boolean hasScheduledChange: boolean + unifiedBillingSettingsEnabled: boolean + isActive: boolean } // An Enterprise cancel_at is an agreed end date — an operator pilot term or @@ -96,13 +98,22 @@ function deriveLifecycleNotice( return showsPlanChange ? 'planChange' : null } +function cloudCreditBannersOpen(inputs: BillingBannerInputs): boolean { + if (!inputs.unifiedBillingSettingsEnabled) return true + return inputs.isActive +} + function deriveNoticeBanner( inputs: BillingBannerInputs, audience: BillingBannerAudience ): BillingBannerKind | null { if (!inputs.canAccessSubscriptionFeatures) return null if (!inputs.billingControlEnabled) return null - if (inputs.hasFunds === false && !inputs.outOfCreditsDismissed) { + if ( + cloudCreditBannersOpen(inputs) && + inputs.hasFunds === false && + !inputs.outOfCreditsDismissed + ) { return 'outOfCredits' } return deriveLifecycleNotice(inputs, audience) @@ -192,6 +203,8 @@ function useBillingBannerInternal() { planEndedDismissed: planEndedDismissed.value, outOfCreditsDismissed: outOfCreditsDismissed.value, planChangeDismissed: planChangeDismissed.value, + unifiedBillingSettingsEnabled: flags.unifiedBillingSettingsEnabled, + isActive: subscription.value?.isActive === true, ...readSubscriptionInputs(subscription.value) }))