I am using stripe in a next.js application in order to accept one time payments and so far have been following the standard tutorial for Stripe Elements.
The way it works is that I create a PaymentIntent
on first render:
useEffect(() => {
// Create PaymentIntent as soon as the page loads
// using nextjs api route here:
fetch('http://localhost:3001/api/create-payment-intent', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
})
.then((res) => res.json())
.then((data) => setClientSecret(data.clientSecret));
}, []);
This gives me a clientSecret, which is store in state. Then, Stripes Payment Element Component is being displayed and on submit, I am calling confirmPayment
:
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
// Make sure to change this to your payment completion page
return_url:
'http://localhost:3001/confirm'
}
});
My problem is that I want to also grab the users name and email address, but I have no clue where I would capture those and where to send them to in stripe?
I guess it would make the most sense to create a new customer in stripe and add name
and email
to that customer object. But since almost everything is happening in the frontend (or at least not on my backend), I don't understand how to do that? I could do it when I create the PaymentIntent
and send back the clientSecret
- but then I would potentially be creating customers, even when they don't complete the payment intent.
PS: I know that this question has been asked a few times before, but Stripes API has changed quite significantly since then.