Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -3683,6 +3683,11 @@
"body": "Your plan will renew on {date}. You can cancel again anytime.",
"title": "Resume your {plan} plan?"
},
"salesManaged": {
"line": "Billed by contract.",
"renews": "Billed by contract. Renews {date}.",
"title": "Enterprise"
},
"scheduledChange": "Changes to {plan} on {date}.",
"stayConfirm": {
"body": "Your plan won't change to {plan} on {date}. You can schedule a change again anytime.",
Expand Down Expand Up @@ -3758,7 +3763,7 @@
"title": "Payment received"
},
"verifyPayment": {
"action": "Verify your payment",
"action": "Complete verification",
"body": "Your bank requires additional verification to complete this payment.",
"title": "Verify your payment"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function renderBanner(banner: PlanCheckoutBanner) {
}

describe('BillingPlanCheckoutBanner', () => {
it('links the bank check when the operation serves an action url', () => {
it('links the bank check from a white Complete verification action with no Dismiss', () => {
renderBanner({
kind: 'verifyPayment',
opId: 'op-1',
Expand All @@ -35,24 +35,45 @@ describe('BillingPlanCheckoutBanner', () => {
expect(screen.getByRole('status')).toHaveTextContent(
'Your bank requires additional verification to complete this payment.'
)
const action = screen.getByRole('link', { name: 'Complete verification' })
expect(action).toHaveAttribute('href', 'https://pay.example/verify')
expect(action).toHaveAttribute('data-variant', 'inverted')
expect(
screen.getByRole('link', { name: 'Verify your payment' })
).toHaveAttribute('href', 'https://pay.example/verify')
screen.queryByRole('button', { name: 'Dismiss' })
).not.toBeInTheDocument()
})

it('uses the 12px banner shell with md buttons', () => {
renderBanner({
kind: 'verifyPayment',
opId: 'op-1',
actionUrl: 'https://pay.example/verify'
})
it.for<{
case: string
banner: PlanCheckoutBanner
role: 'link' | 'button'
name: string
}>([
{
case: 'the verify action',
banner: {
kind: 'verifyPayment',
opId: 'op-1',
actionUrl: 'https://pay.example/verify'
},
role: 'link',
name: 'Complete verification'
},
{
case: 'Dismiss',
banner: { kind: 'paymentReceived', opId: 'op-1' },
role: 'button',
name: 'Dismiss'
}
])(
'uses the 12px banner shell with an md $case',
({ banner, role, name }) => {
renderBanner(banner)

expect(screen.getByRole('status')).toHaveClass('rounded-xl', 'p-3')
expect(screen.getByRole('button', { name: 'Dismiss' })).toHaveClass('h-8')
expect(
screen.getByRole('link', { name: 'Verify your payment' })
).toHaveClass('h-8')
})
expect(screen.getByRole('status')).toHaveClass('rounded-xl', 'p-3')
expect(screen.getByRole(role, { name })).toHaveClass('h-8')
}
)

it('shows verify payment with no link when the operation omits action_url', () => {
renderBanner({ kind: 'verifyPayment', opId: 'op-1', actionUrl: null })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
<p class="m-0 pl-6 text-sm text-muted-foreground">{{ copy?.body }}</p>
</div>
<div class="flex shrink-0 flex-wrap items-center gap-2 pl-6 sm:pl-0">
<Button variant="textonly" size="md" @click="emit('dismiss')">
<Button
v-if="banner.kind !== 'verifyPayment'"
variant="textonly"
size="md"
@click="emit('dismiss')"
>
{{ $t('workspacePanel.billingStatus.planCheckout.dismiss') }}
</Button>
<Button
Expand All @@ -32,7 +37,7 @@
:href="banner.actionUrl"
target="_blank"
rel="noopener"
variant="secondary"
variant="inverted"
size="md"
class="no-underline"
>
Expand Down
12 changes: 12 additions & 0 deletions src/platform/billing/components/billingTab/BillingPlanRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ const title = computed(() => {
if (state.kind === 'unknown') {
return t('workspacePanel.billingTab.plan.unknown.title')
}
if (state.kind === 'salesManaged') {
return (
state.planName ?? t('workspacePanel.billingTab.plan.salesManaged.title')
)
}
return state.planName
})

Expand Down Expand Up @@ -119,6 +124,13 @@ const statusLine = computed(() => {
}
if (state.kind === 'active') return activeLine(state)
if (state.kind === 'noPlan') return noPlanLine(state)
if (state.kind === 'salesManaged') {
return state.renewsAt
? t(`${key}.salesManaged.renews`, {
date: formatPlanDate(state.renewsAt, locale.value, state.cadence)
})
: t(`${key}.salesManaged.line`)
}
if (state.kind === 'ending') {
return t(`${key}.ending`, {
date: formatPlanDate(state.endsAt, locale.value, state.cadence)
Expand Down
46 changes: 46 additions & 0 deletions src/platform/billing/components/billingTab/BillingTab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,52 @@ describe('BillingTab', () => {
}
)

it.for([
{
case: 'a served renewal date',
renewalDate: '2027-10-28T00:00:00Z',
line: 'Billed by contract. Renews October 28, 2027.'
},
{
case: 'no renewal date',
renewalDate: null,
line: 'Billed by contract.'
}
])(
'shows an active sales-managed plan as Enterprise with $case',
({ renewalDate, line }) => {
arrange({
planKind: 'sales_managed',
canOpenPlans: false,
subscription: {
...activeSubscription,
tier: 'ENTERPRISE',
duration: 'ANNUAL',
renewalDate
}
})

expect(
screen.getByRole('heading', { name: 'Enterprise' })
).toBeInTheDocument()
expect(screen.getByTestId('billing-plan-line').textContent.trim()).toBe(
line
)
expect(
screen.getByRole('link', { name: 'Contact sales' })
).toHaveAttribute('href', 'https://comfy.org/contact/')
}
)

it('picks the contract-billing row by plan_kind and keeps the served plan name on a PRO tier', () => {
arrange({ planKind: 'sales_managed', canOpenPlans: false })

expect(screen.getByRole('heading', { name: 'Pro' })).toBeInTheDocument()
expect(screen.getByTestId('billing-plan-line').textContent.trim()).toBe(
'Billed by contract. Renews November 15.'
)
})

it('opens plan management on Cloud instead of a platform plans page', async () => {
arrange()

Expand Down
56 changes: 55 additions & 1 deletion src/platform/billing/components/billingTab/planRow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const baseFacts: PlanRowFacts = {
renewalDate: '2026-11-15T00:00:00Z',
endDate: null,
scheduledChange: null,
freeRuns: null
freeRuns: null,
planKind: 'self_serve'
}

describe('derivePlanRow', () => {
Expand Down Expand Up @@ -166,6 +167,59 @@ describe('derivePlanRow', () => {
case: 'an ended plan without an end date',
facts: { subscriptionStatus: 'ended' },
expected: { kind: 'unknown' }
},
{
case: 'an active sales-managed plan with no served plan name',
facts: { planKind: 'sales_managed', planName: null, duration: null },
expected: {
kind: 'salesManaged',
planName: null,
cadence: null,
renewsAt: '2026-11-15T00:00:00Z'
}
},
{
case: 'an active sales-managed plan without a renewal date',
facts: { planKind: 'sales_managed', planName: null, renewalDate: null },
expected: {
kind: 'salesManaged',
planName: null,
cadence: 'monthly',
renewsAt: null
}
},
{
case: 'a paused sales-managed plan with no served plan name',
facts: {
planKind: 'sales_managed',
billingStatus: 'paused',
planName: null
},
expected: { kind: 'unknown' }
},
{
case: 'a canceled sales-managed plan',
facts: {
planKind: 'sales_managed',
subscriptionStatus: 'canceled',
endDate: '2026-12-01T00:00:00Z'
},
expected: {
kind: 'ending',
planName: 'Pro',
cadence: 'monthly',
endsAt: '2026-12-01T00:00:00Z'
}
},
{
case: 'an ended sales-managed plan with no served plan name',
facts: {
planKind: 'sales_managed',
subscriptionStatus: 'ended',
planName: null,
endDate: '2026-09-01T00:00:00Z'
},
expected: { kind: 'unknown' }
}
])('maps $case', ({ facts, expected }) => {
expect(derivePlanRow({ ...baseFacts, ...facts })).toEqual(expected)
Expand Down
29 changes: 29 additions & 0 deletions src/platform/billing/components/billingTab/planRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface PlanRowFacts {
endDate: string | null
scheduledChange: { planName: string; effectiveAt: string } | null
freeRuns: { remaining: number; total: number } | null
planKind: PlanKind | null
}

export type PlanRowState =
Expand Down Expand Up @@ -48,6 +49,12 @@ export type PlanRowState =
kind: 'noPlan'
freeRuns: { remaining: number; total: number } | null
}
| {
kind: 'salesManaged'
planName: string | null
cadence: BillingCadence | null
renewsAt: string | null
}
| { kind: 'unknown' }

export type PlanRowAction =
Expand All @@ -72,6 +79,25 @@ function toCadence(
return null
}

function salesManagedRow(facts: PlanRowFacts): PlanRowState | null {
if (facts.planKind !== 'sales_managed') return null
switch (facts.billingStatus) {
case 'paused':
return null
}
switch (facts.subscriptionStatus) {
case 'active':
return {
kind: 'salesManaged',
planName: facts.planName,
cadence: toCadence(facts.duration),
renewsAt: facts.renewalDate
}
default:
return null
}
}

/** Maps the served status fields onto the plan row; whatever they cannot render is `unknown`. */
export function derivePlanRow(facts: PlanRowFacts): PlanRowState {
const { subscriptionStatus, planName, renewalDate, endDate } = facts
Expand All @@ -81,6 +107,8 @@ export function derivePlanRow(facts: PlanRowFacts): PlanRowState {
if (subscriptionStatus === null) {
return { kind: 'noPlan', freeRuns: facts.freeRuns }
}
const salesManaged = salesManagedRow(facts)
if (salesManaged) return salesManaged
if (planName === null) return UNKNOWN
switch (facts.billingStatus) {
case 'paused':
Expand Down Expand Up @@ -131,6 +159,7 @@ export function planRowAction(
case 'ended':
return 'choosePlan'
case 'ending':
case 'salesManaged':
return null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { isSalesManagedTier } from '@/platform/billing/subscription/constants/ti
import type { SubscriptionTier } from '@/platform/workspace/api/workspaceApi'
import { resolveSubscriptionTierKey } from '@/platform/billing/components/subscriptionPanelWorkspace.logic'
import { derivePlanRow } from '@/platform/billing/components/billingTab/planRow'
import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
import { useScheduledPlanChange } from '@/platform/billing/composables/useScheduledPlanChange'

export function useBillingPlanRow() {
Expand All @@ -20,6 +21,7 @@ export function useBillingPlanRow() {
} = useBillingContext()
const { quotaEnabled, available, maxAvailable } = useFreeTierQuota()
const scheduled = useScheduledPlanChange()
const { planKind } = useBillingCapabilities()

function planNameFor(tier: SubscriptionTier | null): string | null {
if (tier === null || isSalesManagedTier(tier)) return null
Expand Down Expand Up @@ -55,7 +57,8 @@ export function useBillingPlanRow() {
subscriptionState: subscriptionState.value,
billingStatus: billingStatus.value,
scheduledChange: scheduledChange.value,
freeRuns: freeRuns.value
freeRuns: freeRuns.value,
planKind: planKind.value
})
)

Expand Down
Loading