Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions apps/billing-web/src/checkout/checkoutPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())],
Expand Down
4 changes: 3 additions & 1 deletion apps/billing-web/src/checkout/checkoutPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 11 additions & 2 deletions packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
Expand All @@ -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 () => {
Expand Down
14 changes: 9 additions & 5 deletions packages/account-ui/src/billing/stripe/StripePaymentForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' }
Expand Down Expand Up @@ -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 () => {
Expand All @@ -272,7 +277,6 @@ onMounted(async () => {
...intentOptions(),
amount: amountCents,
currency: currency.toLowerCase(),
paymentMethodConfiguration: paymentMethodConfigurationId,
appearance: resolveAppearance(paymentElementTarget.value)
})
mountPaymentElement(stripeElements.value, paymentElementTarget.value)
Expand Down
Loading