From 83d6a770bfecae71e27c866e7ef11b99b46b3313 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 5 Nov 2026 06:56:29 +0000 Subject: [PATCH 1/6] fix(billing): explain locked credits on Subscribe to Run for an inactive account with funds An inactive Cloud account that holds credits never reaches the server refusal that shows the locked-credits line (#22514): the client-side run block and the Subscribe to Run button open the paywall directly. Pass creditsLocked from billing status has_funds on both paths so the dialog says why the top-up did not unlock runs. Refs FRONT-3758 --- src/composables/useCoreCommands.test.ts | 25 +++++++++++++++++-- src/composables/useCoreCommands.ts | 3 ++- .../components/SubscribeToRun.test.ts | 25 +++++++++++++++++++ .../components/SubscribeToRun.vue | 5 +++- .../utils/subscribeToRunDialogOptions.test.ts | 21 ++++++++++++++++ .../utils/subscribeToRunDialogOptions.ts | 19 ++++++++++++++ 6 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts create mode 100644 src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index 01e8027e693..10c363645a2 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -154,6 +154,7 @@ vi.mock(import('@/platform/billing/subscription/composables/useSubscription')) const mockBillingState = vi.hoisted(() => ({ canAccessSubscriptionFeatures: true, subscriptionTier: null as string | null, + hasFunds: false, initialized: true, routing: 'workspace' as 'workspace' | 'unknown', onInitialize: null as (() => void) | null @@ -182,8 +183,11 @@ vi.mock( }, subscription: { get value() { - return mockBillingState.subscriptionTier - ? { tier: mockBillingState.subscriptionTier } + return mockBillingState.subscriptionTier || mockBillingState.hasFunds + ? { + tier: mockBillingState.subscriptionTier, + hasFunds: mockBillingState.hasFunds + } : null } } @@ -253,6 +257,7 @@ describe('useCoreCommands', () => { mockDistributionState.isCloud = false mockBillingState.canAccessSubscriptionFeatures = true mockBillingState.subscriptionTier = null + mockBillingState.hasFunds = false mockBillingState.initialized = true mockBillingState.routing = 'workspace' mockBillingState.onInitialize = null @@ -902,6 +907,22 @@ describe('useCoreCommands', () => { } ) + it('explains locked credits when an inactive Cloud account holds funds', async () => { + mockDistributionState.isCloud = true + mockBillingState.canAccessSubscriptionFeatures = false + mockBillingState.hasFunds = true + + await findCmd('Comfy.QueuePrompt').function() + + expect(app.queuePrompt).not.toHaveBeenCalled() + expect( + useSubscriptionPaywall().showSubscriptionDialog + ).toHaveBeenCalledWith({ + reason: 'subscribe_to_run', + creditsLocked: true + }) + }) + it.for(['ENTERPRISE', 'GALACTIC'] as const)( 'explains the block instead of a subscribe dialog on a sales-managed %s plan', async (tier) => { diff --git a/src/composables/useCoreCommands.ts b/src/composables/useCoreCommands.ts index b596997efac..dd02cea485b 100644 --- a/src/composables/useCoreCommands.ts +++ b/src/composables/useCoreCommands.ts @@ -30,6 +30,7 @@ import { useBillingContext } from '@/platform/billing/composables/useBillingCont import { useSubscriptionPaywall } from '@/platform/billing/composables/useSubscriptionPaywall' import { openModelLibraryBrowser } from '@/platform/assets/composables/openModelLibraryBrowser' import { isSalesManagedTier } from '@/platform/billing/subscription/constants/tierPricing' +import { subscribeToRunDialogOptions } from '@/platform/billing/subscription/utils/subscribeToRunDialogOptions' import { isCloud } from '@/platform/distribution/types' import { useMissingModelStore } from '@/platform/workflowErrors/missingModel/missingModelStore' import { resetOnboardingState } from '@/platform/onboarding/onboardingReset' @@ -108,7 +109,7 @@ export function useCoreCommands(): ComfyCommand[] { duration: 5000 }) } else { - showSubscriptionDialog({ reason: 'subscribe_to_run' }) + showSubscriptionDialog(subscribeToRunDialogOptions(subscription.value)) } return true } diff --git a/src/platform/billing/subscription/components/SubscribeToRun.test.ts b/src/platform/billing/subscription/components/SubscribeToRun.test.ts index 9baa4b4ba1a..2b787a3ef91 100644 --- a/src/platform/billing/subscription/components/SubscribeToRun.test.ts +++ b/src/platform/billing/subscription/components/SubscribeToRun.test.ts @@ -6,8 +6,11 @@ import { computed, ref } from 'vue' import { createI18n } from 'vue-i18n' import { useTelemetry } from '@comfyorg/telemetry' +import { useBillingContext } from '@/platform/billing/composables/useBillingContext' import { useBillingUI } from '@/platform/billing/composables/useBillingUI' +import type { SubscriptionInfo } from '@/platform/billing/composables/types' import { receiveServerFact } from '@/platform/serverFacts/serverFact' +import { fromPartial } from '@total-typescript/shoehorn' import SubscribeToRun from './SubscribeToRun.vue' @@ -18,6 +21,8 @@ vi.mock(import('@/platform/billing/composables/useSubscriptionPaywall')) vi.mock(import('@/platform/billing/composables/useBillingUI')) +vi.mock(import('@/platform/billing/composables/useBillingContext')) + vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: true })) @@ -104,6 +109,26 @@ describe('SubscribeToRun', () => { ).toHaveBeenCalledExactlyOnceWith({ reason: 'subscribe_to_run' }) }) + it('says why credits did not help when the inactive account holds funds', async () => { + const context = useBillingContext() + vi.mocked(useBillingContext).mockReturnValue({ + ...context, + subscription: computed(() => + fromPartial({ isActive: false, hasFunds: true }) + ) + }) + const { user } = renderButton() + + await user.click(screen.getByTestId('subscribe-to-run-button')) + + expect( + useSubscriptionPaywall().showSubscriptionDialog + ).toHaveBeenCalledExactlyOnceWith({ + reason: 'subscribe_to_run', + creditsLocked: true + }) + }) + it('routes members to the same role-aware dialog on click', async () => { mockCanManageSubscription.value = false const { user } = renderButton() diff --git a/src/platform/billing/subscription/components/SubscribeToRun.vue b/src/platform/billing/subscription/components/SubscribeToRun.vue index fe790cc7af5..4e065d8c113 100644 --- a/src/platform/billing/subscription/components/SubscribeToRun.vue +++ b/src/platform/billing/subscription/components/SubscribeToRun.vue @@ -26,7 +26,9 @@ import Button from '@comfyorg/design-system/button/Button' import { useSubscriptionPaywall } from '@/platform/billing/composables/useSubscriptionPaywall' import { useRunButtonTelemetry } from '@/composables/useRunButtonTelemetry' import { isCloud } from '@/platform/distribution/types' +import { useBillingContext } from '@/platform/billing/composables/useBillingContext' import { useBillingUI } from '@/platform/billing/composables/useBillingUI' +import { subscribeToRunDialogOptions } from '@/platform/billing/subscription/utils/subscribeToRunDialogOptions' const { t } = useI18n() @@ -36,6 +38,7 @@ const breakpoints = useBreakpoints(breakpointsTailwind) const isMdOrLarger = breakpoints.greaterOrEqual('md') const { permissions } = useBillingUI() +const { subscription } = useBillingContext() const { showSubscriptionDialog } = useSubscriptionPaywall() const { trackRunButton } = useRunButtonTelemetry() @@ -59,6 +62,6 @@ function handleSubscribeToRun() { trackRunButton({ subscribe_to_run: true }) } - showSubscriptionDialog({ reason: 'subscribe_to_run' }) + showSubscriptionDialog(subscribeToRunDialogOptions(subscription.value)) } diff --git a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts new file mode 100644 index 00000000000..a08e3263c78 --- /dev/null +++ b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from 'vitest' + +import { subscribeToRunDialogOptions } from './subscribeToRunDialogOptions' + +describe('subscribeToRunDialogOptions', () => { + it('says the credits are locked when the inactive account holds funds', () => { + expect(subscribeToRunDialogOptions({ hasFunds: true })).toEqual({ + reason: 'subscribe_to_run', + creditsLocked: true + }) + }) + + it.for([ + { name: 'no funds', subscription: { hasFunds: false } }, + { name: 'billing not loaded', subscription: null } + ])('opens the plain subscribe dialog with $name', ({ subscription }) => { + expect(subscribeToRunDialogOptions(subscription)).toEqual({ + reason: 'subscribe_to_run' + }) + }) +}) diff --git a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts new file mode 100644 index 00000000000..3675f731eb5 --- /dev/null +++ b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts @@ -0,0 +1,19 @@ +import type { + SubscriptionDialogOptions, + SubscriptionInfo +} from '@/platform/billing/composables/types' + +/** + * Options for the paywall opened by the client-side run block and the + * Subscribe to Run button. An inactive account that still holds credits gets + * the same locked-credits line as a server-refused run, so a top-up without a + * plan is explained on every path, not only after a 402. + */ +export function subscribeToRunDialogOptions( + subscription: Pick | null | undefined +): SubscriptionDialogOptions { + return { + reason: 'subscribe_to_run', + ...(subscription?.hasFunds === true && { creditsLocked: true }) + } +} From ef7e82d53a7cde5c1d8ead4a21cc1a2c5f4cf902 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 5 Nov 2026 06:58:38 +0000 Subject: [PATCH 2/6] test(billing): cloud e2e for the locked-credits line on Subscribe to Run Refs FRONT-3758 --- .../billing/cloudCreditsLockedRefusal.spec.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts b/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts index fc720012cf7..b5d1f3033f1 100644 --- a/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts +++ b/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts @@ -94,3 +94,45 @@ test.describe('Run refused for locked credits', { tag: '@cloud' }, () => { ).toHaveCount(0) }) }) + +test.describe( + 'Subscribe to Run for an inactive account', + { tag: '@cloud' }, + () => { + async function openFromSubscribeToRun(page: Page, hasFunds: boolean) { + await new CloudWorkspaceMockHelper(page).setup( + DEFAULT_TEAM_MEMBERS, + workspace('personal', 'owner'), + { ...PERSONAL_BILLING_STATUS, has_funds: hasFunds } + ) + await page.route('**/api/features', (route) => + route.fulfill(jsonRoute({ subscription_required: true })) + ) + await page.goto(APP_URL) + await waitForCloudApp(page) + + await page.getByTestId(TestIds.topbar.subscribeToRunButton).click() + await expect(page.getByRole('dialog')).toBeVisible({ timeout: 30_000 }) + } + + test('says why credits did not help when the account holds funds', async ({ + page + }) => { + await openFromSubscribeToRun(page, true) + + await expect( + page.getByTestId(TestIds.dialogs.creditsLockedNotice) + ).toContainText("Buying credits doesn't") + }) + + test('stays out of the dialog when the account has no funds', async ({ + page + }) => { + await openFromSubscribeToRun(page, false) + + await expect( + page.getByTestId(TestIds.dialogs.creditsLockedNotice) + ).toHaveCount(0) + }) + } +) From d1c1c7efa4a95ebbcb5ba9c43398ee86ab48c80a Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 5 Nov 2026 07:35:34 +0000 Subject: [PATCH 3/6] fix(billing): require an inactive plan for the Subscribe to Run locked-credits line The Subscribe to Run button shows whenever the account cannot run, which includes an active plan that is blocked for another reason. Only mark credits locked when billing reads inactive, and mark the client-side derivation as interim until billing status serves credits_locked (BE-24447). The e2e pins the ended-plan wording. Refs FRONT-3758 --- .../billing/cloudCreditsLockedRefusal.spec.ts | 10 ++++++++-- src/composables/useCoreCommands.test.ts | 1 + .../utils/subscribeToRunDialogOptions.test.ts | 10 ++++++++-- .../utils/subscribeToRunDialogOptions.ts | 14 ++++++++++++-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts b/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts index b5d1f3033f1..81214821c6e 100644 --- a/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts +++ b/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts @@ -103,7 +103,11 @@ test.describe( await new CloudWorkspaceMockHelper(page).setup( DEFAULT_TEAM_MEMBERS, workspace('personal', 'owner'), - { ...PERSONAL_BILLING_STATUS, has_funds: hasFunds } + { + ...PERSONAL_BILLING_STATUS, + subscription_state: 'ended', + has_funds: hasFunds + } ) await page.route('**/api/features', (route) => route.fulfill(jsonRoute({ subscription_required: true })) @@ -122,7 +126,9 @@ test.describe( await expect( page.getByTestId(TestIds.dialogs.creditsLockedNotice) - ).toContainText("Buying credits doesn't") + ).toHaveText( + "Buying credits doesn't restart your Cloud plan. Resubscribe to run workflows on Cloud." + ) }) test('stays out of the dialog when the account has no funds', async ({ diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index 10c363645a2..c223cf9ee70 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -186,6 +186,7 @@ vi.mock( return mockBillingState.subscriptionTier || mockBillingState.hasFunds ? { tier: mockBillingState.subscriptionTier, + isActive: false, hasFunds: mockBillingState.hasFunds } : null diff --git a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts index a08e3263c78..32c200ed24c 100644 --- a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts +++ b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts @@ -4,14 +4,20 @@ import { subscribeToRunDialogOptions } from './subscribeToRunDialogOptions' describe('subscribeToRunDialogOptions', () => { it('says the credits are locked when the inactive account holds funds', () => { - expect(subscribeToRunDialogOptions({ hasFunds: true })).toEqual({ + expect( + subscribeToRunDialogOptions({ isActive: false, hasFunds: true }) + ).toEqual({ reason: 'subscribe_to_run', creditsLocked: true }) }) it.for([ - { name: 'no funds', subscription: { hasFunds: false } }, + { name: 'no funds', subscription: { isActive: false, hasFunds: false } }, + { + name: 'an active plan that cannot run', + subscription: { isActive: true, hasFunds: true } + }, { name: 'billing not loaded', subscription: null } ])('opens the plain subscribe dialog with $name', ({ subscription }) => { expect(subscribeToRunDialogOptions(subscription)).toEqual({ diff --git a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts index 3675f731eb5..1900dea8a4d 100644 --- a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts +++ b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts @@ -2,6 +2,7 @@ import type { SubscriptionDialogOptions, SubscriptionInfo } from '@/platform/billing/composables/types' +import { pendingServerFact } from '@/platform/serverFacts/pendingServerFact' /** * Options for the paywall opened by the client-side run block and the @@ -10,10 +11,19 @@ import type { * plan is explained on every path, not only after a 402. */ export function subscribeToRunDialogOptions( - subscription: Pick | null | undefined + subscription: + | Pick + | null + | undefined ): SubscriptionDialogOptions { + // Interim: billing status does not yet serve `credits_locked`, which the + // 402 refusal carries (BE-24447). + const creditsLocked = pendingServerFact( + 'BE-24447', + subscription?.isActive === false && subscription.hasFunds + ) return { reason: 'subscribe_to_run', - ...(subscription?.hasFunds === true && { creditsLocked: true }) + ...(creditsLocked && { creditsLocked: true }) } } From 69daed959e8f136b75d1b32d68c4505f8215ceb4 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 5 Nov 2026 07:41:03 +0000 Subject: [PATCH 4/6] [automated] Apply ESLint and Oxfmt fixes --- .../billing/subscription/utils/subscribeToRunDialogOptions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts index 1900dea8a4d..acbf0233eba 100644 --- a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts +++ b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts @@ -20,7 +20,7 @@ export function subscribeToRunDialogOptions( // 402 refusal carries (BE-24447). const creditsLocked = pendingServerFact( 'BE-24447', - subscription?.isActive === false && subscription.hasFunds + subscription?.isActive === false && subscription.hasFunds ) return { reason: 'subscribe_to_run', From d30ac54f8844eb08327be15138d33b0eaf692e8a Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 5 Nov 2026 07:44:07 +0000 Subject: [PATCH 5/6] fix(billing): gate the Subscribe to Run locked-credits line on the served plan state Review: a funded account that is paused, past due or activating is inactive too, and the locked-credits line would send it to subscribe for the wrong reason. Show the line only when the server-owned subscription_state is never_subscribed or ended, as the Add credits dialog's plan line does. Shorten the helper JSDoc to its contract and split the e2e arrangement into beforeEach per case. Refs FRONT-3758 --- .../billing/cloudCreditsLockedRefusal.spec.ts | 71 +++++++++++-------- src/composables/useCoreCommands.test.ts | 8 +++ src/composables/useCoreCommands.ts | 8 ++- .../components/SubscribeToRun.test.ts | 3 +- .../components/SubscribeToRun.vue | 9 ++- .../utils/subscribeToRunDialogOptions.test.ts | 45 +++++++----- .../utils/subscribeToRunDialogOptions.ts | 31 ++++---- 7 files changed, 106 insertions(+), 69 deletions(-) diff --git a/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts b/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts index 81214821c6e..f978dd4ad55 100644 --- a/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts +++ b/browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts @@ -95,47 +95,60 @@ test.describe('Run refused for locked credits', { tag: '@cloud' }, () => { }) }) +async function arrangeEndedPlan(page: Page, hasFunds: boolean) { + await new CloudWorkspaceMockHelper(page).setup( + DEFAULT_TEAM_MEMBERS, + workspace('personal', 'owner'), + { + ...PERSONAL_BILLING_STATUS, + subscription_state: 'ended', + has_funds: hasFunds + } + ) + await page.route('**/api/features', (route) => + route.fulfill(jsonRoute({ subscription_required: true })) + ) +} + +async function clickSubscribeToRun(page: Page) { + await page.goto(APP_URL) + await waitForCloudApp(page) + await page.getByTestId(TestIds.topbar.subscribeToRunButton).click() +} + test.describe( - 'Subscribe to Run for an inactive account', + 'Subscribe to Run for an ended plan with funds', { tag: '@cloud' }, () => { - async function openFromSubscribeToRun(page: Page, hasFunds: boolean) { - await new CloudWorkspaceMockHelper(page).setup( - DEFAULT_TEAM_MEMBERS, - workspace('personal', 'owner'), - { - ...PERSONAL_BILLING_STATUS, - subscription_state: 'ended', - has_funds: hasFunds - } - ) - await page.route('**/api/features', (route) => - route.fulfill(jsonRoute({ subscription_required: true })) - ) - await page.goto(APP_URL) - await waitForCloudApp(page) - - await page.getByTestId(TestIds.topbar.subscribeToRunButton).click() - await expect(page.getByRole('dialog')).toBeVisible({ timeout: 30_000 }) - } + test.beforeEach(async ({ page }) => { + await arrangeEndedPlan(page, true) + }) - test('says why credits did not help when the account holds funds', async ({ - page - }) => { - await openFromSubscribeToRun(page, true) + test('says why credits did not help', async ({ page }) => { + await clickSubscribeToRun(page) await expect( page.getByTestId(TestIds.dialogs.creditsLockedNotice) ).toHaveText( - "Buying credits doesn't restart your Cloud plan. Resubscribe to run workflows on Cloud." + "Buying credits doesn't restart your Cloud plan. Resubscribe to run workflows on Cloud.", + { timeout: 30_000 } ) }) + } +) - test('stays out of the dialog when the account has no funds', async ({ - page - }) => { - await openFromSubscribeToRun(page, false) +test.describe( + 'Subscribe to Run for an ended plan without funds', + { tag: '@cloud' }, + () => { + test.beforeEach(async ({ page }) => { + await arrangeEndedPlan(page, false) + }) + test('stays out of the dialog', async ({ page }) => { + await clickSubscribeToRun(page) + + await expect(page.getByRole('dialog')).toBeVisible({ timeout: 30_000 }) await expect( page.getByTestId(TestIds.dialogs.creditsLockedNotice) ).toHaveCount(0) diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index c223cf9ee70..46f5d2db32a 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -155,6 +155,7 @@ const mockBillingState = vi.hoisted(() => ({ canAccessSubscriptionFeatures: true, subscriptionTier: null as string | null, hasFunds: false, + subscriptionState: null as string | null, initialized: true, routing: 'workspace' as 'workspace' | 'unknown', onInitialize: null as (() => void) | null @@ -181,6 +182,11 @@ vi.mock( return mockBillingState.canAccessSubscriptionFeatures } }, + subscriptionState: { + get value() { + return mockBillingState.subscriptionState + } + }, subscription: { get value() { return mockBillingState.subscriptionTier || mockBillingState.hasFunds @@ -259,6 +265,7 @@ describe('useCoreCommands', () => { mockBillingState.canAccessSubscriptionFeatures = true mockBillingState.subscriptionTier = null mockBillingState.hasFunds = false + mockBillingState.subscriptionState = null mockBillingState.initialized = true mockBillingState.routing = 'workspace' mockBillingState.onInitialize = null @@ -912,6 +919,7 @@ describe('useCoreCommands', () => { mockDistributionState.isCloud = true mockBillingState.canAccessSubscriptionFeatures = false mockBillingState.hasFunds = true + mockBillingState.subscriptionState = 'ended' await findCmd('Comfy.QueuePrompt').function() diff --git a/src/composables/useCoreCommands.ts b/src/composables/useCoreCommands.ts index dd02cea485b..8f936aa8720 100644 --- a/src/composables/useCoreCommands.ts +++ b/src/composables/useCoreCommands.ts @@ -92,6 +92,7 @@ export function useCoreCommands(): ComfyCommand[] { const { canAccessSubscriptionFeatures, subscription, + subscriptionState, isInitialized, initialize, type: billingType @@ -109,7 +110,12 @@ export function useCoreCommands(): ComfyCommand[] { duration: 5000 }) } else { - showSubscriptionDialog(subscribeToRunDialogOptions(subscription.value)) + showSubscriptionDialog( + subscribeToRunDialogOptions({ + subscriptionState: subscriptionState.value, + hasFunds: subscription.value?.hasFunds + }) + ) } return true } diff --git a/src/platform/billing/subscription/components/SubscribeToRun.test.ts b/src/platform/billing/subscription/components/SubscribeToRun.test.ts index 2b787a3ef91..e3964a36574 100644 --- a/src/platform/billing/subscription/components/SubscribeToRun.test.ts +++ b/src/platform/billing/subscription/components/SubscribeToRun.test.ts @@ -115,7 +115,8 @@ describe('SubscribeToRun', () => { ...context, subscription: computed(() => fromPartial({ isActive: false, hasFunds: true }) - ) + ), + subscriptionState: computed(() => 'never_subscribed' as const) }) const { user } = renderButton() diff --git a/src/platform/billing/subscription/components/SubscribeToRun.vue b/src/platform/billing/subscription/components/SubscribeToRun.vue index 4e065d8c113..de2e0527dd3 100644 --- a/src/platform/billing/subscription/components/SubscribeToRun.vue +++ b/src/platform/billing/subscription/components/SubscribeToRun.vue @@ -38,7 +38,7 @@ const breakpoints = useBreakpoints(breakpointsTailwind) const isMdOrLarger = breakpoints.greaterOrEqual('md') const { permissions } = useBillingUI() -const { subscription } = useBillingContext() +const { subscription, subscriptionState } = useBillingContext() const { showSubscriptionDialog } = useSubscriptionPaywall() const { trackRunButton } = useRunButtonTelemetry() @@ -62,6 +62,11 @@ function handleSubscribeToRun() { trackRunButton({ subscribe_to_run: true }) } - showSubscriptionDialog(subscribeToRunDialogOptions(subscription.value)) + showSubscriptionDialog( + subscribeToRunDialogOptions({ + subscriptionState: subscriptionState.value, + hasFunds: subscription.value?.hasFunds + }) + ) } diff --git a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts index 32c200ed24c..181818f5b2a 100644 --- a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts +++ b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.test.ts @@ -3,25 +3,36 @@ import { describe, expect, it } from 'vitest' import { subscribeToRunDialogOptions } from './subscribeToRunDialogOptions' describe('subscribeToRunDialogOptions', () => { - it('says the credits are locked when the inactive account holds funds', () => { - expect( - subscribeToRunDialogOptions({ isActive: false, hasFunds: true }) - ).toEqual({ - reason: 'subscribe_to_run', - creditsLocked: true - }) - }) + it.for(['never_subscribed', 'ended'] as const)( + 'says the credits are locked for a funded account in state %s', + (subscriptionState) => { + expect( + subscribeToRunDialogOptions({ subscriptionState, hasFunds: true }) + ).toEqual({ reason: 'subscribe_to_run', creditsLocked: true }) + } + ) it.for([ - { name: 'no funds', subscription: { isActive: false, hasFunds: false } }, { - name: 'an active plan that cannot run', - subscription: { isActive: true, hasFunds: true } + name: 'no funds', + subscriptionState: 'never_subscribed', + hasFunds: false }, - { name: 'billing not loaded', subscription: null } - ])('opens the plain subscribe dialog with $name', ({ subscription }) => { - expect(subscribeToRunDialogOptions(subscription)).toEqual({ - reason: 'subscribe_to_run' - }) - }) + { name: 'a paused plan', subscriptionState: 'paused', hasFunds: true }, + { name: 'a past-due plan', subscriptionState: 'past_due', hasFunds: true }, + { name: 'an active plan', subscriptionState: 'active', hasFunds: true }, + { name: 'an unknown state', subscriptionState: null, hasFunds: true }, + { + name: 'billing not loaded', + subscriptionState: null, + hasFunds: undefined + } + ] as const)( + 'opens the plain subscribe dialog with $name', + ({ subscriptionState, hasFunds }) => { + expect( + subscribeToRunDialogOptions({ subscriptionState, hasFunds }) + ).toEqual({ reason: 'subscribe_to_run' }) + } + ) }) diff --git a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts index acbf0233eba..1c8baecc8d8 100644 --- a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts +++ b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts @@ -1,26 +1,19 @@ -import type { - SubscriptionDialogOptions, - SubscriptionInfo -} from '@/platform/billing/composables/types' +import type { SubscriptionState } from '@comfyorg/ingest-types' + +import type { SubscriptionDialogOptions } from '@/platform/billing/composables/types' import { pendingServerFact } from '@/platform/serverFacts/pendingServerFact' -/** - * Options for the paywall opened by the client-side run block and the - * Subscribe to Run button. An inactive account that still holds credits gets - * the same locked-credits line as a server-refused run, so a top-up without a - * plan is explained on every path, not only after a 402. - */ -export function subscribeToRunDialogOptions( - subscription: - | Pick - | null - | undefined -): SubscriptionDialogOptions { - // Interim: billing status does not yet serve `credits_locked`, which the - // 402 refusal carries (BE-24447). +/** Subscribe to Run paywall options; flags locked credits for a funded account with no plan. */ +export function subscribeToRunDialogOptions(facts: { + subscriptionState: SubscriptionState | null + hasFunds: boolean | undefined +}): SubscriptionDialogOptions { + // Interim until billing status serves `credits_locked` (BE-24447). const creditsLocked = pendingServerFact( 'BE-24447', - subscription?.isActive === false && subscription.hasFunds + facts.hasFunds === true && + (facts.subscriptionState === 'never_subscribed' || + facts.subscriptionState === 'ended') ) return { reason: 'subscribe_to_run', From 258f497fc77e8cd9f914bece5e22735cc220307a Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 5 Nov 2026 07:47:11 +0000 Subject: [PATCH 6/6] refactor(billing): drop the interim comment; the ticket stays on pendingServerFact Refs FRONT-3758 --- .../billing/subscription/utils/subscribeToRunDialogOptions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts index 1c8baecc8d8..e600b5c6dcc 100644 --- a/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts +++ b/src/platform/billing/subscription/utils/subscribeToRunDialogOptions.ts @@ -8,7 +8,6 @@ export function subscribeToRunDialogOptions(facts: { subscriptionState: SubscriptionState | null hasFunds: boolean | undefined }): SubscriptionDialogOptions { - // Interim until billing status serves `credits_locked` (BE-24447). const creditsLocked = pendingServerFact( 'BE-24447', facts.hasFunds === true &&