Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const StripeCardForm = ({ setupIntentSecret, billingAddressDetails, successUrl, isCreditCardStored }: StripeCardFormProps): React.Node => {
// eslint-disable-next-line flowtype/no-weak-types
const formRef = useRef(null)
const [cardErrorMessage, setCardErrorMessage] = useState(null)
const [isStripeFormVisible, setIsStripeFormVisible] = useState(!isCreditCardStored)
const [stripePaymentMethodId, setStripePaymentMethodId] = useState('')
const [formComplete, setFormComplete] = useState(false)
const stripe = useStripe()
const elements = useElements()
const toogleVisibility = () => setIsStripeFormVisible(!isStripeFormVisible)
const handleSubmit = async event => {
event.preventDefault()
setFormComplete(false)
if (!stripe || !elements) {
return
}
const { error, setupIntent } = await stripe.confirmCardSetup(setupIntentSecret, {
payment_method: {
card: elements.getElement(CardElement),
billing_details: {
address: billingAddressDetails