Skip to content

Commit

Permalink
refs #921 Catch possible errors in stripe payment
Browse files Browse the repository at this point in the history
  • Loading branch information
elboletaire committed Jan 8, 2025
1 parent 80e4127 commit 88bcfa0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/components/Pricing/SubscriptionPayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ModalFooter,
ModalOverlay,
Text,
useToast,
} from '@chakra-ui/react'
import { EmbeddedCheckout, EmbeddedCheckoutProvider } from '@stripe/react-stripe-js'
import { loadStripe, Stripe } from '@stripe/stripe-js'
Expand Down Expand Up @@ -57,6 +58,7 @@ export const SubscriptionPayment = ({ amount, lookupKey }: SubscriptionPaymentDa
const { subscription } = useSubscription()
const { mutateAsync: checkSubscription } = useUpdateSubscription()
const { closeModal } = usePricingModal()
const toast = useToast()

const [stripePromise] = useState<Promise<Stripe | null>>(
loadStripe(stripePublicKey, {
Expand All @@ -82,6 +84,16 @@ export const SubscriptionPayment = ({ amount, lookupKey }: SubscriptionPaymentDa
})
// Return the client secret, required by stripe.js
.then((data) => data.clientSecret)
.catch((e) => {
toast({
status: 'error',
title: i18n.t('pricing.error'),
description: e.message,
})
closeModal()

return null
})
}
return await Promise.resolve('')
}, [signer])
Expand Down

0 comments on commit 88bcfa0

Please sign in to comment.