#Iconer-pi-elements
1 messages · Page 1 of 1 (latest)
Hey, can you share the code that throws the error?
Why are you creating a new PI?
Hi, thanks for your response. I've reused the code is triggered when the payment form is loaded in first place, so it will create a new PI as part of it. I didn't though about updating it
will updating a PI be a better approach?
It depends on what it is you're updating
How though?
Yes, but Payment Intents don't support our Price objects. So what's the actual update call look like
sorry, I made you confuse. this is the code for PI:
$order = $stripe->paymentIntents->create([
'amount' => $price_details->unit_amount,
'currency' => $price_details->currency,
'metadata' => [
'stripe_price_id' => $request->stripe_price_id
],
'customer' => $request->user()->stripe_customer_id
]);
when user changes the option amount and metadata will be changed
Ok, sure. Personally I'd recommend just updating the existing Payment Intent
Are you using the Payment Element?
If so, you can call elements.fetchUpdates() (https://stripe.com/docs/js/elements_object/fetch_updates) and it'll update the Payment Element to reflect the updated PI
yes, was about to ask if Payment Element is a JS side.
will PI return new client_secret after update?
No, it'll be the same. So you can just call fetchUpdates() and the Payment Element will update
No need to tear it down and initialise a new one with a different client secret
I imagine that'll fix the issue you're seeing
great, I will give it a try. Thanks for your help!