#Steve Sizer
1 messages ยท Page 1 of 1 (latest)
Hi ๐
No this isn't something you can do AFAIK.
I'm just using the new payment element at the moment and you have to create a payment intent first, so i dont have any client details at that point...
Does the Payment Intent have a value in the customer property?
intent = Stripe::PaymentIntent.create({
amount: price.to_i,
currency: 'usd',
automatic_payment_methods: {
enabled: true,
},
})
no. I just create the payment intent
๐ stepping in as Snufkin needs to step away
Can i create a customer just before the confirm payment?
Yep you can
There are basically two options
You can either update the PaymentIntent before confirmation to include a Customer ID
Or you can use setup_future_usage with the PaymentIntent, then you attach the PaymentMethod to the Customer after the PaymentIntent is confirmed
That will associate the PaymentIntent and PaymentMethod to that Customer
so before i call confirm payment i do the following which returns a customer
const {
data: { error, customer, amount },
} = await axiosInstance.post(/playlists/${playlist.slug}/purchase, {
coupon_code: coupon.current.value,
first_name: firstName,
last_name: lastName,
email: email,
phone: phone,
});
so what i could do is pass the payment intent as a param in the above call and attach it to the customer here
This only seemed to occur though with testing google payments i don't know if that has anything to do with it?
The above code is frontend code where you are making an Axios request, no?
That is not where you create a Customer nor PaymentIntent
That all happens in your backend
Let's back up a second
What are you trying to accomplish?
I've already created a payment intent, so in the above axios request where i create and return the customer could i not pass the payment intent previously created on the initial page load. And attach it to said returned customer?
hope this makes sense
No not really. You don't "attach PaymentIntents to customers". You attach PaymentMethods to Customers, and then any PaymentIntent paid with that PaymentMethod would also be associated with that Customer.
So you would want to do what I stated before. When you create your PaymentIntent you pass setup_future_usage: https://stripe.com/docs/api/payment_intents/create#create_payment_intent-setup_future_usage
This allows you to later attach a PaymentMethod created from that PaymentIntent to a Customer
awesome thank you ๐