From d7de003df2f77d9f782327d81d1da7561e336d14 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Thu, 12 Nov 2026 15:17:59 -0500 Subject: [PATCH] fix(billing): hide auto top-up while billing is paused Auto top-up can't charge while a plan is paused, so DES-1240's Not available row hides the card and offers no Turn on on every surface. account-core now owns that rule as isAutoTopUpNotAvailable: setup unavailable, or frozen for payment_past_due or billing_paused. The Billing tab card, its viewed event, the top-up dialog's Set up offer and the Add credits suggestion all read it. --- .../billing/billingTab/autoTopUpCard.test.ts | 33 +++++++++++++++++-- .../core/billing/billingTab/autoTopUpCard.ts | 18 +++++++--- .../account-core/src/core/billing/index.ts | 1 + .../billing/tab/BillingAutoTopUpCard.test.ts | 10 +++--- .../src/billing/tab/BillingAutoTopUpCard.vue | 3 +- .../components/TopUpAutoTopUpCard.test.ts | 16 ++++++--- .../billing/components/TopUpAutoTopUpCard.vue | 15 +++++---- .../composables/useAutoTopUpCardSection.ts | 7 ++-- 8 files changed, 78 insertions(+), 25 deletions(-) diff --git a/packages/account-core/src/core/billing/billingTab/autoTopUpCard.test.ts b/packages/account-core/src/core/billing/billingTab/autoTopUpCard.test.ts index 0aa1c33a8c2..a6032438a16 100644 --- a/packages/account-core/src/core/billing/billingTab/autoTopUpCard.test.ts +++ b/packages/account-core/src/core/billing/billingTab/autoTopUpCard.test.ts @@ -1,11 +1,12 @@ -import type { AutoReloadSettings } from '@comfyorg/ingest-types' +import type { AutoReloadSettings, AutoTopUpSetup } from '@comfyorg/ingest-types' import { describe, expect, it } from 'vitest' import { autoTopUpOffView, canSetUpAutoTopUp, deriveAutoTopUpCard, - deriveAutoTopUpSection + deriveAutoTopUpSection, + isAutoTopUpNotAvailable } from './autoTopUpCard' import type { AutoTopUpSectionFacts, @@ -170,8 +171,36 @@ describe('canSetUpAutoTopUp', () => { name: 'a setup frozen for past due', facts: { setup: { state: 'frozen', reason: 'payment_past_due' } }, can: false + }, + { + name: 'a setup frozen for paused billing', + facts: { setup: { state: 'frozen', reason: 'billing_paused' } }, + can: false } ])('$name: $can', ({ facts, can }) => { expect(canSetUpAutoTopUp({ ...manager, ...facts })).toBe(can) }) }) + +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/billingTab/autoTopUpCard.ts b/packages/account-core/src/core/billing/billingTab/autoTopUpCard.ts index d64150f545b..3f45b389fb7 100644 --- a/packages/account-core/src/core/billing/billingTab/autoTopUpCard.ts +++ b/packages/account-core/src/core/billing/billingTab/autoTopUpCard.ts @@ -46,12 +46,22 @@ export interface AutoTopUpSetupFacts { setup: AutoTopUpSetup | null } -/** Platform Billing's Turn on block: served `auto_top_up_enabled` and `can_manage_auto_top_up`, and a setup neither unavailable nor frozen for past due. */ +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) +} + +/** Platform Billing's Turn on block: served `auto_top_up_enabled` and `can_manage_auto_top_up`, and a served setup that is not Not available. */ export function canSetUpAutoTopUp(facts: AutoTopUpSetupFacts): boolean { if (!facts.autoTopUpEnabled || !facts.canManageAutoTopUp) return false - const { setup } = facts - if (setup === null || setup.state === 'unavailable') return false - return !(setup.state === 'frozen' && setup.reason === 'payment_past_due') + return facts.setup !== null && !isAutoTopUpNotAvailable(facts.setup) } export type AutoTopUpOffView = diff --git a/packages/account-core/src/core/billing/index.ts b/packages/account-core/src/core/billing/index.ts index be7a5b4b4b8..3aac03f39ce 100644 --- a/packages/account-core/src/core/billing/index.ts +++ b/packages/account-core/src/core/billing/index.ts @@ -425,6 +425,7 @@ export type { export { autoTopUpOffView, canSetUpAutoTopUp, + isAutoTopUpNotAvailable, deriveAutoTopUpCard, deriveAutoTopUpSection } from './billingTab/autoTopUpCard' diff --git a/packages/account-ui/src/billing/tab/BillingAutoTopUpCard.test.ts b/packages/account-ui/src/billing/tab/BillingAutoTopUpCard.test.ts index 14177028302..93f43eb94ab 100644 --- a/packages/account-ui/src/billing/tab/BillingAutoTopUpCard.test.ts +++ b/packages/account-ui/src/billing/tab/BillingAutoTopUpCard.test.ts @@ -252,10 +252,12 @@ describe('BillingAutoTopUpCard', () => { expect(onRetry).toHaveBeenCalledOnce() }) - it('renders nothing when the server marks setup unavailable', () => { - renderCard(loaded(), { - setup: { state: 'unavailable', reason: 'billing_rail_not_supported' } - }) + it.for([ + { state: 'unavailable', reason: 'billing_rail_not_supported' }, + { state: 'frozen', reason: 'billing_paused' }, + { state: 'frozen', reason: 'payment_past_due' } + ] as const)('renders nothing when setup is $state for $reason', (setup) => { + renderCard(loaded({ status: 'on' }), { setup }) expect(screen.queryByTestId('billing-auto-top-up-card')).toBeNull() }) diff --git a/packages/account-ui/src/billing/tab/BillingAutoTopUpCard.vue b/packages/account-ui/src/billing/tab/BillingAutoTopUpCard.vue index dccaeb6cf3b..2f0bb3dad8d 100644 --- a/packages/account-ui/src/billing/tab/BillingAutoTopUpCard.vue +++ b/packages/account-ui/src/billing/tab/BillingAutoTopUpCard.vue @@ -1,6 +1,6 @@