Files
Verso/services/web/frontend/js/features/subscription/util/handle-stripe-payment-action.ts
T
Kristina a8df91e91b Merge pull request #26087 from overleaf/mf-change-to-stripe-uk
[web] Configure to use Stripe UK account

GitOrigin-RevId: 0856f6da2caae8caf9887ec2acea8e7f0972e598
2025-06-09 08:05:09 +00:00

30 lines
1001 B
TypeScript

import { FetchError, postJSON } from '@/infrastructure/fetch-json'
import getMeta from '../../../utils/meta'
import { loadStripe } from '@stripe/stripe-js/pure'
export default async function handleStripePaymentAction(
error: FetchError
): Promise<{ handled: boolean }> {
const clientSecret = error?.data?.clientSecret
if (clientSecret) {
// TODO: support both US and UK Stripe accounts
const stripeUKPublicKey = getMeta('ol-stripeUKApiKey')
const stripe = await loadStripe(stripeUKPublicKey)
if (stripe) {
const manualConfirmationFlow =
await stripe.confirmCardPayment(clientSecret)
if (!manualConfirmationFlow.error) {
try {
await postJSON(`/user/subscription/sync`)
} catch (error) {
// if the sync fails, there may be stale data until the webhook is
// processed but we can't do any special handling for that in here
}
return { handled: true }
}
}
}
return { handled: false }
}