From bd4898ca88704131175f30ad8392dd47fcf4a2ff Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Fri, 13 Nov 2026 01:47:51 +0000 Subject: [PATCH 1/2] fix(billing): hide auto top-up while billing is paused (#23323) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Per [DES-1240](https://linear.app/comfyorg/issue/DES-1240) (Not available row) and Alex's call in the #23278 review thread, auto top-up is hidden with no Turn on while a plan is paused. Cloud still offered Turn on for `auto_top_up_setup` frozen with `billing_paused`; Platform already offered no action. - **Why:** auto top-up can't charge while billing is paused. It comes back as it was once the payment goes through. - **Root cause:** `canSetUpAutoTopUp` only treated `payment_past_due` as paused. The account-ui card hid only `state: 'unavailable'`. - **How:** account-core adds `isAutoTopUpNotAvailable(setup)`. It returns true when setup is `unavailable`, or `frozen` for `payment_past_due` or `billing_paused`. - `canSetUpAutoTopUp` uses it, which covers the top-up dialog's Set up offer and the Add credits suggestion. - The account-ui `BillingAutoTopUpCard` hides on it, and so does the card-viewed event. - `TopUpAutoTopUpCard` reads `canSetUpAutoTopUp` instead of its inline copy. This is the same swap as #23278, so whichever PR lands second needs a trivial rebase. - Server facts: the rule renders the served setup state and reason. It does not combine them with role, plan or tier. - The 1.60 code under `legacy160` is unchanged. | | AS IS | TO BE | |---|---|---| | setup frozen, `billing_paused` | card shows Off · Turn on ↗; dialog offers Set up | card hidden; no Set up offer | | setup frozen, `payment_past_due` | card shown; no Set up offer | card hidden; no Set up offer | ```mermaid graph LR A[#23278 platformAutoTopUpPath] -. touches same lines of TopUpAutoTopUpCard .- B[this PR] ``` ## Verification - `vitest`: account-core `autoTopUpCard` and `addCredits` (230 passed); account-ui `BillingAutoTopUpCard` (19 passed); app `TopUpAutoTopUpCard`, `useAutoTopUpCardSection`, `useAutoTopUpSetupOffer` (71 passed). - Mutation check: I dropped `billing_paused` from the rule and re-ran. The new card case and the new `TopUpAutoTopUpCard` case both failed, then passed once I restored it. - Not checked against a live backend in the paused state. (cherry picked from commit 4d07c599b5cfe69167fa4d4bf4717115343dc525) # Conflicts: # packages/account-core/src/core/billing/billingTab/autoTopUpCard.test.ts # packages/account-core/src/core/billing/billingTab/autoTopUpCard.ts # packages/account-core/src/core/billing/index.ts # packages/account-ui/src/billing/tab/BillingAutoTopUpCard.test.ts # packages/account-ui/src/billing/tab/BillingAutoTopUpCard.vue # src/platform/billing/composables/useAutoTopUpCardSection.ts --- .../src/core/billing/capabilities.test.ts | 25 +++++++++++++++++++ .../src/core/billing/capabilities.ts | 13 ++++++++++ .../account-core/src/core/billing/index.ts | 1 + .../components/TopUpAutoTopUpCard.test.ts | 16 ++++++++---- .../billing/components/TopUpAutoTopUpCard.vue | 4 +-- .../billingTab/BillingAutoTopUpCard.test.ts | 11 ++++---- .../billingTab/BillingAutoTopUpCard.vue | 5 ++-- 7 files changed, 61 insertions(+), 14 deletions(-) diff --git a/packages/account-core/src/core/billing/capabilities.test.ts b/packages/account-core/src/core/billing/capabilities.test.ts index beeecc27e8d..a2186d7caf1 100644 --- a/packages/account-core/src/core/billing/capabilities.test.ts +++ b/packages/account-core/src/core/billing/capabilities.test.ts @@ -1,3 +1,4 @@ +import type { AutoTopUpSetup } from '@comfyorg/ingest-types' import { describe, expect, it, vi } from 'vitest' import type { SessionSnapshot } from '#/core/session' @@ -7,6 +8,7 @@ import type { BillingSession, BillingTransport } from './billingContracts' import { CAPABILITY_REVISION_HEADER, createCapabilitiesReader, + isAutoTopUpNotAvailable, readCapabilityRevision } from './capabilities' import { createSessionBillingTransport } from './transport' @@ -763,3 +765,26 @@ describe('readCapabilityRevision', () => { expect(readCapabilityRevision(() => value)).toBeUndefined() }) }) + +describe('isAutoTopUpNotAvailable', () => { + it.for<{ setup: AutoTopUpSetup | null; hidden: boolean }>([ + { setup: null, hidden: false }, + { setup: { state: 'ready' }, hidden: false }, + { + setup: { state: 'frozen', reason: 'default_payment_method_missing' }, + hidden: false + }, + { + setup: { state: 'frozen', reason: 'billing_payment_pending' }, + hidden: false + }, + { setup: { state: 'frozen', reason: 'billing_paused' }, hidden: true }, + { setup: { state: 'frozen', reason: 'payment_past_due' }, hidden: true }, + { + setup: { state: 'unavailable', reason: 'billing_rail_not_supported' }, + hidden: true + } + ])('reads setup $setup as hidden: $hidden', ({ setup, hidden }) => { + expect(isAutoTopUpNotAvailable(setup)).toBe(hidden) + }) +}) diff --git a/packages/account-core/src/core/billing/capabilities.ts b/packages/account-core/src/core/billing/capabilities.ts index 064f05fd598..89f1c94386e 100644 --- a/packages/account-core/src/core/billing/capabilities.ts +++ b/packages/account-core/src/core/billing/capabilities.ts @@ -12,6 +12,7 @@ * push concerns that need a document and a scheduler, so they belong to the * view package that has both — not to a framework-free core. */ +import type { AutoTopUpSetup } from '@comfyorg/ingest-types' import { zBillingCapabilities, zBillingCapabilitiesResponse, @@ -247,3 +248,15 @@ export function createCapabilitiesReader( dispose: reader.dispose } } + +const PAUSED_PLAN_REASONS: ReadonlySet = new Set([ + 'payment_past_due', + 'billing_paused' +]) + +/** Auto top-up is hidden on every surface while setup is unavailable or frozen for a paused plan. */ +export function isAutoTopUpNotAvailable(setup: AutoTopUpSetup | null): boolean { + if (setup === null) return false + if (setup.state === 'unavailable') return true + return setup.state === 'frozen' && PAUSED_PLAN_REASONS.has(setup.reason) +} diff --git a/packages/account-core/src/core/billing/index.ts b/packages/account-core/src/core/billing/index.ts index 0f9f4420f97..072ce2e3073 100644 --- a/packages/account-core/src/core/billing/index.ts +++ b/packages/account-core/src/core/billing/index.ts @@ -45,6 +45,7 @@ export { CAPABILITIES_ROUTE, CAPABILITY_REVISION_HEADER, createCapabilitiesReader, + isAutoTopUpNotAvailable, readCapabilityRevision } from './capabilities' export type { diff --git a/src/platform/billing/components/TopUpAutoTopUpCard.test.ts b/src/platform/billing/components/TopUpAutoTopUpCard.test.ts index 882a192c2b6..1208384f540 100644 --- a/src/platform/billing/components/TopUpAutoTopUpCard.test.ts +++ b/src/platform/billing/components/TopUpAutoTopUpCard.test.ts @@ -97,11 +97,17 @@ describe('TopUpAutoTopUpCard', () => { expect(screen.queryByText(PROMPT)).toBeNull() }) - it('stays shown while setup is frozen for another reason', () => { - renderCard({ setup: { state: 'frozen', reason: 'billing_paused' } }) - - expect(screen.getByText(PROMPT)).toBeInTheDocument() - }) + it.for([ + { reason: 'billing_paused', shown: false }, + { reason: 'default_payment_method_missing', shown: true } + ] as const)( + 'shows the prompt: $shown while setup is frozen for $reason', + ({ reason, shown }) => { + renderCard({ setup: { state: 'frozen', reason } }) + + expect(screen.queryByText(PROMPT) !== null).toBe(shown) + } + ) it('reads the auto top-up status only when the served facts allow setup', () => { renderCard({ canManage: false }) diff --git a/src/platform/billing/components/TopUpAutoTopUpCard.vue b/src/platform/billing/components/TopUpAutoTopUpCard.vue index b31c83c10df..8afc719747f 100644 --- a/src/platform/billing/components/TopUpAutoTopUpCard.vue +++ b/src/platform/billing/components/TopUpAutoTopUpCard.vue @@ -23,6 +23,7 @@