#Adaman
1 messages · Page 1 of 1 (latest)
Hi @reef marsh
Got a few questions for you if that's cool, sorry I'm new to stripe
Sure thing
So I'm trying to set up elements on my site and I'm using dynamic pricing. Having looked at the docs I'm meant to set up a paymentIntent on page load. I can do that, but I need to be able to update it based on what the user enters in the form in order to get the correct pricing.
In essence what I need to know is:
- should I create the paymentIntent on page load or when I am ready to take payment and if on page load is there a way to update them?
- Is there a way of creating line items within a payment intent? (I watched the great dynamic pricing video on yt but that seems to be for checkout)
sorry for the long winded explaination
1/ Either way is fine really. You can update a PaymentIntent before it is confirmed. However I would mostly recommend just waiting until the customer is ready for payment otherwise you will end up with a lot of incomplete PaymentIntents (which is fine but will just cause some Dashboard clutter) and then you will make less updates.
2/ No line items aren't supported with PaymentIntents. You basically just want to track your line items in your own database, or you could add them as metadata to your PaymentIntent.
- Perfect thanks
- That's fine, so the invoice would just be a total amount unless I override it or create my own one?
There are no invoices associated with PaymentIntents if you create PaymentIntents directly. You could instead create Invoices (which does involve line items) and then the Invoice will create a PaymentIntent when it is finalized.
You would need to create new Invoices though if there are updates
Ok I'll take a look into that, while I've got you I have another quick question.
I know you pass a return_url, is there a way instead of calling a javascript function when a payment is successfully completed?
Well yeah you can run a function when your return_url is hit
Sorry I don't quite understand that question
No worries,
So I want to stay on the same page (not call a new url) once the payment succeeds as I have further functions I need to perform after payment.
So I guess I need to listen for a success message from stripe?
Ah okay so when you call confirmPayment you want to set redirect: 'if_required': https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-redirect
Then you won't have a redirect for paymnet method types that don't require one
And you wait for the confirmPayment promise to resolve successfully then you run your next logic
Ahh brill, think you've solved it. So a redirect based payment method would normally be bank account yeah?
Yep it would be a bank redirect
Where they have to get redirected to their bank for authentication
As well as certain wallet payment methods
Like WeChat
If you want to support that
Yeah I get it. So to minimise the chance of a redirect primarily stick to apple/google/card?
Bank debits should be fine as well