mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-07-29 23:00:08 +02:00

[web] support 3DS for Stripe US GitOrigin-RevId: b798b59601f3fb0df54afbcfb19434fbb0b38cdf
27 lines
896 B
TypeScript
27 lines
896 B
TypeScript
import { FetchError, postJSON } from '@/infrastructure/fetch-json'
|
|
import { loadStripe } from '@stripe/stripe-js/pure'
|
|
|
|
export default async function handleStripePaymentAction(
|
|
error: FetchError
|
|
): Promise<{ handled: boolean }> {
|
|
const clientSecret = error?.data?.clientSecret
|
|
const publicKey = error?.data?.publicKey
|
|
|
|
if (clientSecret && publicKey) {
|
|
const stripe = await loadStripe(publicKey)
|
|
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 }
|
|
}
|