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 55242750124..18ab585b34b 100644 --- a/src/platform/workspace/composables/deriveBillingBanner.test.ts +++ b/src/platform/workspace/composables/deriveBillingBanner.test.ts @@ -22,7 +22,9 @@ const funded: BillingBannerInputs = { planChangeDismissed: false, hasScheduledChange: false, topUpDeniedPastDue: false, - runDeniedPastDue: false + runDeniedPastDue: false, + unifiedBillingSettingsEnabled: false, + isActive: true } function derive(overrides: Partial, now?: number) { @@ -168,6 +170,27 @@ 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, + topUpDeniedPastDue: true + }) + ).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 30aeda9df96..12045eb6f35 100644 --- a/src/platform/workspace/composables/useBillingBanner.ts +++ b/src/platform/workspace/composables/useBillingBanner.ts @@ -42,6 +42,8 @@ export interface BillingBannerInputs { hasScheduledChange: boolean topUpDeniedPastDue: boolean runDeniedPastDue: boolean + unifiedBillingSettingsEnabled: boolean + isActive: boolean } // An Enterprise cancel_at is an agreed end date — an operator pilot term or @@ -108,14 +110,24 @@ function showsPastDueOutOfCredits(inputs: BillingBannerInputs): boolean { ) } +function cloudCreditBannersOpen(inputs: BillingBannerInputs): boolean { + if (!inputs.unifiedBillingSettingsEnabled) return true + return inputs.isActive +} + function deriveNoticeBanner( inputs: BillingBannerInputs, audience: BillingBannerAudience ): BillingBannerKind | null { if (!inputs.billingControlEnabled) return null - if (showsPastDueOutOfCredits(inputs)) return 'outOfCredits' + const creditsOpen = cloudCreditBannersOpen(inputs) + if (creditsOpen && showsPastDueOutOfCredits(inputs)) return 'outOfCredits' if (!inputs.canAccessSubscriptionFeatures) return null - if (inputs.hasFunds === false && !inputs.outOfCreditsDismissed) { + if ( + creditsOpen && + inputs.hasFunds === false && + !inputs.outOfCreditsDismissed + ) { return 'outOfCredits' } return deriveLifecycleNotice(inputs, audience) @@ -208,6 +220,8 @@ function useBillingBannerInternal() { planChangeDismissed: planChangeDismissed.value, topUpDeniedPastDue: isTopUpDeniedPastDue(topUpDenial.value), runDeniedPastDue: runDeniedPaymentPastDue.value, + unifiedBillingSettingsEnabled: flags.unifiedBillingSettingsEnabled, + isActive: subscription.value?.isActive === true, ...readSubscriptionInputs(subscription.value) }))