Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Setting browser cookies after triggering a stripe webhook handler

I’ve no backend experience background and I wanted to know if it’s possible to set the browser cookies of the customer after he/she fulfills a payment procedure and stripe triggers the checkout session completed event. I’m using NextJs framework and I implemented an API webhook endpoint to listen to that event for some other tasks. Would really appreciate your help.

I’ve used the Stripe-cli to simulate a checkout being made and installed the cookies npm module to set browser cookies in the backend but that’s totally not the way to go since I’m only just testing the webhook endpoint via the stripe commands(trigger, listen).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Not really, since a webhook has nothing to do with the customer and their browser. A webhook is a HTTP request sent by Stripe’s server to yours to let up update your backend systems. So if you were to respond back to it with Set-Cookie headers or so on, you’re just attempting to set cookies on Stripe’s server HTTP client(which won’t do anything).

If you want to set cookies on the customer, you might do that for example when they visit the success_url page on your server, which you provided to the CheckoutSession. Note that anyone can visit that URL so you shouldn’t set some access/ship a product based only on that. What you might do is set a cookie identifying the customer, and then when they try to access your product or whatever it is they’ve paid for, you can check your database to see if you’ve updated it from the Stripe webhook to indicate they’ve paid.

https://stripe.com/docs/payments/checkout/custom-success-page
https://stripe.com/docs/payments/checkout/fulfill-orders

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading