#Iconer-pi-elements

1 messages · Page 1 of 1 (latest)

midnight hatch
#

Hey, can you share the code that throws the error?

#

Why are you creating a new PI?

glacial dragon
#

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?

midnight hatch
#

It depends on what it is you're updating

glacial dragon
#

price id

#

and value

midnight hatch
#

Which paramater is 'price id'?

#

How are you reloading the Element?

glacial dragon
#

it's this same service just with different price

#

yes, I'm reloading the element

midnight hatch
#

How though?

midnight hatch
glacial dragon
#

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

midnight hatch
#

Ok, sure. Personally I'd recommend just updating the existing Payment Intent

#

Are you using the Payment Element?

glacial dragon
#

yes, was about to ask if Payment Element is a JS side.

#

will PI return new client_secret after update?

midnight hatch
#

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

glacial dragon
#

great, I will give it a try. Thanks for your help!