Skip to content
12 changes: 10 additions & 2 deletions browser_tests/tests/billing/localWebBillingHandoff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test.describe('Local web billing handoff', () => {
await expect(page.getByRole('dialog')).toHaveCount(0)
})

test('shows the Billing tab in Settings instead of Plan & Credits', async ({
test('shows the Billing tab without Platform links instead of Plan & Credits', async ({
comfyPage,
cloudFlagReads
}) => {
Expand All @@ -102,7 +102,15 @@ test.describe('Local web billing handoff', () => {
)

await settings.category('Billing', { exact: true }).click()
await expect(comfyPage.page.getByTestId('billing-tab')).toBeVisible()
const billingTab = comfyPage.page.getByTestId('billing-tab')
await expect(billingTab).toBeVisible()
await expect(billingTab.getByTestId('billing-handoff')).toHaveCount(0)
await expect(billingTab.locator('a[href*="/profile/"]')).toHaveCount(0)
await expect(
billingTab
.getByTestId('billing-plan-section')
.getByRole('button', { name: /plan/i })
).toHaveCount(0)
await expect(
settings.category('Plan & Credits', { exact: true })
).toHaveCount(0)
Expand Down
18 changes: 18 additions & 0 deletions packages/account-ui/src/billing/tab/BillingAutoTopUpCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ describe('BillingAutoTopUpCard', () => {
)
})

it('keeps the status but no action when the host hides it', () => {
render(BillingAutoTopUpCard, {
props: {
state: loaded({ status: 'failed' }),
offView: 'off',
setup: null,
copy: autoTopUpCardCopy,
locale: 'en',
actionHref: 'https://billing.test/profile/billing',
actionHidden: true
}
})

expect(screen.getByTestId('billing-auto-top-up-status')).toBeTruthy()
expect(screen.queryByRole('link')).toBeNull()
expect(screen.queryByRole('button')).toBeNull()
})

it('opens the host link in a new tab and reports the action', async () => {
const onAction = vi.fn()
render(BillingAutoTopUpCard, {
Expand Down
23 changes: 8 additions & 15 deletions packages/account-ui/src/billing/tab/BillingAutoTopUpCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,13 @@
{{ copy.status[view.status] }}
</span>
</h3>
<p
v-for="line in view.lines"
:key="line.text"
:class="
cn(
'm-0 flex items-center gap-1 text-sm text-muted-foreground',
classes?.line
)
"
data-testid="billing-auto-top-up-line"
>
{{ line.text }}
<BillingInfoTip v-if="line.tooltip" :text="line.tooltip" />
</p>
<BillingAutoTopUpLines
:lines="view.lines"
:line-class="classes?.line"
/>
</div>
<slot
v-if="!actionHidden"
name="action"
:action="view.action"
:label="copy.actions[view.actionLabel]"
Expand Down Expand Up @@ -120,7 +111,7 @@ import { cn } from '@comfyorg/tailwind-utils'

import CheckoutButton from '#/billing/checkout/CheckoutButton.vue'
import BillingBannerActionButton from './BillingBannerActionButton.vue'
import BillingInfoTip from './BillingInfoTip.vue'
import BillingAutoTopUpLines from './BillingAutoTopUpLines.vue'
import { autoTopUpCardView } from './autoTopUpCardView'
import type { AutoTopUpCardCopy, AutoTopUpViewKey } from './autoTopUpCardView'

Expand Down Expand Up @@ -162,6 +153,7 @@ const {
copy,
locale,
actionHref = null,
actionHidden = false,
variants,
classes
} = defineProps<{
Expand All @@ -171,6 +163,7 @@ const {
copy: AutoTopUpCardCopy
locale: string
actionHref?: string | null
actionHidden?: boolean
variants?: Partial<Record<AutoTopUpViewKey, ActionVariant>>
classes?: Partial<
Record<
Expand Down
25 changes: 25 additions & 0 deletions packages/account-ui/src/billing/tab/BillingAutoTopUpLines.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template>
<p
v-for="line in lines"
:key="line.text"
:class="
cn('m-0 flex items-center gap-1 text-sm text-muted-foreground', lineClass)
"
data-testid="billing-auto-top-up-line"
>
{{ line.text }}
<BillingInfoTip v-if="line.tooltip" :text="line.tooltip" />
</p>
</template>

<script setup lang="ts">
import { cn } from '@comfyorg/tailwind-utils'

import BillingInfoTip from './BillingInfoTip.vue'
import type { AutoTopUpLine } from './autoTopUpCardView'

const { lines, lineClass } = defineProps<{
lines: readonly AutoTopUpLine[]
lineClass?: string
}>()
</script>
4 changes: 2 additions & 2 deletions packages/account-ui/src/billing/tab/billingBannerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export type BillingBannerView = BillingBannerText &
}
| {
readonly kind: 'autoTopUp'
readonly action: 'updatePayment'
readonly href: string
readonly action: 'updatePayment' | null
readonly href: string | null
}
| {
readonly kind: 'credit'
Expand Down
2 changes: 2 additions & 0 deletions src/__mocks__/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { vi } from 'vitest'
import { ref } from 'vue'
import type { st as realSt, t as realT } from '@/i18n'

export const t = vi.fn<typeof realT>((key) => String(key))
export const st = vi.fn<typeof realSt>(
(key, fallbackMessage) => fallbackMessage || key
)
export const i18n = { global: { locale: ref('en') } }
75 changes: 16 additions & 59 deletions src/platform/account/components/dialogs/settings/BillingTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<BillingPlanRow
v-else
:state="planRow"
:action
:action="shownPlanAction"
:copy="planRowCopy"
:locale
:sales-variant="salesVariant"
Expand Down Expand Up @@ -134,6 +134,7 @@
:copy="autoTopUpCardCopy"
:locale
:action-href="autoTopUpHref"
:action-hidden="!autoTopUpAvailable"
@action="trackAutoTopUp"
@retry="retryAutoTopUp"
/>
Expand All @@ -146,49 +147,7 @@
</section>

<div class="flex flex-col gap-6">
<section class="flex flex-col gap-3" data-testid="billing-handoff">
<h2 class="m-0 text-base font-medium text-foreground">
{{ $t(`workspacePanel.billingTab.handoff.${handoffAudience}.label`) }}
</h2>
<div
class="flex items-center gap-4 rounded-xl border border-border px-5 py-4"
data-testid="billing-handoff-card"
>
<i18n-t
v-if="handoffAudience === 'owner'"
keypath="workspacePanel.billingTab.handoff.owner.line"
tag="p"
class="m-0 text-sm text-muted-foreground"
>
<template #platform>
<a
:href="handoffHref"
target="_blank"
rel="noopener"
class="text-muted-foreground underline hover:text-foreground"
@click="trackHandoff"
>
{{ $t('workspacePanel.billingTab.handoff.owner.platform') }}
</a>
</template>
</i18n-t>
<Button
as="a"
:href="handoffHref"
target="_blank"
rel="noopener"
variant="secondary"
size="md"
class="ml-auto shrink-0 no-underline"
@click="trackHandoff"
>
{{
$t(`workspacePanel.billingTab.handoff.${handoffAudience}.action`)
}}
<i class="icon-[lucide--arrow-up-right]" aria-hidden="true" />
</Button>
</div>
</section>
<BillingPlatformHandoffCard :audience="handoffAudience" />

<footer class="flex items-center gap-4" data-testid="billing-footer">
<Button
Expand Down Expand Up @@ -264,6 +223,7 @@ import { useTopUpPlanCreditCopy } from '@/platform/billing/composables/useTopUpP
import { usePausedBanner } from '@/platform/billing/composables/usePausedBanner'
import { useTopupCheckoutBanner } from '@/platform/billing/composables/useTopupCheckoutBanner'
import { usePlatformHandoff } from '@/platform/billing/composables/usePlatformHandoff'
import BillingPlatformHandoffCard from '@/platform/billing/components/settings/BillingPlatformHandoffCard.vue'
import { usePlanRowCopy } from '@/platform/billing/composables/usePlanRowCopy'
import { useCreditsCardCopy } from '@/platform/billing/composables/useCreditsCardCopy'
import { useAutoTopUpCardSection } from '@/platform/billing/composables/useAutoTopUpCardSection'
Expand Down Expand Up @@ -316,11 +276,6 @@ const partnerNodesPricingHref = computed(() =>
buildDocsUrl(docsPaths.partnerNodesPricing, { includeLocale: true })
)

const HANDOFF = {
owner: { path: '/profile/billing', target: 'open_billing' },
member: { path: '/profile/usage', target: 'usage' }
} as const

const handoffAudience = computed(() =>
capabilities.canManageBilling.value ? 'owner' : 'member'
)
Expand All @@ -342,6 +297,10 @@ const action = computed(() =>
})
)

const shownPlanAction = computed(() =>
action.value === 'contactSales' || plansAvailable.value ? action.value : null
)

const { state: autoTopUp } = useBillingAutoTopUpCard()
const autoTopUpSection = computed(() =>
deriveAutoTopUpSection({
Expand All @@ -358,6 +317,7 @@ const {
copy: autoTopUpCardCopy,
href: autoTopUpHref,
track: trackAutoTopUp,
available: autoTopUpAvailable,
retry: retryAutoTopUp
} = useAutoTopUpCardSection(
() => load.value === 'ready' && autoTopUpSection.value.kind === 'card'
Expand All @@ -378,7 +338,8 @@ const addCreditsVariant = computed(() =>
? autoTopUp.value.settings.status
: null,
planActionIsPrimary:
action.value === 'subscribe' || (action.value === 'choosePlan' && isCloud)
shownPlanAction.value === 'subscribe' ||
(shownPlanAction.value === 'choosePlan' && isCloud)
})
)

Expand All @@ -390,15 +351,11 @@ const salesVariant = computed(() =>
billing.subscriptionStatus.value === 'ended' ? 'inverted' : 'secondary'
)

const { href: handoffHref, track: trackHandoff } = usePlatformHandoff(
() => HANDOFF[handoffAudience.value].path,
() => ({ target: HANDOFF[handoffAudience.value].target })
)

const { href: plansHref, track: trackPlans } = usePlatformHandoff(
'/profile/billing/plans',
{ target: 'plans' }
)
const {
href: plansHref,
track: trackPlans,
available: plansAvailable
} = usePlatformHandoff('/profile/billing/plans', { target: 'plans' })

function planActionHref(shown: PlanRowAction) {
return shown === 'contactSales' ? CONTACT_SALES_URL : plansHref.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@
</section>

<div class="flex flex-col gap-6">
<section class="flex flex-col gap-3" data-testid="billing-handoff">
<section
v-if="handoffAvailable"
class="flex flex-col gap-3"
data-testid="billing-handoff"
>
<h2 class="m-0 text-base font-medium text-foreground">
{{ $t(`workspacePanel.billingTab.handoff.${handoffAudience}.label`) }}
</h2>
Expand Down Expand Up @@ -261,6 +265,12 @@ const action = computed(() =>
})
)

const shownPlanAction = computed(() =>
action.value === 'contactSales' || handoffAvailable.value
? action.value
: null
)

const { state: autoTopUp } = useBillingAutoTopUpCard()
const addCreditsVariant = computed(() =>
addCreditsEmphasis({
Expand All @@ -274,7 +284,8 @@ const addCreditsVariant = computed(() =>
? autoTopUp.value.settings.status
: null,
planActionIsPrimary:
action.value === 'subscribe' || (action.value === 'choosePlan' && isCloud)
shownPlanAction.value === 'subscribe' ||
(shownPlanAction.value === 'choosePlan' && isCloud)
})
)

Expand All @@ -286,7 +297,11 @@ const salesVariant = computed(() =>
billing.subscriptionStatus.value === 'ended' ? 'inverted' : 'secondary'
)

const { href: handoffHref, track: trackHandoff } = usePlatformHandoff(
const {
href: handoffHref,
track: trackHandoff,
available: handoffAvailable
} = usePlatformHandoff(
() => HANDOFF[handoffAudience.value].path,
() => ({ target: HANDOFF[handoffAudience.value].target })
)
Expand Down
2 changes: 2 additions & 0 deletions src/platform/billing/billingTab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ describe('reserveBillingTab', () => {
vi.spyOn(window, 'open').mockReturnValue(tab as never)

reserveBillingTab({
lang: 'ko',
title: 'Opening checkout…',
detail: 'This takes a few seconds.'
})

expect(tab.document.documentElement.lang).toBe('ko')
expect(tab.document.title).toBe('Opening checkout…')
expect(
tab.document
Expand Down
2 changes: 2 additions & 0 deletions src/platform/billing/billingTab.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { handsPopupsToSystemBrowser } from '@/platform/distribution/desktopBrowser'

export interface OpeningPage {
readonly lang: string
readonly title: string
readonly detail: string
}
Expand All @@ -16,6 +17,7 @@ p { margin: 0; font-size: 12px; color: #8a8a8a; }
`

function paintOpeningPage(page: Document, opening: OpeningPage): void {
page.documentElement.lang = opening.lang
page.title = opening.title
const style = page.createElement('style')
style.textContent = OPENING_PAGE_STYLE
Expand Down
11 changes: 6 additions & 5 deletions src/platform/billing/components/TopUpAutoTopUpCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ watch(
{ immediate: true }
)

const { href, track, available } = usePlatformHandoff('/profile/billing', {
target: 'auto_top_up',
action: 'turn_on'
})

const visible = computed(() => {
if (!available.value) return false
if (!canSetUp.value) return false
const read = state.value
return read.kind === 'loaded' && read.settings.status === 'off'
})

const { href, track } = usePlatformHandoff('/profile/billing', {
target: 'auto_top_up',
action: 'turn_on'
})
</script>
Loading
Loading