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 @@