diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 25414ee268d..ebe828563b2 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -3711,6 +3711,7 @@ "yearly": "Billed yearly. Next invoice {date}." }, "ended": "Ended {date}.", + "endedNoDate": "This plan has ended.", "ending": "Ends {date}. You won't be charged again.", "lifecycleRefused": "We couldn't make this change. Try again.", "managedByOwner": "Managed by the workspace owner.", diff --git a/src/platform/account/components/dialogs/settings/BillingTab.test.ts b/src/platform/account/components/dialogs/settings/BillingTab.test.ts index 8c659675069..7d5635a5aff 100644 --- a/src/platform/account/components/dialogs/settings/BillingTab.test.ts +++ b/src/platform/account/components/dialogs/settings/BillingTab.test.ts @@ -1071,6 +1071,42 @@ describe('BillingTab', () => { ) }) + it.for([ + { + case: 'a served end date', + endDate: '2026-09-01T00:00:00Z', + line: 'Ended September 1.' + }, + { case: 'no end date', endDate: null, line: 'This plan has ended.' } + ])('reads an ended plan with $case as "$line"', ({ endDate, line }) => { + arrange({ + subscriptionStatus: 'ended', + subscription: { ...activeSubscription, isActive: false, endDate } + }) + + expect(screen.getByTestId('billing-plan-line').textContent.trim()).toBe( + line + ) + expect( + screen.getByRole('link', { name: 'Choose a plan' }) + ).toBeInTheDocument() + }) + + it('titles an ended plan with no served plan name as Your plan', () => { + arrange({ + subscriptionStatus: null, + subscriptionState: 'ended', + subscription: { ...activeSubscription, isActive: false, tier: null } + }) + + expect( + screen.getByRole('heading', { name: 'Your plan' }) + ).toBeInTheDocument() + expect(screen.getByTestId('billing-plan-line').textContent.trim()).toBe( + 'This plan has ended.' + ) + }) + it('renders an unrecognised plan as Your plan', () => { arrange({ subscription: { ...activeSubscription, tier: null } }) @@ -1247,6 +1283,45 @@ describe('BillingTab', () => { expect(addCreditsVariants()).toEqual(['inverted', 'inverted']) }) + it.for([ + { signal: 'subscription_status', subscriptionStatus: 'ended' as const }, + { signal: 'subscription_state', subscriptionState: 'ended' as const } + ])( + 'keeps the Credits card the one white Add credits on local ComfyUI when $signal is ended and out of credits', + async (scenario) => { + vi.mocked(useFeatureFlags().flags).unifiedBillingSettingsEnabled = true + arrange({ + ...scenario, + balance: zeroBalance, + subscription: { + ...activeSubscription, + isActive: false, + hasFunds: false + } + }) + + await screen.findByTestId('billing-auto-top-up-status') + expect( + within(screen.getByTestId('billing-local-credit-banner')).getByRole( + 'button', + { name: 'Add credits' } + ) + ).toHaveAttribute('data-variant', 'secondary') + expect( + within(screen.getByTestId('billing-credits-card')).getByRole( + 'button', + { name: 'Add credits' } + ) + ).toHaveAttribute('data-variant', 'inverted') + expect( + [ + ...screen.queryAllByRole('button'), + ...screen.queryAllByRole('link') + ].filter((el) => el.dataset.variant === 'inverted') + ).toHaveLength(1) + } + ) + it('turns Add credits white at 0 while a top-up payment is processing and auto top-up is off', async () => { servedCheckouts(checkout('payment_processing')) arrange({ balance: zeroBalance }) @@ -1292,6 +1367,51 @@ describe('BillingTab', () => { expect(addCreditsVariants()).toEqual(['secondary']) }) + it.for([ + { + surface: 'Cloud', + isCloud: true, + choosePlan: 'inverted', + addCredits: 'secondary', + planEndedBanners: 1 + }, + { + surface: 'local ComfyUI', + isCloud: false, + choosePlan: 'secondary', + addCredits: 'inverted', + planEndedBanners: 0 + } + ])( + 'keeps one white button on $surface when an ended plan is out of credits', + async ({ isCloud, choosePlan, addCredits, planEndedBanners }) => { + distribution.isCloud = isCloud + onTestFinished(() => { + distribution.isCloud = false + }) + arrange({ + balance: zeroBalance, + subscriptionStatus: 'ended', + subscription: { ...activeSubscription, isActive: false } + }) + + await screen.findByTestId('billing-auto-top-up-status') + expect( + screen.getByRole('link', { name: 'Choose a plan' }) + ).toHaveAttribute('data-variant', choosePlan) + expect(addCreditsVariants()).toEqual([addCredits]) + expect(screen.queryAllByText(/^Your .*plan has ended$/)).toHaveLength( + planEndedBanners + ) + expect( + [ + ...screen.queryAllByRole('button'), + ...screen.queryAllByRole('link') + ].filter((el) => el.dataset.variant === 'inverted') + ).toHaveLength(1) + } + ) + it('offers no Add credits on a failed top-up when the server withholds can_top_up', async () => { servedCheckouts(checkout('failed')) arrange({ canTopUp: false }) diff --git a/src/platform/account/components/dialogs/settings/BillingTab.vue b/src/platform/account/components/dialogs/settings/BillingTab.vue index b96167ea5f2..5422f1a3eee 100644 --- a/src/platform/account/components/dialogs/settings/BillingTab.vue +++ b/src/platform/account/components/dialogs/settings/BillingTab.vue @@ -24,7 +24,7 @@

@@ -59,6 +59,7 @@ :state="planRow" :action="action" :sales-variant="salesVariant" + :add-credits-variant="addCreditsVariant" :can-manage-subscription="capabilities.canManageSubscription.value" />

@@ -159,6 +160,7 @@ import Button from '@comfyorg/design-system/button/Button' import Skeleton from '@comfyorg/design-system/skeleton/Skeleton' import { useBillingContext } from '@/platform/billing/composables/useBillingContext' import { useBillingDialogs } from '@/platform/billing/composables/useBillingDialogs' +import { isCloud } from '@/platform/distribution/types' import { useExternalLink } from '@/composables/useExternalLink' import { useMessageSupport } from '@/platform/billing/subscription/composables/useSubscriptionActions' import { useTelemetry } from '@comfyorg/telemetry' @@ -250,10 +252,14 @@ const addCreditsVariant = computed(() => ? autoTopUp.value.settings.status : null, planActionIsPrimary: - action.value === 'subscribe' || action.value === 'choosePlan' + action.value === 'subscribe' || (action.value === 'choosePlan' && isCloud) }) ) +const creditBannerAddCreditsVariant = computed(() => + planRow.value.kind === 'ended' ? 'secondary' : addCreditsVariant.value +) + const salesVariant = computed(() => billing.subscriptionStatus.value === 'ended' ? 'inverted' : 'secondary' ) diff --git a/src/platform/billing/components/billingTab/BillingPlanRow.vue b/src/platform/billing/components/billingTab/BillingPlanRow.vue index 9b680a219fc..baed0b3eec0 100644 --- a/src/platform/billing/components/billingTab/BillingPlanRow.vue +++ b/src/platform/billing/components/billingTab/BillingPlanRow.vue @@ -35,7 +35,11 @@ :href="plansHref" target="_blank" rel="noopener" - :variant="action === 'manage' ? 'secondary' : 'inverted'" + :variant=" + action === 'manage' || addCreditsVariant === 'inverted' + ? 'secondary' + : 'inverted' + " size="md" class="shrink-0 no-underline" @click="trackPlans" @@ -67,12 +71,14 @@ const { state, action, canManageSubscription, - salesVariant = 'secondary' + salesVariant = 'secondary', + addCreditsVariant = 'secondary' } = defineProps<{ state: PlanRowState action: PlanRowAction | null canManageSubscription: boolean salesVariant?: 'inverted' | 'secondary' + addCreditsVariant?: 'inverted' | 'secondary' }>() const { href: plansHref, track: trackPlans } = usePlatformHandoff( @@ -89,6 +95,9 @@ const title = computed(() => { if (state.kind === 'unknown') { return t('workspacePanel.billingTab.plan.unknown.title') } + if (state.kind === 'ended') { + return state.planName ?? t('workspacePanel.billingTab.plan.unknown.title') + } if (state.kind === 'salesManaged') { return ( state.planName ?? t('workspacePanel.billingTab.plan.salesManaged.title') @@ -124,6 +133,14 @@ function noPlanLine(state: Extract) { : t(`${key}.freeRunsUsed`, { total }) } +function endedLine(state: Extract) { + const key = 'workspacePanel.billingTab.plan' + if (!state.endedAt) return t(`${key}.endedNoDate`) + return t(`${key}.ended`, { + date: formatPlanDate(state.endedAt, locale.value, state.cadence) + }) +} + const statusLine = computed(() => { const key = 'workspacePanel.billingTab.plan' if (state.kind === 'activating') { @@ -144,11 +161,7 @@ const statusLine = computed(() => { date: formatPlanDate(state.endsAt, locale.value, state.cadence) }) } - if (state.kind === 'ended') { - return t(`${key}.ended`, { - date: formatPlanDate(state.endedAt, locale.value, state.cadence) - }) - } + if (state.kind === 'ended') return endedLine(state) return '' }) diff --git a/src/platform/billing/components/billingTab/planRow.test.ts b/src/platform/billing/components/billingTab/planRow.test.ts index ebd2a228cf9..041402d662a 100644 --- a/src/platform/billing/components/billingTab/planRow.test.ts +++ b/src/platform/billing/components/billingTab/planRow.test.ts @@ -166,7 +166,64 @@ describe('derivePlanRow', () => { { case: 'an ended plan without an end date', facts: { subscriptionStatus: 'ended' }, - expected: { kind: 'unknown' } + expected: { + kind: 'ended', + planName: 'Pro', + cadence: 'monthly', + endedAt: null + } + }, + { + case: 'an ended plan with a served ended_at over cancel_at', + facts: { + subscriptionStatus: 'ended', + endedAt: '2026-08-20T00:00:00Z', + endDate: '2026-09-01T00:00:00Z' + }, + expected: { + kind: 'ended', + planName: 'Pro', + cadence: 'monthly', + endedAt: '2026-08-20T00:00:00Z' + } + }, + { + case: 'an ended plan whose ended_at is served as null', + facts: { + subscriptionStatus: 'ended', + endedAt: null, + endDate: '2026-09-01T00:00:00Z' + }, + expected: { + kind: 'ended', + planName: 'Pro', + cadence: 'monthly', + endedAt: null + } + }, + { + case: 'an ended subscription_state with no plan name', + facts: { + subscriptionState: 'ended', + subscriptionStatus: null, + planName: null + }, + expected: { + kind: 'ended', + planName: null, + cadence: 'monthly', + endedAt: null + } + }, + { + case: 'a served ended subscription_state', + facts: { subscriptionState: 'ended', subscriptionStatus: null }, + expected: { + kind: 'ended', + planName: 'Pro', + cadence: 'monthly', + endedAt: null + } }, { case: 'an active sales-managed plan with no served plan name', @@ -219,7 +276,22 @@ describe('derivePlanRow', () => { planName: null, endDate: '2026-09-01T00:00:00Z' }, - expected: { kind: 'unknown' } + expected: { + kind: 'ended', + planName: null, + cadence: 'monthly', + endedAt: '2026-09-01T00:00:00Z' + } + }, + { + case: 'an ended subscription_status with no plan name', + facts: { subscriptionStatus: 'ended', planName: null, duration: null }, + expected: { + kind: 'ended', + planName: null, + cadence: null, + endedAt: null + } } ])('maps $case', ({ facts, expected }) => { expect(derivePlanRow({ ...baseFacts, ...facts })).toEqual(expected) diff --git a/src/platform/billing/components/billingTab/planRow.ts b/src/platform/billing/components/billingTab/planRow.ts index 406615a7381..37d27996315 100644 --- a/src/platform/billing/components/billingTab/planRow.ts +++ b/src/platform/billing/components/billingTab/planRow.ts @@ -19,6 +19,7 @@ export interface PlanRowFacts { planName: string | null renewalDate: string | null endDate: string | null + endedAt?: string | null scheduledChange: { planName: string; effectiveAt: string } | null freeRuns: { remaining: number; total: number } | null planKind: PlanKind | null @@ -42,9 +43,9 @@ export type PlanRowState = } | { kind: 'ended' - planName: string + planName: string | null cadence: BillingCadence | null - endedAt: string + endedAt: string | null } | { kind: 'noPlan' @@ -80,6 +81,19 @@ function toCadence( return null } +function endedDate(facts: PlanRowFacts): string | null { + return facts.endedAt === undefined ? facts.endDate : facts.endedAt +} + +function endedRow(facts: PlanRowFacts): PlanRowState { + return { + kind: 'ended', + planName: facts.planName, + cadence: toCadence(facts.duration), + endedAt: endedDate(facts) + } +} + function salesManagedRow(facts: PlanRowFacts): PlanRowState | null { if (facts.planKind !== 'sales_managed') return null switch (facts.billingStatus) { @@ -105,6 +119,13 @@ export function derivePlanRow(facts: PlanRowFacts): PlanRowState { if (facts.subscriptionState === 'activating' && planName !== null) { return { kind: 'activating', planName } } + if (facts.subscriptionState === 'ended') { + return endedRow(facts) + } + switch (subscriptionStatus) { + case 'ended': + return endedRow(facts) + } if (subscriptionStatus === null) { return { kind: 'noPlan', freeRuns: facts.freeRuns } } @@ -131,10 +152,6 @@ export function derivePlanRow(facts: PlanRowFacts): PlanRowState { return endDate ? { kind: 'ending', planName, cadence, endsAt: endDate } : UNKNOWN - case 'ended': - return endDate - ? { kind: 'ended', planName, cadence, endedAt: endDate } - : UNKNOWN default: return UNKNOWN } diff --git a/src/platform/billing/components/billingTab/useBillingPlanRow.ts b/src/platform/billing/components/billingTab/useBillingPlanRow.ts index 31faa31ea08..5dad62f4699 100644 --- a/src/platform/billing/components/billingTab/useBillingPlanRow.ts +++ b/src/platform/billing/components/billingTab/useBillingPlanRow.ts @@ -43,12 +43,24 @@ export function useBillingPlanRow() { : null ) - const subscriptionFacts = computed(() => ({ - duration: subscription.value?.duration ?? null, - planName: planNameFor(subscription.value?.tier ?? null), - renewalDate: subscription.value?.renewalDate ?? null, - endDate: subscription.value?.endDate ?? null - })) + const subscriptionFacts = computed(() => { + const current = subscription.value + if (!current) { + return { + duration: null, + planName: null, + renewalDate: null, + endDate: null + } + } + return { + duration: current.duration, + planName: planNameFor(current.tier), + renewalDate: current.renewalDate, + endDate: current.endDate, + endedAt: current.endedAt + } + }) const state = computed(() => derivePlanRow({ diff --git a/src/platform/billing/composables/types.ts b/src/platform/billing/composables/types.ts index db2b6be5ef4..d2976930a3b 100644 --- a/src/platform/billing/composables/types.ts +++ b/src/platform/billing/composables/types.ts @@ -76,6 +76,8 @@ export interface SubscriptionInfo { renewalDate: string | null /** ISO 8601; format at the display site. */ endDate: string | null + /** Served `ended_at`; absent when the server omits the field. */ + endedAt?: string | null isCancelled: boolean hasFunds: boolean /** Agent funds across shared credits and the Agent-scoped balance. */ diff --git a/src/platform/billing/composables/useBillingContext.test.ts b/src/platform/billing/composables/useBillingContext.test.ts index a296b8e38ce..1df5f65aebf 100644 --- a/src/platform/billing/composables/useBillingContext.test.ts +++ b/src/platform/billing/composables/useBillingContext.test.ts @@ -204,6 +204,7 @@ describe('useBillingContext', () => { scheduledChange: null, renewalDate: '2025-01-01T00:00:00Z', endDate: null, + endedAt: null, isCancelled: false, hasFunds: true, agentHasFunds: true, diff --git a/src/platform/billing/composables/useLegacyBilling.test.ts b/src/platform/billing/composables/useLegacyBilling.test.ts index c3e650b571c..7a77e994add 100644 --- a/src/platform/billing/composables/useLegacyBilling.test.ts +++ b/src/platform/billing/composables/useLegacyBilling.test.ts @@ -99,6 +99,34 @@ describe('useLegacyBilling', () => { expect(useLegacyBilling().subscription.value).toBeNull() }) + it('keeps a tierless ended status without an invoice as a subscription', () => { + useInactiveStatus( + statusWith({ + is_active: false, + subscription_status: 'ended', + ended_at: '2026-08-20T00:00:00Z' + }) + ) + + expect(useLegacyBilling().subscription.value?.endedAt).toBe( + '2026-08-20T00:00:00Z' + ) + }) + + it('keeps a tierless ended subscription_state without an invoice as a subscription', () => { + useInactiveStatus( + statusWith({ + is_active: false, + subscription_state: 'ended', + ended_at: '2026-08-20T00:00:00Z' + }) + ) + + expect(useLegacyBilling().subscription.value?.endedAt).toBe( + '2026-08-20T00:00:00Z' + ) + }) + it('is null when the billing status carries no renewal invoice', () => { useSubscription().subscriptionStatus.value = statusWith({}) diff --git a/src/platform/billing/composables/useLegacyBilling.ts b/src/platform/billing/composables/useLegacyBilling.ts index e88ea5a3c2c..4568bcccaaa 100644 --- a/src/platform/billing/composables/useLegacyBilling.ts +++ b/src/platform/billing/composables/useLegacyBilling.ts @@ -33,6 +33,27 @@ type RuntimeLegacyBalance = Omit< } type StatusReadResult = { ok: true } | { ok: false; cause: unknown } +function datesFromStatus(status: BillingStatusResponse | null) { + return { + renewalDate: status?.renewal_date ?? null, + endDate: status?.cancel_at ?? null, + endedAt: status?.ended_at + } +} + +function servesEndedSubscription(status: BillingStatusResponse | null) { + switch (status?.subscription_status) { + case 'ended': + return true + } + switch (status?.subscription_state) { + case 'ended': + return true + default: + return false + } +} + function fundsFromStatus( status: BillingStatusResponse | null, statusReadAuthoritative: boolean @@ -121,7 +142,8 @@ export function useLegacyBilling(): BillingState & BillingActions { if ( !legacyCanAccessSubscriptionFeatures.value && !subscriptionTier.value && - !status?.renewal_invoice + !status?.renewal_invoice && + !servesEndedSubscription(status) ) { return null } @@ -132,8 +154,7 @@ export function useLegacyBilling(): BillingState & BillingActions { duration: subscriptionDuration.value, planSlug: null, scheduledChange: null, - renewalDate: status?.renewal_date ?? null, - endDate: status?.cancel_at ?? null, + ...datesFromStatus(status), isCancelled: isCancelled.value, ...fundsFromStatus(status, statusReadAuthoritative.value) } diff --git a/src/platform/billing/composables/useWorkspaceBilling.test.ts b/src/platform/billing/composables/useWorkspaceBilling.test.ts index d7d77bf3066..93101f1008a 100644 --- a/src/platform/billing/composables/useWorkspaceBilling.test.ts +++ b/src/platform/billing/composables/useWorkspaceBilling.test.ts @@ -288,6 +288,23 @@ describe('useWorkspaceBilling', () => { } ) + it.for([ + { case: 'a recorded end', endedAt: '2026-05-20T00:00:00Z' }, + { case: 'an unrecorded end', endedAt: null } + ])('passes the served ended_at through for $case', async ({ endedAt }) => { + mockWorkspaceApi.getBillingStatus.mockResolvedValue({ + ...activeStatus, + subscription_status: 'ended', + subscription_state: 'ended', + ended_at: endedAt + }) + + const billing = setupBilling() + await billing.fetchStatus() + + expect(billing.subscription.value?.endedAt).toBe(endedAt) + }) + it('maps status response into subscription info', async () => { mockWorkspaceApi.getBillingStatus.mockResolvedValue({ ...activeStatus, diff --git a/src/platform/billing/composables/useWorkspaceBilling.ts b/src/platform/billing/composables/useWorkspaceBilling.ts index 0208f2c560b..8468a7f6c61 100644 --- a/src/platform/billing/composables/useWorkspaceBilling.ts +++ b/src/platform/billing/composables/useWorkspaceBilling.ts @@ -238,6 +238,7 @@ export function useWorkspaceBilling(): WorkspaceBilling { scheduledChange: status.scheduled_change ?? null, renewalDate: status.renewal_date ?? null, endDate: status.cancel_at ?? null, + endedAt: status.ended_at, isCancelled: status.subscription_status === 'canceled', hasFunds: status.has_funds, agentHasFunds: