Skip to content
Merged
1 change: 1 addition & 0 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
120 changes: 120 additions & 0 deletions src/platform/account/components/dialogs/settings/BillingTab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } })

Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
)

it('offers no Add credits on a failed top-up when the server withholds can_top_up', async () => {
servedCheckouts(checkout('failed'))
arrange({ canTopUp: false })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<BillingStatusBanner section="billing" />
<BillingLocalCreditBanner
:suppressed="suppressCreditBanner"
:add-credits-variant="addCreditsVariant"
:add-credits-variant="creditBannerAddCreditsVariant"
/>
<section class="flex flex-col gap-3" data-testid="billing-plan-section">
<h2 class="m-0 text-base font-medium text-foreground">
Expand Down Expand Up @@ -59,6 +59,7 @@
:state="planRow"
:action="action"
:sales-variant="salesVariant"
:add-credits-variant="addCreditsVariant"
:can-manage-subscription="capabilities.canManageSubscription.value"
/>
</section>
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
)
Expand Down
27 changes: 20 additions & 7 deletions src/platform/billing/components/billingTab/BillingPlanRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand All @@ -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')
Expand Down Expand Up @@ -124,6 +133,14 @@ function noPlanLine(state: Extract<PlanRowState, { kind: 'noPlan' }>) {
: t(`${key}.freeRunsUsed`, { total })
}

function endedLine(state: Extract<PlanRowState, { kind: 'ended' }>) {
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') {
Expand All @@ -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 ''
})

Expand Down
76 changes: 74 additions & 2 deletions src/platform/billing/components/billingTab/planRow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading