Line data Source code
1 5 : <template>
2 : <div class="flex flex-col gap-12 pt-7 pb-6" data-testid="billing-tab">
3 : <WorkspaceHeaderMenu />
4 : <BillingBanner
5 : v-if="isPaused"
6 : :view="pausedView(capabilities.canManageBilling.value)"
7 : :copy="bannerCopy"
8 : :loading="isUpdatingPayment"
9 : @action="updatePayment"
10 : />
11 : <BillingBanner
12 : v-if="planCheckout.banner.value"
13 : :view="planCheckoutBannerView(planCheckout.banner.value, bannerCopy)"
14 : :copy="bannerCopy"
15 : @dismiss="planCheckout.dismiss"
16 : />
17 : <BillingBanner
18 : v-if="topupCheckout.banner.value"
19 : :view="
20 : topupCheckoutBannerView(
21 : topupCheckout.banner.value,
22 : topupBannerCopy,
23 : capabilities.canTopUp.value
24 : )
25 : "
26 : :copy="topupBannerCopy"
27 : :add-credits-variant="addCreditsVariant"
28 : @dismiss="topupCheckout.dismiss"
29 : @action="addCredits('settings_billing_panel')"
30 : />
31 : <BillingBanner
32 : v-if="
33 : capabilities.hasParkedBillingOperation.value &&
34 : capabilities.canManageBilling.value
35 : "
36 : :view="parkedView"
37 : :copy="bannerCopy"
38 : />
39 : <BillingStatusBanner section="billing" />
40 : <BillingBanner
41 : v-if="creditBanner"
42 : :view="creditBanner"
43 : :copy="creditBannerCopy"
44 : :loading="isUpdatingCreditPayment"
45 : :add-credits-variant="creditBannerAddCreditsVariant"
46 : @action="actOnCreditBanner"
47 : @dismiss="dismissCreditBanner"
48 : />
49 : <section class="flex flex-col gap-3" data-testid="billing-plan-section">
50 : <h2 class="m-0 text-base font-medium text-foreground">
51 : {{ $t('workspacePanel.billingTab.credits.plan') }}
52 : </h2>
53 : <div
54 : v-if="load === 'loading'"
55 : class="rounded-xl border border-border px-5 py-4"
56 : data-testid="billing-plan-skeleton"
57 : aria-busy="true"
58 : >
59 : <div class="flex flex-col gap-2">
60 : <Skeleton class="h-6 w-1/3" />
61 : <Skeleton class="h-4 w-2/3" />
62 : </div>
63 : </div>
64 : <div
65 : v-else-if="load === 'error'"
66 : class="flex items-center justify-between gap-4 rounded-xl border border-border px-5 py-4"
67 : role="alert"
68 : data-testid="billing-load-error"
69 : >
70 : <p class="m-0 text-sm text-muted-foreground">
71 : {{ $t(loadErrorKey) }}
72 : </p>
73 : <Button variant="secondary" size="md" class="shrink-0" @click="retry">
74 : {{ $t('workspacePanel.billingTab.tryAgain') }}
75 : </Button>
76 : </div>
77 : <BillingPlanRow
78 : v-else
79 : :state="planRow"
80 : :action="action"
81 : :copy="planRowCopy"
82 : :locale
83 : :sales-variant="salesVariant"
84 : :add-credits-variant="addCreditsVariant"
85 : :can-manage-subscription="capabilities.canManageSubscription.value"
86 : >
87 : <template #leading>
88 : <BillingPlanLifecycle :state="planRow" />
89 : </template>
90 : <template #action="{ action: shown, label, variant }">
91 : <Button
92 : v-bind="planActionButton(shown)"
93 : :variant
94 : size="md"
95 : class="shrink-0 no-underline"
96 : @click="followPlanAction(shown)"
97 : >
98 : {{ label }}
99 : <i class="icon-[lucide--arrow-up-right]" aria-hidden="true" />
100 : </Button>
101 : </template>
102 : </BillingPlanRow>
103 : </section>
104 :
105 : <section
106 : v-if="load === 'ready'"
107 : class="flex flex-col gap-3"
108 : data-testid="billing-credits-section"
109 : >
110 : <BillingCreditsCard
111 : :state="creditsCard"
112 : :add-credits="
113 : addCreditsAvailability({
114 : resolved: capabilities.hasResolvedCapabilities.value,
115 : canTopUp: capabilities.canTopUp.value,
116 : denial: capabilities.topUpDenial.value
117 : })
118 : "
119 : :add-credits-variant="addCreditsVariant"
120 : :plan-credit-note="planCreditNote"
121 : :copy="creditsCardCopy"
122 : :locale
123 : @retry="retryBalance"
124 : @add-credits="addCredits('credits_panel')"
125 : />
126 : <BillingAutoTopUpCard
127 : v-if="autoTopUpSection.kind === 'card'"
128 : :state="autoTopUpCardState"
129 : :off-view="autoTopUpOffView"
130 : :setup="autoTopUpSetup"
131 : :copy="autoTopUpCardCopy"
132 : :locale
133 : :action-href="autoTopUpHref"
134 : @action="openAutoTopUp"
135 : @retry="retryAutoTopUp"
136 : />
137 : <BillingAutoTopUpMemberBlock
138 : v-else-if="autoTopUpSection.kind === 'memberBlock'"
139 : :copy="autoTopUpMemberCopy"
140 : :view="autoTopUpMemberView"
141 : :locale
142 : />
143 : </section>
144 :
145 : <div class="flex flex-col gap-6">
146 : <BillingPlatformHandoffCard :audience="handoffAudience" />
147 :
148 : <footer class="flex items-center gap-4" data-testid="billing-footer">
149 : <Button
150 : as="a"
151 : :href="partnerNodesPricingHref"
152 : target="_blank"
153 : rel="noopener"
154 : variant="muted-textonly"
155 : size="md"
156 : class="no-underline"
157 : >
158 : <i class="icon-[lucide--coins] size-3.5" aria-hidden="true" />
159 : {{ $t('workspacePanel.billingTab.footer.partnerNodesPricing') }}
160 : </Button>
161 : <Button
162 : variant="muted-textonly"
163 : size="md"
164 : :loading="isLoadingSupport"
165 : @click="handleMessageSupport"
166 : >
167 : <i
168 : class="icon-[lucide--message-circle] size-3.5"
169 : aria-hidden="true"
170 : />
171 : {{ $t('workspacePanel.billingTab.footer.messageSupport') }}
172 : </Button>
173 : </footer>
174 : </div>
175 : </div>
176 : </template>
177 :
178 : <script setup lang="ts">
179 : import { computed, onMounted } from 'vue'
180 : import { useI18n } from 'vue-i18n'
181 :
182 : import Button from '@comfyorg/design-system/button/Button'
183 : import Skeleton from '@comfyorg/design-system/skeleton/Skeleton'
184 : import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
185 : import { useBillingDialogs } from '@/platform/billing/composables/useBillingDialogs'
186 : import { isCloud } from '@/platform/distribution/types'
187 : import { useExternalLink } from '@/composables/useExternalLink'
188 : import { useMessageSupport } from '@/platform/billing/subscription/composables/useSubscriptionActions'
189 : import { useTelemetry } from '@comfyorg/telemetry'
190 : import { paymentIntentSourceForAddCreditsClick } from '@/platform/telemetry/utils/paymentIntentSource'
191 : import WorkspaceHeaderMenu from '@/platform/account/components/dialogs/settings/WorkspaceHeaderMenu.vue'
192 : import BillingStatusBanner from '@/platform/billing/components/settings/BillingStatusBanner.vue'
193 : import { usePlanCheckoutBanner } from '@/platform/billing/composables/usePlanCheckoutBanner'
194 : import BillingPlanLifecycle from '@/platform/billing/components/billingTab/BillingPlanLifecycle.vue'
195 : import {
196 : addCreditsAvailability,
197 : addCreditsEmphasis,
198 : CONTACT_SALES_URL,
199 : deriveAutoTopUpSection,
200 : deriveBillingTabLoad,
201 : planRowAction
202 : } from '@comfyorg/account-core/billing'
203 : import type { PlanRowAction } from '@comfyorg/account-core/billing'
204 : import {
205 : BillingAutoTopUpCard,
206 : BillingAutoTopUpMemberBlock,
207 : BillingBanner,
208 : BillingCreditsCard,
209 : BillingPlanRow,
210 : planCheckoutBannerView,
211 : suppressesCreditBanners,
212 : topupCheckoutBannerView
213 : } from '@comfyorg/account-ui/billing'
214 : import { useBillingCreditsCard } from '@/platform/billing/components/billingTab/useBillingCreditsCard'
215 : import { useBillingPlanRow } from '@/platform/billing/components/billingTab/useBillingPlanRow'
216 : import { useBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard'
217 : import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
218 : import { useRefreshBillingOnReturn } from '@/platform/billing/composables/useRefreshBillingOnReturn'
219 : import { useTopUpPlanCreditCopy } from '@/platform/billing/composables/useTopUpPlanCreditCopy'
220 : import { usePausedBanner } from '@/platform/billing/composables/usePausedBanner'
221 : import { useTopupCheckoutBanner } from '@/platform/billing/composables/useTopupCheckoutBanner'
222 : import { usePlatformPlansLink } from '@/platform/billing/composables/usePlatformHandoff'
223 : import BillingPlatformHandoffCard from '@/platform/billing/components/settings/BillingPlatformHandoffCard.vue'
224 : import { usePlanRowCopy } from '@/platform/billing/composables/usePlanRowCopy'
225 : import { useCreditsCardCopy } from '@/platform/billing/composables/useCreditsCardCopy'
226 : import { useAutoTopUpCardSection } from '@/platform/billing/composables/useAutoTopUpCardSection'
227 : import { useAutoTopUpMemberBlockCopy } from '@/platform/billing/composables/useAutoTopUpCopy'
228 : import { useBillingBannerCopy } from '@/platform/billing/composables/useBillingBannerCopy'
229 : import { useCreditBanner } from '@/platform/billing/composables/useCreditBanner'
230 : import { usePaymentRecoveryDialog } from '@/platform/billing/composables/usePaymentRecoveryDialog'
231 : import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
232 :
233 5 : const billing = useBillingContext()
234 5 : const workspaceStore = useTeamWorkspaceStore()
235 5 : const capabilities = useBillingCapabilities()
236 5 : const { isPaused } = usePausedBanner()
237 5 : const planCheckout = usePlanCheckoutBanner()
238 5 : const topupCheckout = useTopupCheckoutBanner(
239 : () => capabilities.canManageBilling.value
240 : )
241 5 : const suppressCreditBanner = computed(() =>
242 : suppressesCreditBanners([
243 : ...(isPaused.value ? (['paused'] as const) : []),
244 : ...(planCheckout.banner.value ? (['planCheckout'] as const) : []),
245 : ...(topupCheckout.banner.value ? (['topupCheckout'] as const) : [])
246 : ])
247 : )
248 5 : const {
249 : copy: bannerCopy,
250 : topupCopy: topupBannerCopy,
251 : pausedView,
252 : parkedView
253 : } = useBillingBannerCopy()
254 5 : const { updatePayment, isUpdatingPayment } = usePaymentRecoveryDialog()
255 5 : const {
256 : view: creditBanner,
257 : copy: creditBannerCopy,
258 : isUpdatingPayment: isUpdatingCreditPayment,
259 : act: actOnCreditBanner,
260 : dismiss: dismissCreditBanner
261 : } = useCreditBanner(suppressCreditBanner)
262 5 : const { state: planRow } = useBillingPlanRow()
263 5 : const planRowCopy = usePlanRowCopy()
264 5 : const { locale } = useI18n()
265 5 : const { state: creditsCard } = useBillingCreditsCard(planRow)
266 5 : const planCreditNote = useTopUpPlanCreditCopy()
267 5 : const creditsCardCopy = useCreditsCardCopy()
268 5 : const { showTopUpCreditsDialog } = useBillingDialogs()
269 5 : const telemetry = useTelemetry()
270 5 : const loadErrorKey = isCloud
271 : ? 'workspacePanel.billingTab.loadError'
272 : : 'workspacePanel.billingTab.localLoadError'
273 5 : const { isLoadingSupport, handleMessageSupport } = useMessageSupport()
274 5 : const { buildDocsUrl, docsPaths } = useExternalLink()
275 5 : const partnerNodesPricingHref = computed(() =>
276 : buildDocsUrl(docsPaths.partnerNodesPricing, { includeLocale: true })
277 : )
278 :
279 5 : const handoffAudience = computed(() =>
280 : capabilities.canManageBilling.value ? 'owner' : 'member'
281 : )
282 :
283 5 : const load = computed(() =>
284 : deriveBillingTabLoad({
285 : workspaceLoadFailed: workspaceStore.initState === 'error',
286 : billingError: billing.error.value,
287 : billingInitialized: billing.isInitialized.value,
288 : capabilitiesReady: capabilities.isReady.value,
289 : capabilitiesResolved: capabilities.hasResolvedCapabilities.value
290 : })
291 : )
292 :
293 5 : const action = computed(() =>
294 : planRowAction(planRow.value, {
295 : canOpenPlans: capabilities.canOpenPlans.value,
296 : planKind: capabilities.planKind.value
297 : })
298 : )
299 :
300 5 : const { state: autoTopUp } = useBillingAutoTopUpCard()
301 5 : const autoTopUpSection = computed(() =>
302 : deriveAutoTopUpSection({
303 : autoTopUpEnabled: capabilities.autoTopUpEnabled.value,
304 : canViewAutoTopUpCard: capabilities.canViewAutoTopUpCard.value,
305 : canViewAutoTopUpMemberNotice:
306 : capabilities.canViewAutoTopUpMemberNotice.value
307 : })
308 : )
309 5 : const {
310 : state: autoTopUpCardState,
311 : offView: autoTopUpOffView,
312 : setup: autoTopUpSetup,
313 : copy: autoTopUpCardCopy,
314 : href: autoTopUpHref,
315 : open: openAutoTopUp,
316 : retry: retryAutoTopUp
317 : } = useAutoTopUpCardSection(
318 : () => load.value === 'ready' && autoTopUpSection.value.kind === 'card'
319 : )
320 5 : const autoTopUpMemberCopy = useAutoTopUpMemberBlockCopy()
321 5 : const autoTopUpMemberView = computed(
322 : () => capabilities.autoTopUpMemberView.value
323 : )
324 5 : const addCreditsVariant = computed(() =>
325 : addCreditsEmphasis({
326 : availableCents:
327 : creditsCard.value.kind === 'unavailable'
328 : ? null
329 : : creditsCard.value.availableCents,
330 : canTopUp: capabilities.canTopUp.value,
331 : autoTopUpStatus:
332 : autoTopUp.value.kind === 'loaded'
333 : ? autoTopUp.value.settings.status
334 : : null,
335 : planActionIsPrimary:
336 : action.value === 'subscribe' || (action.value === 'choosePlan' && isCloud)
337 : })
338 : )
339 :
340 5 : const creditBannerAddCreditsVariant = computed(() =>
341 : planRow.value.kind === 'ended' ? 'secondary' : addCreditsVariant.value
342 : )
343 :
344 5 : const salesVariant = computed(() =>
345 : billing.subscriptionStatus.value === 'ended' ? 'inverted' : 'secondary'
346 : )
347 :
348 5 : const { button: plansButton, open: openPlans } = usePlatformPlansLink()
349 :
350 5 : const CONTACT_SALES_BUTTON = {
351 : as: 'a',
352 : href: CONTACT_SALES_URL,
353 : target: '_blank',
354 : rel: 'noopener'
355 : } as const
356 :
357 5 : function planActionButton(shown: PlanRowAction) {
358 5 : return shown === 'contactSales' ? CONTACT_SALES_BUTTON : plansButton.value
359 : }
360 :
361 1 : function followPlanAction(shown: PlanRowAction) {
362 1 : if (shown !== 'contactSales') openPlans()
363 : }
364 :
365 0 : async function retryBalance() {
366 0 : await billing.fetchBalance().catch(() => undefined)
367 : }
368 :
369 0 : function addCredits(source: 'credits_panel' | 'settings_billing_panel') {
370 0 : telemetry?.trackAddApiCreditButtonClicked({ source })
371 0 : void showTopUpCreditsDialog({
372 : source: paymentIntentSourceForAddCreditsClick(source)
373 : })
374 : }
375 :
376 0 : async function retry() {
377 0 : if (workspaceStore.initState === 'error') {
378 0 : await workspaceStore.initialize().catch(() => undefined)
379 : }
380 0 : await Promise.allSettled([billing.initialize(), capabilities.refresh()])
381 : }
382 :
383 5 : onMounted(() => {
384 5 : if (!billing.isInitialized.value && !billing.isLoading.value) {
385 0 : void billing.initialize().catch(() => undefined)
386 : }
387 5 : void capabilities.initialize()
388 : })
389 :
390 5 : useRefreshBillingOnReturn()
391 : </script>
|