From 846b3baa34684081f7b071cad65edcdb144bdc76 Mon Sep 17 00:00:00 2001
From: dante01yoon
Date: Fri, 2 Oct 2026 17:55:38 -0400
Subject: [PATCH 1/4] FE-3121 feat(billing): add the portal event to the
billing telemetry contract
---
.../telemetry/billingTelemetryEvent.ts | 2 +
.../src/core/billing/telemetry/eventNames.ts | 5 +-
.../src/core/billing/telemetry/index.ts | 1 +
.../src/core/billing/telemetry/payload.ts | 1 +
.../billing/telemetry/portalEvent.test.ts | 84 +++++++++++++++++++
.../src/core/billing/telemetry/portalEvent.ts | 22 +++++
6 files changed, 114 insertions(+), 1 deletion(-)
create mode 100644 packages/account-core/src/core/billing/telemetry/portalEvent.test.ts
create mode 100644 packages/account-core/src/core/billing/telemetry/portalEvent.ts
diff --git a/packages/account-core/src/core/billing/telemetry/billingTelemetryEvent.ts b/packages/account-core/src/core/billing/telemetry/billingTelemetryEvent.ts
index 3326da66271..474ecef4b9f 100644
--- a/packages/account-core/src/core/billing/telemetry/billingTelemetryEvent.ts
+++ b/packages/account-core/src/core/billing/telemetry/billingTelemetryEvent.ts
@@ -3,6 +3,7 @@ import type { CapabilityReadBillingEvent } from './capabilityReadEvent.js'
import type { DowngradeToPersonalBillingEvent } from './downgradeToPersonalEvent.js'
import type { EntryBillingEvent } from './entryEvent.js'
import type { BillingOperationBillingEvent } from './operationEvent.js'
+import type { PortalBillingEvent } from './portalEvent.js'
import type { ResubscribeBillingEvent } from './resubscribeEvent.js'
import type { SubscriptionCheckoutBillingEvent } from './subscriptionCheckoutEvent.js'
import type { TopupBillingEvent } from './topupEvent.js'
@@ -31,6 +32,7 @@ export type BillingTelemetryEvent = {
| WebSessionBillingEvent
| EntryBillingEvent
| CancelBillingEvent
+ | PortalBillingEvent
)
type BillingTelemetryEventNameFor =
diff --git a/packages/account-core/src/core/billing/telemetry/eventNames.ts b/packages/account-core/src/core/billing/telemetry/eventNames.ts
index 000f3ea9bdd..97a7a1194c4 100644
--- a/packages/account-core/src/core/billing/telemetry/eventNames.ts
+++ b/packages/account-core/src/core/billing/telemetry/eventNames.ts
@@ -38,5 +38,8 @@ export const BILLING_TELEMETRY_EVENTS = {
BILLING_ENTRY_ADD_CREDITS_CLICKED: 'billing.entry.add_credits_clicked',
BILLING_CANCEL_INTENT: 'billing.cancel.intent',
BILLING_CANCEL_ABANDONED: 'billing.cancel.abandoned',
- BILLING_CANCEL_FAILED: 'billing.cancel.failed'
+ BILLING_CANCEL_FAILED: 'billing.cancel.failed',
+ BILLING_PORTAL_OPENED: 'billing.portal.opened',
+ BILLING_PORTAL_FAILED: 'billing.portal.failed',
+ BILLING_PORTAL_RETURNED: 'billing.portal.returned'
} as const satisfies Record
diff --git a/packages/account-core/src/core/billing/telemetry/index.ts b/packages/account-core/src/core/billing/telemetry/index.ts
index fcfa44b4178..0f89ab3165f 100644
--- a/packages/account-core/src/core/billing/telemetry/index.ts
+++ b/packages/account-core/src/core/billing/telemetry/index.ts
@@ -18,6 +18,7 @@ export {
} from './payload.js'
export { BILLING_TELEMETRY_EVENTS } from './eventNames.js'
export { toBillingTelemetryEvent } from './operationLifecycleEvent.js'
+export type { BillingPortalTarget } from './portalEvent.js'
export type { SubscriptionCheckoutUi } from './subscriptionCheckoutEvent.js'
export type {
WebEntryBillingEvent,
diff --git a/packages/account-core/src/core/billing/telemetry/payload.ts b/packages/account-core/src/core/billing/telemetry/payload.ts
index e8c291ed792..f17c3b00eb0 100644
--- a/packages/account-core/src/core/billing/telemetry/payload.ts
+++ b/packages/account-core/src/core/billing/telemetry/payload.ts
@@ -28,6 +28,7 @@ export const BILLING_PAYLOAD_FIELD_HANDLING = {
reason: 'required',
result: 'required',
source: 'required',
+ target: 'required',
to: 'required',
amount_cents: 'optional',
amount_preset: 'optional',
diff --git a/packages/account-core/src/core/billing/telemetry/portalEvent.test.ts b/packages/account-core/src/core/billing/telemetry/portalEvent.test.ts
new file mode 100644
index 00000000000..e910904a3c1
--- /dev/null
+++ b/packages/account-core/src/core/billing/telemetry/portalEvent.test.ts
@@ -0,0 +1,84 @@
+import { describe, expect, it } from 'vitest'
+
+import { getBillingTelemetryEventName } from './billingTelemetryEvent.js'
+import type { BillingTelemetryEvent } from './billingTelemetryEvent.js'
+import { BILLING_TELEMETRY_EVENTS } from './eventNames.js'
+import {
+ getBillingWebTelemetryEventPayload,
+ getCloudAppBillingTelemetryEventPayload
+} from './payload.js'
+
+describe('the portal events', () => {
+ it.for<{
+ name: string
+ event: BillingTelemetryEvent
+ eventName: string
+ payload: Record
+ }>([
+ {
+ name: 'the portal opening on its payment methods',
+ event: {
+ operation: 'portal',
+ stage: 'opened',
+ outcome: 'pending',
+ target: 'payment_methods',
+ billing_client: 'sdk'
+ },
+ eventName: 'billing.portal.opened',
+ payload: {
+ operation: 'portal',
+ stage: 'opened',
+ outcome: 'pending',
+ target: 'payment_methods',
+ billing_client: 'sdk'
+ }
+ },
+ {
+ name: 'the portal failing to open on its invoices',
+ event: {
+ operation: 'portal',
+ stage: 'failed',
+ outcome: 'failure',
+ target: 'invoices',
+ failure_category: 'redirect',
+ error_code: 'payment_popup_blocked'
+ },
+ eventName: 'billing.portal.failed',
+ payload: {
+ operation: 'portal',
+ stage: 'failed',
+ outcome: 'failure',
+ target: 'invoices',
+ failure_category: 'redirect',
+ error_code: 'payment_popup_blocked'
+ }
+ },
+ {
+ name: 'the customer coming back from managing the subscription',
+ event: {
+ operation: 'portal',
+ stage: 'returned',
+ outcome: 'pending',
+ target: 'manage_subscription'
+ },
+ eventName: 'billing.portal.returned',
+ payload: {
+ operation: 'portal',
+ stage: 'returned',
+ outcome: 'pending',
+ target: 'manage_subscription'
+ }
+ }
+ ])('names and reports $name', ({ event, eventName, payload }) => {
+ expect(getBillingTelemetryEventName(event)).toBe(eventName)
+ expect(Object.values(BILLING_TELEMETRY_EVENTS)).toContain(eventName)
+ expect(getCloudAppBillingTelemetryEventPayload(event)).toStrictEqual({
+ ...payload,
+ billing_surface: 'cloud_app'
+ })
+ expect(getBillingWebTelemetryEventPayload(event)).toStrictEqual({
+ ...payload,
+ billing_surface: 'billing_web'
+ })
+ })
+})
diff --git a/packages/account-core/src/core/billing/telemetry/portalEvent.ts b/packages/account-core/src/core/billing/telemetry/portalEvent.ts
new file mode 100644
index 00000000000..13ca67b343f
--- /dev/null
+++ b/packages/account-core/src/core/billing/telemetry/portalEvent.ts
@@ -0,0 +1,22 @@
+import type { BillingFailed } from './stages.js'
+
+/** The part of the provider's hosted portal the customer was sent to. */
+export type BillingPortalTarget =
+ | 'payment_methods'
+ | 'invoices'
+ | 'manage_subscription'
+
+/**
+ * A trip to the provider's hosted portal. What the customer does there (adding,
+ * removing or picking a default method, reading invoices) never reaches the
+ * browser, so the trip only records leaving for the portal, failing to, and
+ * coming back.
+ */
+export type PortalBillingEvent = {
+ operation: 'portal'
+ target: BillingPortalTarget
+} & (
+ | { stage: 'opened'; outcome: 'pending' }
+ | BillingFailed
+ | { stage: 'returned'; outcome: 'pending' }
+)
From 5ec629f6e9498e3dd060e03391a3bfb50bf3a210 Mon Sep 17 00:00:00 2001
From: dante01yoon
Date: Fri, 2 Oct 2026 17:56:34 -0400
Subject: [PATCH 2/4] test(billing): expect portal opens, failures and returns
on both hosts
---
.../src/views/InvoicesView.test.ts | 109 +++++++++++++++--
.../src/views/PaymentMethodsView.test.ts | 73 +++++++++++-
.../composables/useSubscription.test.ts | 112 ++++++++++++++++--
...eWorkspaceBilling.subscriptionRail.test.ts | 100 ++++++++++++++++
4 files changed, 376 insertions(+), 18 deletions(-)
diff --git a/apps/billing-web/src/views/InvoicesView.test.ts b/apps/billing-web/src/views/InvoicesView.test.ts
index e9340bb7542..94f55709e99 100644
--- a/apps/billing-web/src/views/InvoicesView.test.ts
+++ b/apps/billing-web/src/views/InvoicesView.test.ts
@@ -1,5 +1,6 @@
import userEvent from '@testing-library/user-event'
import { render, screen } from '@testing-library/vue'
+import { createMemoryHistory, createRouter } from 'vue-router'
import { BILLING_CLIENT_KEY } from '@comfyorg/account-ui/billing'
import { parseBillingEntry } from '@comfyorg/billing-contract'
@@ -8,38 +9,132 @@ import { recordBillingEntry } from '@/entry/billingEntry'
import { createBillingI18n } from '@/i18n'
import type { FakeBillingClientOptions } from '@/test/fakeBillingClient'
import { createFakeBillingClient } from '@/test/fakeBillingClient'
+import { trackedBillingEvents } from '@/test/trackedBillingEvents'
import InvoicesView from '@/views/InvoicesView.vue'
-const INVOICES_PATH = '/v1/invoices?product=comfyui&return_to=comfyui_workspace'
+const SURFACE_PATH = '/v1/invoices'
+const INVOICES_PATH = `${SURFACE_PATH}?product=comfyui&return_to=comfyui_workspace`
-function renderInvoices(options: FakeBillingClientOptions = {}) {
+async function renderInvoices(
+ options: FakeBillingClientOptions = {},
+ path = INVOICES_PATH
+) {
recordBillingEntry(parseBillingEntry(INVOICES_PATH))
+ const router = createRouter({
+ history: createMemoryHistory(),
+ routes: [{ path: SURFACE_PATH, component: InvoicesView }]
+ })
+ await router.push(path)
+ await router.isReady()
const fake = createFakeBillingClient(options)
render(InvoicesView, {
global: {
- plugins: [createBillingI18n()],
+ plugins: [createBillingI18n(), router],
provide: { [BILLING_CLIENT_KEY]: fake.client }
}
})
- return fake
+ return { ...fake, router }
}
describe('InvoicesView', () => {
it('sends the visitor to the portal with this page as the way back', async () => {
const assign = vi.fn()
vi.spyOn(window.location, 'assign').mockImplementation(assign)
- const fake = renderInvoices({ portalUrl: 'https://billing.stripe.test/p' })
+ const fake = await renderInvoices({
+ portalUrl: 'https://billing.stripe.test/p'
+ })
await userEvent.click(screen.getByRole('button', { name: 'Open invoices' }))
expect(fake.openPaymentPortal).toHaveBeenCalledWith({
- returnUrl: window.location.href
+ returnUrl: expect.stringContaining('portal=return')
})
expect(assign).toHaveBeenCalledWith('https://billing.stripe.test/p')
})
+ it('reports the portal opening on the invoices', async () => {
+ vi.spyOn(window.location, 'assign').mockImplementation(() => undefined)
+ const sent = trackedBillingEvents()
+ await renderInvoices({ portalUrl: 'https://billing.stripe.test/p' })
+
+ await userEvent.click(screen.getByRole('button', { name: 'Open invoices' }))
+
+ expect(sent()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'opened',
+ outcome: 'pending',
+ target: 'invoices',
+ billing_client: 'sdk'
+ }
+ ])
+ })
+
+ it('reports the return from the portal once and drops the marker', async () => {
+ const sent = trackedBillingEvents()
+ const { router } = await renderInvoices(
+ {},
+ `${INVOICES_PATH}&portal=return`
+ )
+
+ await vi.waitFor(() => {
+ expect(router.currentRoute.value.fullPath).toBe(INVOICES_PATH)
+ })
+ expect(sent()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'returned',
+ outcome: 'pending',
+ target: 'invoices',
+ billing_client: 'sdk'
+ }
+ ])
+ })
+
+ it.for<{
+ name: string
+ portal: FakeBillingClientOptions['portal']
+ failure: Record
+ }>([
+ {
+ name: 'a request that never reached the server',
+ portal: { status: 'error', code: 'REQUEST_FAILED' },
+ failure: { failure_category: 'network' }
+ },
+ {
+ name: 'a refusal from the server',
+ portal: { status: 'error', code: 'ACCESS_DENIED', httpStatus: 403 },
+ failure: { failure_category: 'api_rejected' }
+ },
+ {
+ name: 'a portal address that fails validation',
+ portal: { status: 'error', code: 'MALFORMED_RESPONSE', httpStatus: 200 },
+ failure: { failure_category: 'unknown' }
+ }
+ ])('reports $name as a failed portal open', async ({ portal, failure }) => {
+ const sent = trackedBillingEvents()
+ await renderInvoices({ portal })
+
+ await userEvent.click(screen.getByRole('button', { name: 'Open invoices' }))
+
+ await vi.waitFor(() => {
+ expect(sent()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'failed',
+ outcome: 'failure',
+ target: 'invoices',
+ billing_client: 'sdk',
+ ...failure
+ }
+ ])
+ })
+ })
+
it('explains a portal it could not open in our own words', async () => {
- renderInvoices({ portal: { status: 'error', code: 'REQUEST_FAILED' } })
+ await renderInvoices({
+ portal: { status: 'error', code: 'REQUEST_FAILED' }
+ })
await userEvent.click(screen.getByRole('button', { name: 'Open invoices' }))
diff --git a/apps/billing-web/src/views/PaymentMethodsView.test.ts b/apps/billing-web/src/views/PaymentMethodsView.test.ts
index 9d04c65fb5d..5f7abae4ad7 100644
--- a/apps/billing-web/src/views/PaymentMethodsView.test.ts
+++ b/apps/billing-web/src/views/PaymentMethodsView.test.ts
@@ -10,6 +10,8 @@ import { parseBillingEntry } from '@comfyorg/billing-contract'
import { recordBillingEntry } from '@/entry/billingEntry'
import { createBillingI18n } from '@/i18n'
import { createFakeBillingClient } from '@/test/fakeBillingClient'
+import type { FakeBillingClientOptions } from '@/test/fakeBillingClient'
+import { trackedBillingEvents } from '@/test/trackedBillingEvents'
import PaymentMethodsView from '@/views/PaymentMethodsView.vue'
const SURFACE_PATH = '/v1/payment-methods'
@@ -22,13 +24,17 @@ const SAVED_CARDS: SavedPaymentMethod[] = [
{ id: 'pm_3', is_default: false, type: 'us_bank_account' }
]
-async function renderPaymentMethods(query: string) {
+async function renderPaymentMethods(
+ query: string,
+ options: FakeBillingClientOptions = {}
+) {
const router = createRouter({
history: createMemoryHistory(),
routes: [{ path: SURFACE_PATH, component: PaymentMethodsView }]
})
const fake = createFakeBillingClient({
- paymentMethods: { status: 'ok', value: SAVED_CARDS }
+ paymentMethods: { status: 'ok', value: SAVED_CARDS },
+ ...options
})
await router.push(`${SURFACE_PATH}?${query}`)
await router.isReady()
@@ -100,4 +106,67 @@ describe('PaymentMethodsView', () => {
)
expect(await screen.findByText('visa •••• 4242')).toBeInTheDocument()
})
+
+ describe('portal telemetry', () => {
+ it('reports the portal opening on the payment methods', async () => {
+ stubNavigation()
+ const sent = trackedBillingEvents()
+ await renderPaymentMethods(ENTRY_QUERY)
+
+ await userEvent.click(
+ await screen.findByRole('button', { name: 'Manage payment methods' })
+ )
+
+ expect(sent()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'opened',
+ outcome: 'pending',
+ target: 'payment_methods',
+ billing_client: 'sdk'
+ }
+ ])
+ })
+
+ it('reports a portal it could not open as a failed open', async () => {
+ const sent = trackedBillingEvents()
+ await renderPaymentMethods(ENTRY_QUERY, {
+ portal: { status: 'error', code: 'NOT_FOUND', httpStatus: 404 }
+ })
+
+ await userEvent.click(
+ await screen.findByRole('button', { name: 'Manage payment methods' })
+ )
+
+ await vi.waitFor(() => {
+ expect(sent()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'failed',
+ outcome: 'failure',
+ target: 'payment_methods',
+ billing_client: 'sdk',
+ failure_category: 'api_rejected'
+ }
+ ])
+ })
+ })
+
+ it('reports the return from the portal once', async () => {
+ const sent = trackedBillingEvents()
+ const fake = await renderPaymentMethods(`${ENTRY_QUERY}&portal=return`)
+
+ await portalReturnHandled(fake.router)
+
+ expect(sent()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'returned',
+ outcome: 'pending',
+ target: 'payment_methods',
+ billing_client: 'sdk'
+ }
+ ])
+ })
+ })
})
diff --git a/src/platform/cloud/subscription/composables/useSubscription.test.ts b/src/platform/cloud/subscription/composables/useSubscription.test.ts
index bbc49db0e79..8e446f508d1 100644
--- a/src/platform/cloud/subscription/composables/useSubscription.test.ts
+++ b/src/platform/cloud/subscription/composables/useSubscription.test.ts
@@ -1,6 +1,6 @@
import { useDialogService } from '@/services/dialogService'
import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
-import { useAuthStore } from '@/stores/authStore'
+import { AuthStoreError, useAuthStore } from '@/stores/authStore'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { computed, effectScope } from 'vue'
@@ -128,7 +128,7 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({
vi.mock(import('@/composables/auth/useAuthActions'), () => ({
useAuthActions: vi.fn(() => ({
reportError: mockReportError,
- accessBillingPortal: mockAccessBillingPortal
+ accessBillingPortalDirect: mockAccessBillingPortal
}))
}))
@@ -2607,27 +2607,121 @@ describe('useSubscription', () => {
windowOpenSpy.mockRestore()
})
- it('should call accessBillingPortal for invoice history', async () => {
+ it('should open the billing portal for invoice history', async () => {
const { handleInvoiceHistory } = useSubscriptionWithScope()
await handleInvoiceHistory()
- expect(useAuthActions().accessBillingPortal).toHaveBeenCalled()
+ expect(useAuthActions().accessBillingPortalDirect).toHaveBeenCalled()
})
- it('should call accessBillingPortal for manage subscription', async () => {
+ it('should open the billing portal for manage subscription', async () => {
const { manageSubscription } = useSubscriptionWithScope()
await manageSubscription()
- expect(useAuthActions().accessBillingPortal).toHaveBeenCalled()
+ expect(useAuthActions().accessBillingPortalDirect).toHaveBeenCalled()
+ })
+
+ describe('portal telemetry', () => {
+ type PortalAction = 'manageSubscription' | 'handleInvoiceHistory'
+
+ function portalEvents() {
+ return mockTelemetry.trackBillingEvent.mock.calls
+ .map(([event]) => event)
+ .filter((event) => event.operation === 'portal')
+ }
+
+ function leaveAndReturn() {
+ window.dispatchEvent(new Event('blur'))
+ window.dispatchEvent(new Event('focus'))
+ }
+
+ beforeEach(() => {
+ mockTelemetry.trackBillingEvent.mockClear()
+ })
+
+ it.for<{ action: PortalAction; target: string }>([
+ { action: 'manageSubscription', target: 'manage_subscription' },
+ { action: 'handleInvoiceHistory', target: 'invoices' }
+ ])(
+ 'reports $action opening the portal and one return',
+ async ({ action, target }) => {
+ await useSubscriptionWithScope()[action]()
+ leaveAndReturn()
+ leaveAndReturn()
+
+ expect(portalEvents()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'opened',
+ outcome: 'pending',
+ target,
+ billing_client: 'legacy'
+ },
+ {
+ operation: 'portal',
+ stage: 'returned',
+ outcome: 'pending',
+ target,
+ billing_client: 'legacy'
+ }
+ ])
+ }
+ )
+
+ it.for<{ action: PortalAction; target: string }>([
+ { action: 'manageSubscription', target: 'manage_subscription' },
+ { action: 'handleInvoiceHistory', target: 'invoices' }
+ ])(
+ 'reports $action as a failed open when the tab is blocked',
+ async ({ action, target }) => {
+ mockAccessBillingPortal.mockResolvedValueOnce(false)
+
+ await useSubscriptionWithScope()[action]()
+ leaveAndReturn()
+
+ expect(portalEvents()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'failed',
+ outcome: 'failure',
+ target,
+ billing_client: 'legacy',
+ failure_category: 'redirect',
+ error_code: 'payment_popup_blocked'
+ }
+ ])
+ }
+ )
+
+ it('reports a refused portal request as a failed open and still reports the error', async () => {
+ const refusal = new AuthStoreError('Portal refused', 500)
+ mockAccessBillingPortal.mockRejectedValueOnce(refusal)
+
+ await expect(
+ useSubscriptionWithScope().manageSubscription()
+ ).rejects.toBe(refusal)
+
+ expect(portalEvents()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'failed',
+ outcome: 'failure',
+ target: 'manage_subscription',
+ billing_client: 'legacy',
+ failure_category: 'api_rejected'
+ }
+ ])
+ expect(mockReportError).toHaveBeenCalledWith(refusal)
+ })
})
it('does not start cancellation watching when the billing portal does not open', async () => {
useCurrentUser().isLoggedIn = computed(() => true)
- vi.mocked(useAuthActions().accessBillingPortal).mockResolvedValueOnce(
- false
- )
+ vi.mocked(
+ useAuthActions().accessBillingPortalDirect
+ ).mockResolvedValueOnce(false)
mockGetBillingStatus.mockResolvedValue({
is_active: true,
diff --git a/src/platform/workspace/composables/useWorkspaceBilling.subscriptionRail.test.ts b/src/platform/workspace/composables/useWorkspaceBilling.subscriptionRail.test.ts
index ebdd5c6c749..ad9f3ecd59e 100644
--- a/src/platform/workspace/composables/useWorkspaceBilling.subscriptionRail.test.ts
+++ b/src/platform/workspace/composables/useWorkspaceBilling.subscriptionRail.test.ts
@@ -559,3 +559,103 @@ describe('payment portal on the billing SDK rail', () => {
)
})
})
+
+describe('payment portal telemetry', () => {
+ function portalEvents() {
+ const trackBillingEvent = useTelemetry()?.trackBillingEvent
+ if (!trackBillingEvent) throw new Error('Telemetry mock unavailable')
+ return vi
+ .mocked(trackBillingEvent)
+ .mock.calls.map(([event]) => event)
+ .filter((event) => event.operation === 'portal')
+ }
+
+ function leaveAndReturn() {
+ window.dispatchEvent(new Event('blur'))
+ window.dispatchEvent(new Event('focus'))
+ }
+
+ beforeEach(() => {
+ const trackBillingEvent = useTelemetry()?.trackBillingEvent
+ if (trackBillingEvent) vi.mocked(trackBillingEvent).mockClear()
+ vi.mocked(window.open).mockReturnValue({
+ location: { href: '' },
+ close: vi.fn()
+ } as unknown as Window)
+ })
+
+ it.for<{
+ name: string
+ railOn: boolean
+ billingClient: 'sdk' | 'legacy'
+ }>([
+ { name: 'the SDK rail', railOn: true, billingClient: 'sdk' },
+ { name: 'the workspace client', railOn: false, billingClient: 'legacy' }
+ ])(
+ 'reports the portal opening from $name and one return',
+ async ({ railOn, billingClient }) => {
+ flagState.billingSdkSubscriptionEnabled = railOn
+ vi.mocked(harness.sdk.commands.openPaymentPortal).mockResolvedValue({
+ status: 'ok',
+ value: { url: 'https://portal.sdk.example/session' }
+ })
+
+ await setupBilling().manageSubscription()
+ leaveAndReturn()
+ leaveAndReturn()
+
+ expect(portalEvents()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'opened',
+ outcome: 'pending',
+ target: 'manage_subscription',
+ billing_client: billingClient
+ },
+ {
+ operation: 'portal',
+ stage: 'returned',
+ outcome: 'pending',
+ target: 'manage_subscription',
+ billing_client: billingClient
+ }
+ ])
+ }
+ )
+
+ it('reports a blocked portal tab as a failed open', async () => {
+ vi.mocked(window.open).mockReturnValue(null)
+
+ await setupBilling().manageSubscription()
+
+ expect(portalEvents()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'failed',
+ outcome: 'failure',
+ target: 'manage_subscription',
+ failure_category: 'redirect',
+ error_code: 'payment_popup_blocked'
+ }
+ ])
+ })
+
+ it('reports a refused portal request as a failed open', async () => {
+ vi.mocked(workspaceApi.getPaymentPortalUrl).mockRejectedValue(
+ new WorkspaceApiError('Forbidden', 403)
+ )
+
+ await expect(setupBilling().manageSubscription()).rejects.toThrow()
+ leaveAndReturn()
+
+ expect(portalEvents()).toEqual([
+ {
+ operation: 'portal',
+ stage: 'failed',
+ outcome: 'failure',
+ target: 'manage_subscription',
+ failure_category: 'api_rejected'
+ }
+ ])
+ })
+})
From 32c44434d4daf9bcb520931f3aed37308ba18b87 Mon Sep 17 00:00:00 2001
From: dante01yoon
Date: Fri, 2 Oct 2026 17:59:32 -0400
Subject: [PATCH 3/4] FE-3121 feat(billing): report portal opens, failures and
returns on the cloud app and billing web
---
.../src/components/PaymentMethodsPanel.vue | 59 ++++-----------
.../src/composables/usePaymentPortal.ts | 60 ++++++++++++++++
.../src/telemetry/portalTelemetry.ts | 39 ++++++++++
apps/billing-web/src/views/InvoicesView.vue | 31 +++-----
.../composables/useSubscription.ts | 26 ++++++-
.../telemetry/utils/billingPortalTelemetry.ts | 71 +++++++++++++++++++
.../composables/useWorkspaceBilling.ts | 30 ++++++--
7 files changed, 239 insertions(+), 77 deletions(-)
create mode 100644 apps/billing-web/src/composables/usePaymentPortal.ts
create mode 100644 apps/billing-web/src/telemetry/portalTelemetry.ts
create mode 100644 src/platform/telemetry/utils/billingPortalTelemetry.ts
diff --git a/apps/billing-web/src/components/PaymentMethodsPanel.vue b/apps/billing-web/src/components/PaymentMethodsPanel.vue
index d8e3230ad97..6581c93ec0d 100644
--- a/apps/billing-web/src/components/PaymentMethodsPanel.vue
+++ b/apps/billing-web/src/components/PaymentMethodsPanel.vue
@@ -1,34 +1,26 @@
@@ -41,7 +30,7 @@ async function openPortal() {
{{ t('hosted.invoices.body') }}
- {{ failure }}
+ {{ refusal(failure) }}