#cole-redfearn
1 messages · Page 1 of 1 (latest)
Hey there
Really up to you, but I'd recommend using Payment Element so that you can easily add other payment method types later if you so desire
Thanks! With regard to creating the Payment Intent, should it be created right when the page renders, possibly in a useEffect hook, or would it be better to create it when the form that holds the Payment Element is submitted?
Payment Element requires a client secret to render, so you need to create the PaymentIntent when you are ready to render the Element. Many people do this on page load, but you could also do it on a button click for something like "add payment method".
Ok makes sense. I'm thinking we'll do it on page load, but the payment amount may change between when page loads and when user submits payment (this is for restaurant ordering so user has to select tip amount). Would you recommend creating the payment intent on page load and then updating payment intent with the correct payment amount when user submits the form for the payment element?
Yep you want fetchUpdates for that. See: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#fetch-updates
And yeah, you can call that on submission or when the amount updates. Mostly up to you as well on that front
Awesome, thanks for the help!