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).

>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.

Leave a ReplyCancel reply