Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5ae4c8d
feat(billing): add the checkout challenge events to the shared teleme…
dante01yoon Oct 2, 2026
c8d44b5
test(billing): expect the lifecycle to report challenges and retryabl…
dante01yoon Oct 2, 2026
8c37a94
feat(billing): report 3DS challenges and retryable declines from the …
dante01yoon Oct 2, 2026
70fb051
feat(billing): add the hosted redirect events to the shared telemetry…
dante01yoon Oct 2, 2026
6de149d
test(billing): expect hosted steps and the return from them to be rep…
dante01yoon Oct 2, 2026
62e449c
feat(billing): report hosted redirects and the return from them on bo…
dante01yoon Oct 2, 2026
203943a
style(billing): format the hosted step return report
dante01yoon Oct 2, 2026
67d5cf8
fix(billing): report a later decline after an echoed failed challenge
dante01yoon Oct 3, 2026
b01782f
Merge branch 'fe3119-1' into fe3119-2
dante01yoon Oct 3, 2026
38f5b4d
refactor(billing): split hosted-step reporting branches and unexport …
dante01yoon Oct 3, 2026
8814fe1
FE-3119 feat(billing-web): report an abandoned checkout and the endin…
dante01yoon Oct 3, 2026
415ab5b
test(billing-web): expect the embedded checkout to report abandons an…
dante01yoon Oct 3, 2026
cc34e7e
feat(billing-web): report abandons and ending screens on the embedded…
dante01yoon Oct 3, 2026
dbb4092
Merge remote-tracking branch 'origin/main' into fe3119-2
dante01yoon Oct 3, 2026
b027eaa
refactor(billing-web): name the own-site payment check outside pay()
dante01yoon Oct 3, 2026
03d073f
test(billing-web): expect an abandon before a provider handoff and af…
dante01yoon Oct 3, 2026
0688712
fix(billing-web): reopen the journey after a retried ending and count…
dante01yoon Oct 3, 2026
001fb64
test(billing): open the hosted page into the real window instead of a…
dante01yoon Oct 3, 2026
d167ad2
Merge remote-tracking branch 'origin/main' into work-19947
dante01yoon Oct 3, 2026
4168df7
fix(billing-web): report an abandon after coming back from a hosted step
dante01yoon Oct 3, 2026
4b29789
Merge remote-tracking branch 'origin/jaewon/fe-3119-payment-friction-…
dante01yoon Oct 3, 2026
4b2dba7
Merge remote-tracking branch 'origin/main' into work-19974
dante01yoon Oct 3, 2026
6bca544
test(billing-web): expect no abandon while a saved non-card method pa…
dante01yoon Oct 3, 2026
09175ff
fix(billing-web): classify a saved method by its loaded type before t…
dante01yoon Oct 3, 2026
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
13 changes: 13 additions & 0 deletions apps/billing-web/src/checkout/checkoutJourney.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type {
CheckoutEndingKind,
CheckoutEntryFlow,
CheckoutEntrySource,
CheckoutJourneyPhaseEvent,
PreviewSubscribeResult,
SubscriptionCommandFailure,
SubscriptionPreview
} from '@comfyorg/account-core/billing'
import { matchesServerCode } from '@comfyorg/account-core/billing'
import type { BillingSource } from '@comfyorg/billing-contract'

import type { CheckoutPageEvent } from '@/checkout/checkoutPage'
Expand Down Expand Up @@ -110,6 +113,16 @@ export function previewFailureOfResult(
}
}

/** The full-page ending the embedded checkout's quote failure screen stands for. */
export function quoteFailureEndingOf(
failure: SubscriptionCommandFailure
): CheckoutEndingKind {
if (failure.code === 'ACCESS_DENIED') return 'refused'
return 'serverCode' in failure && matchesServerCode(failure, 'INVALID_PLAN')
? 'plan_unavailable'
: 'load_failed'
}

type MethodSelectedPhase = Extract<
CheckoutJourneyPhaseEvent,
{ phase: 'method_selected' }
Expand Down
12 changes: 12 additions & 0 deletions apps/billing-web/src/checkout/checkoutRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { previewOf } from '@/test/fakeBillingClient'

import {
buildSubscribeRequest,
paysOnOwnSite,
teamCheckoutPlan,
tierCheckoutPlan
} from './checkoutRequest'
Expand Down Expand Up @@ -123,3 +124,14 @@ describe('buildSubscribeRequest', () => {
).toEqual({ plan_slug: 'pro_monthly', confirmation_token: 'ctok' })
})
})

describe('paysOnOwnSite', () => {
it.for<{ name: string; methodType: string | undefined; away: boolean }>([
{ name: 'an Alipay account', methodType: 'alipay', away: true },
{ name: 'any other non-card method', methodType: 'sepa_debit', away: true },
{ name: 'a card', methodType: 'card', away: false },
{ name: 'a method nobody named', methodType: undefined, away: false }
])('says $name pays on its own site: $away', ({ methodType, away }) => {
expect(paysOnOwnSite(methodType)).toBe(away)
})
})
5 changes: 5 additions & 0 deletions apps/billing-web/src/checkout/checkoutRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export interface PaymentChoice {
readonly confirmReactivation?: boolean
}

/** A method other than a card authenticates on its own site, so the page leaves while it pays. */
export function paysOnOwnSite(methodType: string | undefined): boolean {
return methodType !== undefined && methodType !== 'card'
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

export interface SubscribeContext {
readonly planSlug: string
readonly teamCreditStopId?: string
Expand Down
228 changes: 225 additions & 3 deletions apps/billing-web/src/views/CheckoutView.journey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
import {
createFakeBillingClient,
failedOperation,
hostedPendingOperation,
pendingOperation,
previewOf,
succeededOperation
Expand Down Expand Up @@ -260,9 +261,8 @@ describe('the embedded checkout journey', () => {
])('$name', async ({ options, last }) => {
await renderCheckout(CHECKOUT_PATH, options)

await waitFor(() => expect(journey()).toHaveLength(2))
await waitFor(() => expect(journey()[1]).toMatchObject(last))
expect(journeyNames()[0]).toBe('billing.checkout.entered')
expect(journey()[1]).toMatchObject(last)
})

it.for<{
Expand Down Expand Up @@ -358,7 +358,8 @@ describe('the embedded checkout journey', () => {
'billing.checkout.payment_submit_attempted',
'billing.checkout.method_selected',
'billing.checkout.submitted',
'billing.checkout.operation_linked'
'billing.checkout.operation_linked',
'billing.checkout.ended'
])
)
const [, , , , , submitted, linked] = journey()
Expand Down Expand Up @@ -798,3 +799,224 @@ describe('the embedded checkout journey', () => {
})
})
})

describe('the embedded checkout exits and endings', () => {
beforeEach(() => {
vi.mocked(datadogRum.getInitConfiguration).mockReturnValue({
clientToken: 'pub',
applicationId: 'app'
})
vi.spyOn(window.location, 'assign').mockImplementation(() => {})
vi.spyOn(window, 'close').mockImplementation(() => {})
})

const leavePage = () => {
window.dispatchEvent(new PageTransitionEvent('pagehide'))
}
const exitsOf = () =>
journey().filter(({ name }) => name === 'billing.checkout.abandoned')
const endingsOf = () =>
journey().filter(({ name }) => name === 'billing.checkout.ended')

it.for<{ name: string; leave: () => Promise<void> | void; exit: string }>([
{ name: 'the page goes away', leave: leavePage, exit: 'page_exit' },
{
name: 'the customer goes Back',
leave: () =>
userEvent.click(screen.getByRole('button', { name: 'Back' })),
exit: 'back'
},
{
name: 'the customer closes the checkout',
leave: () =>
userEvent.click(screen.getByRole('button', { name: 'Close' })),
exit: 'close'
}
])(
'reports a checkout abandoned once, at its last phase, when $name',
async ({ leave, exit }) => {
await renderCheckout()
await screen.findByRole('button', { name: 'Pay and subscribe' })
await waitFor(() =>
expect(journeyNames()).toContain('billing.checkout.preview_ready')
)

await leave()
leavePage()

expect(exitsOf()).toEqual([
expect.objectContaining({
phase: 'abandoned',
last_phase: 'preview_ready',
exit,
ui_mode: 'embedded',
billing_surface: 'billing_web'
})
])
}
)

it('reports no abandon for a page handed to a hosted payment step', async () => {
const fake = await renderCheckout()
await screen.findByRole('button', { name: 'Pay and subscribe' })

fake.publishOperation(
hostedPendingOperation('https://hooks.stripe.test/redirect/op_1')
)
await waitFor(() => expect(window.location.assign).toHaveBeenCalled())
leavePage()

expect(exitsOf()).toEqual([])
})

it('reports no abandon for a page that left for a payment method of its own site', async () => {
const fake = await renderCheckout()
await screen.findByRole('button', { name: 'Pay and subscribe' })
fake.subscribe.mockImplementation(() => new Promise(() => {}))

reportConfirm('ctoken_1', 'alipay')
await waitFor(() => expect(fake.subscribe).toHaveBeenCalled())
leavePage()

expect(exitsOf()).toEqual([])
})

it('reports a card Pay still in flight when the page goes away as abandoned', async () => {
const fake = await renderCheckout()
await screen.findByRole('button', { name: 'Pay and subscribe' })
fake.subscribe.mockImplementation(() => new Promise(() => {}))

reportConfirm('ctoken_1', 'card')
await waitFor(() => expect(fake.subscribe).toHaveBeenCalled())
leavePage()

expect(exitsOf()).toEqual([
expect.objectContaining({ last_phase: 'submitted', exit: 'page_exit' })
])
})

it.for<{ name: string; type: string; label: string; exits: number }>([
{
name: 'a saved Alipay account, which pays on its own site',
type: 'alipay',
label: 'Alipay',
exits: 0
},
{ name: 'a saved card', type: 'card', label: 'visa •••• 4242', exits: 1 }
])(
'reports $exits abandon when the page goes away during a Pay with $name',
async ({ type, label, exits }) => {
const fake = await renderCheckout(CHECKOUT_PATH, {
paymentMethods: {
status: 'ok',
value: [
{
id: 'pm_saved',
type,
brand: 'visa',
last4: '4242',
is_default: true
}
]
}
})
await screen.findByText(label)
fake.subscribe.mockImplementation(() => new Promise(() => {}))

await userEvent.click(
screen.getByRole('button', { name: 'Pay and subscribe' })
)
await waitFor(() => expect(fake.subscribe).toHaveBeenCalled())
leavePage()

expect(exitsOf()).toHaveLength(exits)
}
)

it('reports the success its own payment reached, and no abandon after it', async () => {
await renderCheckout(CHECKOUT_PATH, {
subscribe: {
status: 'ok',
value: { phase: 'succeeded', operation: succeededOperation('op_9') }
}
})
await screen.findByRole('button', { name: 'Pay and subscribe' })

reportConfirm('ctoken_1', 'card')
await screen.findByRole('heading', { name: "You're all set" })
await waitFor(() => expect(endingsOf()).toHaveLength(1))
const [, closeButton] = screen.getAllByRole('button', { name: 'Close' })
await userEvent.click(closeButton)
leavePage()

expect(endingsOf()).toEqual([
expect.objectContaining({
phase: 'ended',
ending_kind: 'success',
attribution: 'started',
billing_op_id: 'op_9'
})
])
expect(exitsOf()).toEqual([])
})

it('reports a success this page recovered rather than paid as followed', async () => {
await renderCheckout(CHECKOUT_PATH, {
recover: { status: 'ok', value: succeededOperation('op_old') }
})

await screen.findByRole('heading', { name: "You're all set" })
await waitFor(() => expect(endingsOf()).toHaveLength(1))

expect(endingsOf()[0]).toMatchObject({
ending_kind: 'success',
attribution: 'followed'
})
expect(endingsOf()[0]).not.toHaveProperty('billing_op_id')
})

it.for<{
name: string
preview: PreviewSubscribeResult
kind: string
}>([
{
name: 'a session the quote refused',
preview: { status: 'error', code: 'ACCESS_DENIED' },
kind: 'refused'
},
{
name: 'a plan the catalog does not have',
preview: {
status: 'error',
code: 'REQUEST_FAILED',
httpStatus: 400,
serverCode: readBillingErrorCode({
code: 'INVALID_PLAN',
message: 'unknown plan'
})
},
kind: 'plan_unavailable'
},
{
name: 'a quote that never got an answer',
preview: { status: 'error', code: 'REQUEST_FAILED' },
kind: 'load_failed'
}
])(
'reports the ending screen of $name without an attribution, and no abandon after it',
async ({ preview, kind }) => {
await renderCheckout(CHECKOUT_PATH, { preview })
await screen.findByRole('button', { name: 'Back' })

await userEvent.click(screen.getByRole('button', { name: 'Back' }))
leavePage()

expect(endingsOf()).toEqual([
expect.objectContaining({ phase: 'ended', ending_kind: kind })
])
expect(endingsOf()[0]).not.toHaveProperty('attribution')
expect(exitsOf()).toEqual([])
}
)
})
1 change: 1 addition & 0 deletions apps/billing-web/src/views/CheckoutView.streams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ describe('the embedded checkout journey beside the attempt and the SDK stream',
{ name: 'billing.operation.started', billingOpId: 'op_1' },
{ name: 'billing.checkout.operation_linked', billingOpId: 'op_1' },
{ name: 'billing.operation.succeeded', billingOpId: 'op_1' },
{ name: 'billing.checkout.ended', billingOpId: 'op_1' },
{ name: 'billing.subscription_checkout.succeeded', billingOpId: 'op_1' }
])
})
Expand Down
Loading
Loading