#krutarth
1 messages · Page 1 of 1 (latest)
hi! not sure what you mean by "the context API" exactly
useContext hook
I have stored data using context which i can access using useContext hook
similar to redux, used to manage the state values
let me think about it but I don't think useContext will help here really since it's a redirect to a brand new page
generally you'd use cookies to persist some information on the browser to access after the redirect, or you can pass things like ?my_value=foo in the return_url and access it later
Hi! I'm taking over my colleague. Please, give me a moment to catch up.
What kind of data would you like to persist? Depending on this it might make more sense to go with some other solution, e.g. store the data in the PaymentIntent metadata.
It is simple array of object
I mean, what does this data mean? Is it related to the payment, or UI, or something else?
You can set redirect: 'if_required' on your confirm call: https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-redirect
the data is not related to payment, lets say some UI
This way only the payments that require redirection to another page will use the return_url, other payments like card will keep you on the page, so you can continue with your JS/React logic. When you do get redirected, your local state will be lost, so if you want to persist some information it's best to use localStorage.
Okay, so here when I use redirection, is there any way I can know that payment has been successful? So basically if the payment is successful i need to call a dispatch action otherwise not
By "dispatch action" you mean like Redux?
yes
When you get redirected you will get the payment_intent_client_secret query parameter by which you will be able to retrieve the PI status: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#web-submit-payment:~:text=get(
'-,payment_intent_client_secret,-'
)%3B
However, you should not rely on this for business logic (e.g. fulfilling the orders), and use webhooks instead: https://stripe.com/docs/webhooks
However, some payments take longer to process, e.g. bank transfers, so you will not get the immediate success/error. That's why it's best to use webhooks to get real-time status.
Please, let me know if you have any other questions.
Thanks, For now, I'm good. thanks.