From ca567adca2582b7a3dc5e95772004dd6a34078e4 Mon Sep 17 00:00:00 2001 From: Dante Date: Wed, 28 Oct 2026 12:11:12 +0000 Subject: [PATCH] FE-3562 fix(billing-web): card-only Elements for pay-once top-ups, keep this tab's decline card (#22085) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Why On staging, every new-card top-up on billing-web's pay-once form failed. `POST /api/billing/topup/interactive` answered `pending`, the operation sat at `authentication_state: processing` for ~165s, then ended `failed` / `topup_invoice_payment_failed` with nothing charged. The decline test card failed the same way instead of declining at once, and when the operation finally failed the page went back to the form with no "Payment declined" card. ## Root cause 1. `StripePaymentForm` built the pay-once Elements in automatic mode with the served `paymentMethodConfiguration`, while the backend creates the top-up invoice PaymentIntent with `payment_method_types=['card']`. Stripe rejects a confirmation token from automatic-mode Elements against that PaymentIntent; the worker's ten retries explain the delay (traced on the Stripe test-mode requests). 2. When this tab's own Pay outlived its watch (`payRejectedAsPending`), the re-read landed in `waitingInCapture`, which always marked the operation `sibling: true`. A sibling's verdict belongs to another tab, so the decline reset the form with no card. ## How - Pay-once Elements: `paymentMethodTypes: ['card']`, no `paymentMethodConfiguration`, and `wallets.link: 'never'` on the Payment Element (without the card-only configuration Stripe otherwise adds Link's bank, Klarna and crypto options, which the card-only invoice would refuse). The subscription form is unchanged; the backend card-only / no-future-use guards stay. - `waitingInCapture`: an operation this tab awaited (`awaitedHere`) is not a sibling, so its verdict lands on its own card. Part of FE-3562 ## Tests - `StripePaymentForm.test.ts`: paying once mounts card-only Elements with no configuration and Link off (red before the fix). - `checkoutPage.test.ts`: this tab's own Pay whose watch lapsed declines onto its card once the re-read settles (red before the fix). ## AS IS / TO BE Local billing-web against staging, Stripe test mode. | | AS IS | TO BE | | --- | --- | --- | | New card form | _pending_ | _pending_ | | New card 4242 Pay | _pending_ | _pending_ | | Decline 4000…0002 | _pending_ | _pending_ | ## Plan position | Item | PR | Status | | --- | --- | --- | | Top-up limit server message | https://github.com/Comfy-Org/ComfyUI_frontend/pull/22072 | In review | | **Pay-once card-only Elements + own decline card** | **this PR** | **In review** | | New-card payment acceptance on staging | (after this PR) | Blocked on this PR | ```mermaid graph LR A["Card-only Elements (this PR)"] --> B["New-card acceptance on staging"] style A fill:#f9d71c,stroke:#333,stroke-width:2px ``` --- .../src/checkout/checkoutPage.test.ts | 27 +++++++++++++++++++ apps/billing-web/src/checkout/checkoutPage.ts | 4 ++- .../billing/stripe/StripePaymentForm.test.ts | 13 +++++++-- .../src/billing/stripe/StripePaymentForm.vue | 14 ++++++---- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/apps/billing-web/src/checkout/checkoutPage.test.ts b/apps/billing-web/src/checkout/checkoutPage.test.ts index b719ba19e37..50e667c6f8e 100644 --- a/apps/billing-web/src/checkout/checkoutPage.test.ts +++ b/apps/billing-web/src/checkout/checkoutPage.test.ts @@ -794,6 +794,33 @@ describe('reduceCheckoutPage reconciliation', () => { ], expected: { kind: 'resolving', outcome: declinedElsewhere } }, + { + name: "this tab's own Pay whose watch lapsed declines onto its card once the re-read settles", + events: [ + ...live, + submitted, + { type: 'payRejectedAsPending', because: 'unanswered' }, + reconciled({ ...pendingOperation(), awaitedHere: true }), + changed(failedOperation('card_declined'), declinedElsewhere) + ], + expected: { kind: 'resolving', outcome: declinedElsewhere } + }, + { + name: "this tab's own Pay whose watch lapsed keeps its card when the re-read finds the challenge refused", + events: [ + ...live, + submitted, + { type: 'payRejectedAsPending', because: 'unanswered' }, + reconciled( + { ...refusedChallenge(), awaitedHere: true }, + { kind: 'not_completed', operationId: 'op_3ds' } + ) + ], + expected: { + kind: 'resolving', + outcome: { kind: 'not_completed', operationId: 'op_3ds' } + } + }, { name: 'a form that watched another tab start paying is waiting on a sibling', events: [...live, reconciled(pendingOperation())], diff --git a/apps/billing-web/src/checkout/checkoutPage.ts b/apps/billing-web/src/checkout/checkoutPage.ts index 33da2a471e7..62176c26ad1 100644 --- a/apps/billing-web/src/checkout/checkoutPage.ts +++ b/apps/billing-web/src/checkout/checkoutPage.ts @@ -1104,12 +1104,14 @@ function waitingInCapture( operation: BillingOperationState, outcome: OperationOutcome | undefined ): CheckoutPage { + if (outcome !== undefined && operation.awaitedHere) + return { kind: 'resolving', outcome } if (!isInFlight(operation) || outcome !== undefined) return nothingPending(page) return { kind: 'waiting', operation, - sibling: true, + ...(operation.awaitedHere ? {} : { sibling: true }), ...(awaitsUnansweredPay(page) ? { unanswered: true } : {}), rail: page.rail } diff --git a/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts b/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts index 68c95af4733..f673fce3d4d 100644 --- a/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts +++ b/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts @@ -421,7 +421,7 @@ describe('StripePaymentForm', () => { }) }) - it('collects a one-time payment the card is never saved for when paying once', async () => { + it('collects a one-time card payment the card is never saved for when paying once', async () => { renderForm(2500, 'pmc_topup', { payOnce: true }) await waitFor(() => @@ -432,12 +432,21 @@ describe('StripePaymentForm', () => { mode: 'payment', amount: 2500, currency: 'usd', - paymentMethodConfiguration: 'pmc_topup' + paymentMethodTypes: ['card'] }) ) expect(stripeMocks.stripe.elements).not.toHaveBeenCalledWith( expect.objectContaining({ setupFutureUsage: expect.anything() }) ) + expect(stripeMocks.stripe.elements).not.toHaveBeenCalledWith( + expect.objectContaining({ + paymentMethodConfiguration: expect.anything() + }) + ) + expect(stripeMocks.create).toHaveBeenCalledWith( + 'payment', + expect.objectContaining({ wallets: { link: 'never' } }) + ) }) it('collects deferred subscription details and emits a confirmation token', async () => { diff --git a/packages/account-ui/src/billing/stripe/StripePaymentForm.vue b/packages/account-ui/src/billing/stripe/StripePaymentForm.vue index bbc86a52424..ceffa24b03f 100644 --- a/packages/account-ui/src/billing/stripe/StripePaymentForm.vue +++ b/packages/account-ui/src/billing/stripe/StripePaymentForm.vue @@ -106,8 +106,8 @@ const { amountCents: number currency: string copy: StripePaymentCopy - /** Stripe payment method configuration governing which methods Elements - * offers (served per-environment by the preview). */ + /** Stripe payment method configuration governing which methods a subscription + * offers (served per-environment by the preview); paying once is card only. */ paymentMethodConfigurationId?: string isLoading?: boolean /** A 3DS verification is pending: the host's own verification action is @@ -197,6 +197,7 @@ function mountPaymentElement( // 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' } }, + ...(payOnce ? { wallets: { link: 'never' as const } } : {}), // The host's terms note carries the recurring-charge authorization; // Stripe's card mandate text would say it twice. terms: { card: 'never' } @@ -247,8 +248,12 @@ function mountAddressElement( function intentOptions() { return payOnce - ? ({ mode: 'payment' } as const) - : ({ mode: 'subscription', setupFutureUsage: 'off_session' } as const) + ? { mode: 'payment' as const, paymentMethodTypes: ['card'] } + : { + mode: 'subscription' as const, + setupFutureUsage: 'off_session' as const, + paymentMethodConfiguration: paymentMethodConfigurationId + } } onMounted(async () => { @@ -272,7 +277,6 @@ onMounted(async () => { ...intentOptions(), amount: amountCents, currency: currency.toLowerCase(), - paymentMethodConfiguration: paymentMethodConfigurationId, appearance: resolveAppearance(paymentElementTarget.value) }) mountPaymentElement(stripeElements.value, paymentElementTarget.value)