Stripe webhook test error 302
Asked Answered
B

3

5

I am trying to test a stripe webhook for subscription trial ending. When I go to send the test even to my webhook receiving route I get error 302. I am using a middleware called stripe-webhook-middleware. My route looks like this:

app.post('/stripe/events',
    stripeWebhook.middleware,
    stripeEvents
  );

I know that route goes against what they docs say but I did get it directly from the package creator. So it should work, then I have the stripe-events.js from the package. I am just adding in a console.log to the route to find the correct data I need.

I tried different webhooks and all give the same error, it has to be in how I have it set up. I hope anyways.

Edit **

I have also done a new route that is just a basic post route with a console.log and still getting the 302 error. What could possible causes be? I can't post a github because of a credential I accidentally leaked.

Bertine answered 29/10, 2017 at 19:35 Comment(3)
A 302 is a redirect, where is your endpoint redirecting? that may help to troubleshoot this? Worst case try using curl to make a request to your endpoint curl -IvL http://localhost:4000/stripe/eventsSitwell
@Sitwell Check my answer I posted. It explains what was happening. I was not on localhost but on a cloud dev environment.Bertine
Awesome, glad you solved this!Sitwell
B
10

I am/was using cloud9.io as my development environment and had my test site as private. That was causing stripe to need to login in order to do anything. I made it public and now it works. I had completely forgotten I had to login to see the site because I always was logged in to cloud 9 when I accessed the site. If you are getting a 302 error, make sure you don't need to log in to get to that route.

Bertine answered 29/10, 2017 at 21:13 Comment(0)
C
1

Just in case anyone sees this 302 error with Codeigniter 3, my webhook route was pointing to a Subscription controller that always exits the constructor if a user isn't logged in and authorised - so I moved the method to my Home controller (used for registration, login etc) thus:

$route['webhook']['post'] = 'home/webhook';

and the 302 error went away. I hope this helps a tired CI dev down the road.

Constructive answered 30/8, 2020 at 18:23 Comment(0)
L
0

Just in case someone receives this error with dJango, my webhook route was pointing to a language redirection. You can investigate it with curl -IvL http://localhost:8000/webhooks/stripe as @duck suggested above.

Here was my output:

HTTP/1.1 302 Found
...
* Issue another request to this URL: 'http://localhost:8000/en/webhooks/stripe/'
...

You can see the redirected URL in the output.

So, when I let Stripe CLI listen to that URL, it works:

stripe listen --forward-to localhost:8000/en/webhooks/stripe/
Lacunar answered 16/12, 2021 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.