#mhdev
1 messages · Page 1 of 1 (latest)
Hi there!
Can you share the ID (req_xxx) of the failing API request?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
What is the best way to create and add a customer to a paymentintent once it has succeeded?
In the meanwhile, you can't add a customer to a succeeded PaymentIntent, you need to create a new PaymentIntent and set that customer to
Hi @foggy lark, thanks for the reply. Would you recommend to create the customer after the paymentintent is created? At the moment, the customer is getting added to the paymentintent. This is the code:
const paymentIntentObj = await stripe.paymentIntents.update(paymentIntent.id,
{ customer: customerObj.id },
{ stripeAccount: stripeEvent.account });
req_PcWUX2OzU6htSE
Our general recommendation is to create the Customer object first and then pass the cus_xxx ID to the customer parameter when creating the PI
Hi @fossil lotus, so once the paymentintent is created, create the customer obj and add the cus.id to the paymentintent? e.g.,
const paymentIntent = stripeEvent.data.object;
if (paymentIntent?.metadata?.email && stripeEvent.account) {
// 1. create customer
const customerObj = await stripe.customers.create({
email: paymentIntent?.metadata?.email,
name: paymentIntent?.metadata?.customerName,
phone: paymentIntent?.metadata?.phoneNumber,
address: {
city: paymentIntent?.metadata?.city,
state: paymentIntent?.metadata?.state,
country: paymentIntent?.metadata?.country,
line1: paymentIntent?.metadata?.addressLine1,
line2: paymentIntent?.metadata?.addressLine2,
postal_code: paymentIntent?.metadata?.postalCode
},
metadata: paymentIntent?.metadata
}, { stripeAccount: stripeEvent.account });
if (customerObj.id) {
// 2. update paymentintent with customer
const paymentIntentObj = await stripe.paymentIntents.update(paymentIntent.id,
{ customer: customerObj.id },
{ stripeAccount: stripeEvent.account });
console.log('paymentIntentObj', paymentIntentObj)
}
}
}
Yeah, that should work. Or alternatively create the customer first and it will reduce the # of API calls by 1
@fossil lotus amazing, thanks! another question: when a payment intent is confirmed from front end, does that guarantee that the intent status is "succeeded" in stripe?
It would depend on the Payment Intent parameters, and whether or not 3DS was requested/completed during confirmation
👋 taking over for my colleague. Let me know if there's any follow-up Qs I can answer!