From b2e8328fa2e100cb4e31bfcd1887fc9d911077f9 Mon Sep 17 00:00:00 2001 From: Luke Mino-Altherr Date: Thu, 10 Sep 2026 16:35:18 -0700 Subject: [PATCH 1/4] feat(billing): collect billing address in embedded Stripe checkout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The embedded PaymentElement collected no billing address, so cards reached issuers with no AVS data (address_line1_check / address_postal_code_check unchecked). That raised declines for legitimate customers on the initial_subscription path and removed the anti-abuse friction the hosted Checkout page had. Add a Stripe Address Element in billing mode, created from the same Elements group as the PaymentElement. In billing mode every address field is required, and because both share one Elements group createConfirmationToken folds the address into the token's billing_details automatically — so the resulting PaymentIntent has billing_details.address populated and AVS runs. The existing elements.submit() gate already validates the mounted Address Element, blocking token creation until the address is complete. The subscription mode, off_session setupFutureUsage, paymentMethodConfiguration, terms:{card:'never'}, theme-aware appearance (shared across the Elements group), and redirect/hosted control path are all unchanged. The Address Element mirrors the PaymentElement's ready/loaderror telemetry handlers and is destroyed on unmount. --- src/locales/en/main.json | 1 + .../UnifiedStripePaymentSelector.test.ts | 114 ++++++++++++++++-- .../UnifiedStripePaymentSelector.vue | 29 +++++ 3 files changed, 131 insertions(+), 13 deletions(-) diff --git a/src/locales/en/main.json b/src/locales/en/main.json index d05c5564453..60f55ebc04c 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -3127,6 +3127,7 @@ "confirmChangeTitle": "Review your scheduled change", "paymentPopupBlocked": "Couldn't open the payment page — please allow popups and try again.", "paymentMethod": "Payment method", + "billingAddress": "Billing address", "stripeMethodChoice": "Your payment details are handled securely by Stripe.", "alipayRenewalNote": "Alipay authorization will also be used for automatic renewals and future purchases.", "payAndSubscribe": "Pay and subscribe", diff --git a/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts b/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts index b21220af129..2595b05a34a 100644 --- a/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts +++ b/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts @@ -24,9 +24,20 @@ const stripeMocks = vi.hoisted(() => { const mount = vi.fn() const destroy = vi.fn() const on = vi.fn() + const addressMount = vi.fn() + const addressDestroy = vi.fn() + const addressOn = vi.fn() const submit = vi.fn() const update = vi.fn() - const create = vi.fn(() => ({ mount, destroy, on })) + const paymentElement = { mount, destroy, on } + const addressElement = { + mount: addressMount, + destroy: addressDestroy, + on: addressOn + } + const create = vi.fn((type: string) => + type === 'address' ? addressElement : paymentElement + ) const elements = { submit, create, update } const createConfirmationToken = vi.fn() const stripe = { @@ -37,6 +48,9 @@ const stripeMocks = vi.hoisted(() => { mount, destroy, on, + addressMount, + addressDestroy, + addressOn, submit, update, create, @@ -60,6 +74,7 @@ const i18n = createI18n({ subscription: { preview: { paymentMethod: 'Payment method', + billingAddress: 'Billing address', stripeMethodChoice: 'Choose a payment method', alipayRenewalNote: 'Alipay renewal note', payAndSubscribe: 'Pay and subscribe', @@ -92,6 +107,13 @@ describe('UnifiedStripePaymentSelector', () => { handler?.[1]?.(arg) } + function fireAddressElementEvent(name: string, arg?: unknown) { + const handler = stripeMocks.addressOn.mock.calls.find( + ([event]) => event === name + ) + handler?.[1]?.(arg) + } + let seededJourneyId = '' beforeEach(() => { @@ -109,11 +131,19 @@ describe('UnifiedStripePaymentSelector', () => { vi.stubEnv('VITE_STRIPE_PUBLISHABLE_KEY', 'pk_test_example') stripeMocks.loadStripe.mockResolvedValue(stripeMocks.stripe) stripeMocks.stripe.elements.mockReturnValue(stripeMocks.elements) - stripeMocks.create.mockReturnValue({ - mount: stripeMocks.mount, - destroy: stripeMocks.destroy, - on: stripeMocks.on - }) + stripeMocks.create.mockImplementation((type: string) => + type === 'address' + ? { + mount: stripeMocks.addressMount, + destroy: stripeMocks.addressDestroy, + on: stripeMocks.addressOn + } + : { + mount: stripeMocks.mount, + destroy: stripeMocks.destroy, + on: stripeMocks.on + } + ) stripeMocks.submit.mockResolvedValue({}) stripeMocks.update.mockResolvedValue(undefined) stripeMocks.createConfirmationToken.mockResolvedValue({ @@ -153,6 +183,25 @@ describe('UnifiedStripePaymentSelector', () => { ) }) + it('reports an Address Element load failure as a mount failure', async () => { + renderSelector() + await waitFor(() => + expect(stripeMocks.addressMount).toHaveBeenCalledTimes(1) + ) + + fireAddressElementEvent('loaderror', { + error: { code: 'invalid_request' } + }) + + expect(mockCaptureCheckoutJourneyEvent).toHaveBeenCalledWith( + expect.objectContaining({ + phase: 'payment_element_failed', + element_phase: 'mount', + error_code: 'invalid_request' + }) + ) + }) + it('emits submit attempted before a validation failure', async () => { const user = userEvent.setup() stripeMocks.submit.mockResolvedValue({ @@ -278,6 +327,34 @@ describe('UnifiedStripePaymentSelector', () => { expect(emitted().confirm).toEqual([['ctoken_1']]) }) + it('collects a billing address alongside the payment element', async () => { + renderSelector() + + await waitFor(() => + expect(stripeMocks.create).toHaveBeenCalledWith('address', { + mode: 'billing' + }) + ) + expect(stripeMocks.addressMount).toHaveBeenCalledTimes(1) + }) + + it('blocks submission until the billing address is valid', async () => { + const user = userEvent.setup() + stripeMocks.submit.mockResolvedValue({ + error: { code: 'incomplete_address', message: 'Enter your address' } + }) + const { emitted } = renderSelector() + + await waitFor(() => + expect(stripeMocks.addressMount).toHaveBeenCalledTimes(1) + ) + await user.click(screen.getByRole('button', { name: 'Pay and subscribe' })) + + expect(await screen.findByText('Enter your address')).toBeTruthy() + expect(stripeMocks.createConfirmationToken).not.toHaveBeenCalled() + expect(emitted().confirm).toBeUndefined() + }) + it('keeps the customer in the form when Stripe rejects its contents', async () => { const user = userEvent.setup() stripeMocks.submit.mockResolvedValue({ @@ -370,13 +447,16 @@ describe('UnifiedStripePaymentSelector', () => { }) }) - it('destroys the Stripe element when the preview unmounts', async () => { + it('destroys the Stripe elements when the preview unmounts', async () => { const { unmount } = renderSelector() - await waitFor(() => expect(stripeMocks.mount).toHaveBeenCalledTimes(1)) + await waitFor(() => + expect(stripeMocks.addressMount).toHaveBeenCalledTimes(1) + ) unmount() expect(stripeMocks.destroy).toHaveBeenCalledTimes(1) + expect(stripeMocks.addressDestroy).toHaveBeenCalledTimes(1) }) }) @@ -385,11 +465,19 @@ describe('UnifiedStripePaymentSelector payment method configuration', () => { vi.stubEnv('VITE_STRIPE_PUBLISHABLE_KEY', 'pk_test_example') stripeMocks.loadStripe.mockResolvedValue(stripeMocks.stripe) stripeMocks.stripe.elements.mockReturnValue(stripeMocks.elements) - stripeMocks.create.mockReturnValue({ - mount: stripeMocks.mount, - destroy: stripeMocks.destroy, - on: stripeMocks.on - }) + stripeMocks.create.mockImplementation((type: string) => + type === 'address' + ? { + mount: stripeMocks.addressMount, + destroy: stripeMocks.addressDestroy, + on: stripeMocks.addressOn + } + : { + mount: stripeMocks.mount, + destroy: stripeMocks.destroy, + on: stripeMocks.on + } + ) }) it('mounts against the served configuration instead of a hardcoded method list', async () => { diff --git a/src/platform/workspace/components/UnifiedStripePaymentSelector.vue b/src/platform/workspace/components/UnifiedStripePaymentSelector.vue index b9c0519e222..2d9282bd2a0 100644 --- a/src/platform/workspace/components/UnifiedStripePaymentSelector.vue +++ b/src/platform/workspace/components/UnifiedStripePaymentSelector.vue @@ -22,6 +22,12 @@ class="flex flex-col gap-6 xl:min-h-0 xl:flex-1 xl:overflow-x-hidden xl:overflow-y-auto xl:pr-1" >
+
+

+ {{ $t('subscription.preview.billingAddress') }} +

+
+
import type { Stripe, + StripeAddressElement, StripeElements, StripePaymentElement } from '@stripe/stripe-js' @@ -107,12 +114,14 @@ function emitPaymentJourneyPhase(phase: CheckoutJourneyPhaseEvent): void { } const paymentElementTarget = ref() +const addressElementTarget = ref() const stripeElements = ref() const configurationError = ref('') const isSubmitting = ref(false) const selectedMethodType = ref('') let stripe: Stripe | null = null let paymentElement: StripePaymentElement | undefined +let addressElement: StripeAddressElement | undefined onMounted(async () => { const publishableKey = import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY @@ -240,6 +249,25 @@ onMounted(async () => { paymentElement.on('change', (event) => { selectedMethodType.value = event.value?.type ?? '' }) + + if (!addressElementTarget.value) return + // A full billing address feeds AVS to the issuer and Radar. In billing mode + // every field is required, and because the address shares this Elements + // group, createConfirmationToken folds it into the token's billing_details. + addressElement = stripeElements.value.create('address', { mode: 'billing' }) + addressElement.mount(addressElementTarget.value) + addressElement.on('ready', () => { + if (isUnmounted) return + emitPaymentJourneyPhase({ phase: 'payment_element_ready' }) + }) + addressElement.on('loaderror', (event) => { + if (isUnmounted) return + emitPaymentJourneyPhase({ + phase: 'payment_element_failed', + element_phase: 'mount', + ...(event.error?.code && { error_code: event.error.code }) + }) + }) }) watch([() => amountCents, () => currency], ([amount, nextCurrency]) => { @@ -260,6 +288,7 @@ watch([() => amountCents, () => currency], ([amount, nextCurrency]) => { onBeforeUnmount(() => { isUnmounted = true paymentElement?.destroy() + addressElement?.destroy() }) async function submit() { From 136f5f3ba3502e6570debc5cd139a34bebc4874d Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Mon, 14 Sep 2026 19:21:36 -0400 Subject: [PATCH 2/4] fix(billing): name the reporting element on payment element journey phases The Address Element shares the Elements group with the Payment Element, so both report 'ready' and 'loaderror'. Without a discriminator the funnel counts payment_element_ready twice per journey and cannot attribute a mount failure, which defeats the arm comparison these phases exist for. --- ...eckout-journey-instrumentation-contract.md | 6 ++++- .../telemetry/checkoutJourneyEvent.test.ts | 8 ++++-- src/platform/telemetry/types.ts | 9 ++++++- .../UnifiedStripePaymentSelector.test.ts | 25 +++++++++++++++++-- .../UnifiedStripePaymentSelector.vue | 17 +++++++++++-- 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/docs/adr/BILLING-CHECKOUT-0031-checkout-journey-instrumentation-contract.md b/docs/adr/BILLING-CHECKOUT-0031-checkout-journey-instrumentation-contract.md index a1998bdef76..8937da8d7db 100644 --- a/docs/adr/BILLING-CHECKOUT-0031-checkout-journey-instrumentation-contract.md +++ b/docs/adr/BILLING-CHECKOUT-0031-checkout-journey-instrumentation-contract.md @@ -59,7 +59,11 @@ Every event carries a frozen `CheckoutJourneyContext`: `checkout_journey_id`, `checkout_entered_at` (UTC), `assignment_status`, optional `assigned_arm`, `entry_flow`, `entry_source`, and optional `ui_mode`/`billing_op_id`. `ui_mode` records the checkout UI the user actually saw (`embedded`/`hosted`), -so a frozen arm can be reconciled against real experience. `schema_version` is +so a frozen arm can be reconciled against real experience. The two +`payment_element_*` phases additionally carry `element` (`payment`/`address`), +because the shared Elements group mounts more than one element and a funnel +that counts readiness or attributes a mount failure must know which one +reported it. `schema_version` is stamped on every payload. Correlation rides on `checkout_journey_id` (all events) and `billing_op_id` (from `operation_linked` onward, the join to the terminal `billing.*` taxonomy), plus each provider's own native event id diff --git a/src/platform/telemetry/checkoutJourneyEvent.test.ts b/src/platform/telemetry/checkoutJourneyEvent.test.ts index d1fa486d949..e696b73d966 100644 --- a/src/platform/telemetry/checkoutJourneyEvent.test.ts +++ b/src/platform/telemetry/checkoutJourneyEvent.test.ts @@ -110,15 +110,19 @@ describe('getCheckoutJourneyTelemetryEventPayload', () => { }) }) - it('distinguishes the element failure phase', () => { + it('distinguishes the failing element from the failure phase', () => { const event: CheckoutJourneyTelemetryEvent = { ...baseContext, phase: 'payment_element_failed', assignment_status: 'resolved', assigned_arm: 'treatment', + element: 'address', element_phase: 'mount' } const payload = getCheckoutJourneyTelemetryEventPayload(event) - expect(payload).toMatchObject({ element_phase: 'mount' }) + expect(payload).toMatchObject({ + element: 'address', + element_phase: 'mount' + }) }) }) diff --git a/src/platform/telemetry/types.ts b/src/platform/telemetry/types.ts index 412400deb0f..367a4f81728 100644 --- a/src/platform/telemetry/types.ts +++ b/src/platform/telemetry/types.ts @@ -1017,6 +1017,8 @@ export type CheckoutEntrySource = | 'other' | 'unknown' type CheckoutElementPhase = 'init' | 'mount' | 'update' +/** Which Stripe element in the shared group the observation came from. */ +type CheckoutElementKind = 'payment' | 'address' type CheckoutSubmitPhase = 'validation' | 'token_creation' /** @@ -1054,9 +1056,13 @@ type CheckoutJourneyPreviewFailed = { error_code?: BillingErrorCode preview_revision?: string } -type CheckoutJourneyPaymentElementReady = { phase: 'payment_element_ready' } +type CheckoutJourneyPaymentElementReady = { + phase: 'payment_element_ready' + element: CheckoutElementKind +} type CheckoutJourneyPaymentElementFailed = { phase: 'payment_element_failed' + element: CheckoutElementKind element_phase: CheckoutElementPhase error_code?: string } @@ -1146,6 +1152,7 @@ export function getCheckoutJourneyTelemetryEventPayload( }), ...('error_code' in event && event.error_code !== undefined && { error_code: event.error_code }), + ...('element' in event && { element: event.element }), ...('element_phase' in event && { element_phase: event.element_phase }), ...('submit_phase' in event && { submit_phase: event.submit_phase }) } diff --git a/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts b/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts index 2595b05a34a..68070421edf 100644 --- a/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts +++ b/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts @@ -161,8 +161,27 @@ describe('UnifiedStripePaymentSelector', () => { fireStripeElementEvent('ready') expect(mockTrackCheckoutJourneyEvent).toHaveBeenCalledWith( - expect.objectContaining({ phase: 'payment_element_ready' }) + expect.objectContaining({ + phase: 'payment_element_ready', + element: 'payment' + }) + ) + }) + + it('distinguishes the address readiness from the payment element', async () => { + renderSelector() + await waitFor(() => + expect(stripeMocks.addressMount).toHaveBeenCalledTimes(1) ) + + fireStripeElementEvent('ready') + fireAddressElementEvent('ready') + + const readyElements = mockTrackCheckoutJourneyEvent.mock.calls + .map(([event]) => event) + .filter((event) => event.phase === 'payment_element_ready') + .map((event) => event.element) + expect(readyElements).toStrictEqual(['payment', 'address']) }) it('reports a mount failure with a safe code from loaderror', async () => { @@ -177,6 +196,7 @@ describe('UnifiedStripePaymentSelector', () => { expect.objectContaining({ checkout_journey_id: seededJourneyId, phase: 'payment_element_failed', + element: 'payment', element_phase: 'mount', error_code: 'invalid_request' }) @@ -193,9 +213,10 @@ describe('UnifiedStripePaymentSelector', () => { error: { code: 'invalid_request' } }) - expect(mockCaptureCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(mockTrackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'payment_element_failed', + element: 'address', element_phase: 'mount', error_code: 'invalid_request' }) diff --git a/src/platform/workspace/components/UnifiedStripePaymentSelector.vue b/src/platform/workspace/components/UnifiedStripePaymentSelector.vue index 2d9282bd2a0..ba64f20d603 100644 --- a/src/platform/workspace/components/UnifiedStripePaymentSelector.vue +++ b/src/platform/workspace/components/UnifiedStripePaymentSelector.vue @@ -129,6 +129,7 @@ onMounted(async () => { configurationError.value = t('subscription.preview.stripeUnavailable') emitPaymentJourneyPhase({ phase: 'payment_element_failed', + element: 'payment', element_phase: 'init' }) return @@ -137,6 +138,7 @@ onMounted(async () => { configurationError.value = t('subscription.preview.stripeUnavailable') emitPaymentJourneyPhase({ phase: 'payment_element_failed', + element: 'payment', element_phase: 'init' }) return @@ -153,6 +155,7 @@ onMounted(async () => { configurationError.value = t('subscription.preview.stripeUnavailable') emitPaymentJourneyPhase({ phase: 'payment_element_failed', + element: 'payment', element_phase: 'init' }) return @@ -162,6 +165,7 @@ onMounted(async () => { if (!isUnmounted) { emitPaymentJourneyPhase({ phase: 'payment_element_failed', + element: 'payment', element_phase: 'init' }) } @@ -234,12 +238,16 @@ onMounted(async () => { paymentElement.mount(paymentElementTarget.value) paymentElement.on('ready', () => { if (isUnmounted) return - emitPaymentJourneyPhase({ phase: 'payment_element_ready' }) + emitPaymentJourneyPhase({ + phase: 'payment_element_ready', + element: 'payment' + }) }) paymentElement.on('loaderror', (event) => { if (isUnmounted) return emitPaymentJourneyPhase({ phase: 'payment_element_failed', + element: 'payment', element_phase: 'mount', ...(event.error?.code && { error_code: event.error.code }) }) @@ -258,12 +266,16 @@ onMounted(async () => { addressElement.mount(addressElementTarget.value) addressElement.on('ready', () => { if (isUnmounted) return - emitPaymentJourneyPhase({ phase: 'payment_element_ready' }) + emitPaymentJourneyPhase({ + phase: 'payment_element_ready', + element: 'address' + }) }) addressElement.on('loaderror', (event) => { if (isUnmounted) return emitPaymentJourneyPhase({ phase: 'payment_element_failed', + element: 'address', element_phase: 'mount', ...(event.error?.code && { error_code: event.error.code }) }) @@ -280,6 +292,7 @@ watch([() => amountCents, () => currency], ([amount, nextCurrency]) => { configurationError.value = t('g.error') emitPaymentJourneyPhase({ phase: 'payment_element_failed', + element: 'payment', element_phase: 'update' }) }) From e8f149ac9ad332792af3758048ec1ab8a90f0d11 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Mon, 14 Sep 2026 19:53:11 -0400 Subject: [PATCH 3/4] refactor(billing): extract the Stripe element mounts from onMounted Adding the Address Element pushed the 158-line onMounted past the complexity gate; each element now owns its creation, mount and telemetry wiring. --- .../UnifiedStripePaymentSelector.vue | 163 +++++++++--------- 1 file changed, 82 insertions(+), 81 deletions(-) diff --git a/src/platform/workspace/components/UnifiedStripePaymentSelector.vue b/src/platform/workspace/components/UnifiedStripePaymentSelector.vue index ba64f20d603..d76bd9a7307 100644 --- a/src/platform/workspace/components/UnifiedStripePaymentSelector.vue +++ b/src/platform/workspace/components/UnifiedStripePaymentSelector.vue @@ -123,24 +123,89 @@ let stripe: Stripe | null = null let paymentElement: StripePaymentElement | undefined let addressElement: StripeAddressElement | undefined -onMounted(async () => { - const publishableKey = import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY - if (!publishableKey) { - configurationError.value = t('subscription.preview.stripeUnavailable') +function failElementInit(): void { + configurationError.value = t('subscription.preview.stripeUnavailable') + if (isUnmounted) return + emitPaymentJourneyPhase({ + phase: 'payment_element_failed', + element: 'payment', + element_phase: 'init' + }) +} + +function mountPaymentElement( + elements: StripeElements, + target: HTMLDivElement +): void { + paymentElement = elements.create('payment', { + layout: { + type: 'accordion', + defaultCollapsed: false, + radios: 'always', + spacedAccordionItems: true + }, + // Our terms note carries the recurring-charge authorization; Stripe's + // card mandate text would say it twice. + terms: { card: 'never' } + }) + paymentElement.mount(target) + paymentElement.on('ready', () => { + if (isUnmounted) return + emitPaymentJourneyPhase({ + phase: 'payment_element_ready', + element: 'payment' + }) + }) + paymentElement.on('loaderror', (event) => { + if (isUnmounted) return emitPaymentJourneyPhase({ phase: 'payment_element_failed', element: 'payment', - element_phase: 'init' + element_phase: 'mount', + ...(event.error?.code && { error_code: event.error.code }) }) - return - } - if (!paymentMethodConfigurationId) { - configurationError.value = t('subscription.preview.stripeUnavailable') + }) + // Method-specific notes (e.g. the Alipay auto-renewal disclosure) key off + // whichever payment method the user has selected inside the element. + paymentElement.on('change', (event) => { + selectedMethodType.value = event.value?.type ?? '' + }) +} + +/** + * A full billing address feeds AVS to the issuer and Radar. In billing mode + * every field is required, and because the address shares the Payment + * Element's group, createConfirmationToken folds it into the token's + * billing_details. + */ +function mountAddressElement( + elements: StripeElements, + target: HTMLDivElement +): void { + addressElement = elements.create('address', { mode: 'billing' }) + addressElement.mount(target) + addressElement.on('ready', () => { + if (isUnmounted) return + emitPaymentJourneyPhase({ + phase: 'payment_element_ready', + element: 'address' + }) + }) + addressElement.on('loaderror', (event) => { + if (isUnmounted) return emitPaymentJourneyPhase({ phase: 'payment_element_failed', - element: 'payment', - element_phase: 'init' + element: 'address', + element_phase: 'mount', + ...(event.error?.code && { error_code: event.error.code }) }) + }) +} + +onMounted(async () => { + const publishableKey = import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY + if (!publishableKey || !paymentMethodConfigurationId) { + failElementInit() return } // A non-positive amount means the caller mounted this before its quote @@ -152,23 +217,11 @@ onMounted(async () => { try { stripe = await loadStripe(publishableKey) } catch { - configurationError.value = t('subscription.preview.stripeUnavailable') - emitPaymentJourneyPhase({ - phase: 'payment_element_failed', - element: 'payment', - element_phase: 'init' - }) + failElementInit() return } if (!stripe || !paymentElementTarget.value || isUnmounted) { - configurationError.value = t('subscription.preview.stripeUnavailable') - if (!isUnmounted) { - emitPaymentJourneyPhase({ - phase: 'payment_element_failed', - element: 'payment', - element_phase: 'init' - }) - } + failElementInit() return } @@ -224,62 +277,10 @@ onMounted(async () => { } } }) - paymentElement = stripeElements.value.create('payment', { - layout: { - type: 'accordion', - defaultCollapsed: false, - radios: 'always', - spacedAccordionItems: true - }, - // Our terms note carries the recurring-charge authorization; Stripe's - // card mandate text would say it twice. - terms: { card: 'never' } - }) - paymentElement.mount(paymentElementTarget.value) - paymentElement.on('ready', () => { - if (isUnmounted) return - emitPaymentJourneyPhase({ - phase: 'payment_element_ready', - element: 'payment' - }) - }) - paymentElement.on('loaderror', (event) => { - if (isUnmounted) return - emitPaymentJourneyPhase({ - phase: 'payment_element_failed', - element: 'payment', - element_phase: 'mount', - ...(event.error?.code && { error_code: event.error.code }) - }) - }) - // Method-specific notes (e.g. the Alipay auto-renewal disclosure) key off - // whichever payment method the user has selected inside the element. - paymentElement.on('change', (event) => { - selectedMethodType.value = event.value?.type ?? '' - }) - - if (!addressElementTarget.value) return - // A full billing address feeds AVS to the issuer and Radar. In billing mode - // every field is required, and because the address shares this Elements - // group, createConfirmationToken folds it into the token's billing_details. - addressElement = stripeElements.value.create('address', { mode: 'billing' }) - addressElement.mount(addressElementTarget.value) - addressElement.on('ready', () => { - if (isUnmounted) return - emitPaymentJourneyPhase({ - phase: 'payment_element_ready', - element: 'address' - }) - }) - addressElement.on('loaderror', (event) => { - if (isUnmounted) return - emitPaymentJourneyPhase({ - phase: 'payment_element_failed', - element: 'address', - element_phase: 'mount', - ...(event.error?.code && { error_code: event.error.code }) - }) - }) + mountPaymentElement(stripeElements.value, paymentElementTarget.value) + if (addressElementTarget.value) { + mountAddressElement(stripeElements.value, addressElementTarget.value) + } }) watch([() => amountCents, () => currency], ([amount, nextCurrency]) => { From 93d34d92d5b94a0b54684767bedae9074a26fb4d Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Tue, 15 Sep 2026 07:01:05 -0400 Subject: [PATCH 4/4] fix(billing): make the Address Element the only billing address collected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Payment Element defaults fields.billingDetails to 'auto', so card also rendered its own country and postal inputs above the new Address Element. A customer filling the two differently would send the issuer an address that contradicts the one collected for AVS — the opposite of this change's purpose. --- .../UnifiedStripePaymentSelector.test.ts | 18 ++++++++++++++++++ .../UnifiedStripePaymentSelector.vue | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts b/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts index 68070421edf..bc4c36b37e2 100644 --- a/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts +++ b/src/platform/workspace/components/UnifiedStripePaymentSelector.test.ts @@ -153,6 +153,23 @@ describe('UnifiedStripePaymentSelector', () => { afterEach(cleanup) + it('leaves billing address collection to the Address Element alone', async () => { + renderSelector() + await waitFor(() => expect(stripeMocks.mount).toHaveBeenCalled()) + + // Two address forms in one group can disagree, and the one the issuer sees + // would then contradict the one collected for AVS. + expect(stripeMocks.create).toHaveBeenCalledWith( + 'payment', + expect.objectContaining({ + fields: { billingDetails: { address: 'never' } } + }) + ) + expect(stripeMocks.create).toHaveBeenCalledWith('address', { + mode: 'billing' + }) + }) + describe('checkout journey instrumentation', () => { it('emits payment_element_ready on the ready callback for the live mount', async () => { renderSelector() @@ -331,6 +348,7 @@ describe('UnifiedStripePaymentSelector', () => { radios: 'always', spacedAccordionItems: true }, + fields: { billingDetails: { address: 'never' } }, terms: { card: 'never' } }) expect(stripeMocks.mount).toHaveBeenCalledTimes(1) diff --git a/src/platform/workspace/components/UnifiedStripePaymentSelector.vue b/src/platform/workspace/components/UnifiedStripePaymentSelector.vue index d76bd9a7307..5d370e9ca2f 100644 --- a/src/platform/workspace/components/UnifiedStripePaymentSelector.vue +++ b/src/platform/workspace/components/UnifiedStripePaymentSelector.vue @@ -144,6 +144,11 @@ function mountPaymentElement( radios: 'always', spacedAccordionItems: true }, + // The Address Element below is the single source of billing address. + // Left at the default, card would also render its own country/postal + // inputs, and a customer who filled the two differently would send the + // issuer an address that contradicts the one we collected for AVS. + fields: { billingDetails: { address: 'never' } }, // Our terms note carries the recurring-charge authorization; Stripe's // card mandate text would say it twice. terms: { card: 'never' }