1 year ago
#308198
user17151862
Ngrok error with stripe webhook: 400 bad request
So I have setup a stripe webhook with ngrok but for some reason when the webhook is triggered it shows this error in ngrok, but in stripe dashboard it shows that the webhook was successfull, but it doesn't do the stuff that it's supposed to do when it's successfull.
I have been trying to fix this problem for a week now but found no error in my code, ngrok or stripe so I am asking for help here.
here is my code for the webhook.
app.post('/webhook', express.raw({type: 'application/json'}), async (req, res) => {
const sig = req.headers['stripe-signature']
let event
try {
event = stripe.webhooks.constructEvent(req.body, sig, stripeWebhookSecret)
} catch (err) {
res.status(400).send(`Webhook Error: ${err.message}`)
return
}
switch (event.type) {
case 'checkout.session.completed':
console.log('success')
break
default:
console.log(`Unhandled event type ${event.type}`)
}
res.send()
})
here is how I expose my local server host to internet with ngrok
here is how I setup the webhook with stripe
javascript
stripe-payments
ngrok
0 Answers
Your Answer