#rbole
1 messages · Page 1 of 1 (latest)
sharing the code is difficult, but on index.js I do:
app.use((req, res, next) => {
if (req.originalUrl === '/api/rt/swhabo') {
console.log(req.originalUrl)
express.raw();
console.log(req.rawBody)
next();
} else {
express.json({limit: '3mb'});
express.urlencoded({ extended: true });
next();
}
})
I have to switch between JSON and the raw body
/api/rt/swhabo' is this your webhook endpoint URL?
you have a very good example here https://github.com/stripe/stripe-node/blob/master/examples/webhook-signing/express/main.ts
ok, thanks I know that typescript example.
your code needs to be the same as the one I shared
e.g.
next();
} else {
express.json()(req, res, next);
}```
app.use((req, res, next) => {
if (req.originalUrl === '/api/rt/swhabo') {
next();
} else {
express.json({limit: '3mb'});
express.urlencoded({ extended: true });
next();
}
})
I think that is the same
and on the endpoint I do:
router.route('/swhabo', express.raw({type: 'application/json'})).post(function(req, res){
console.log('RawBody',req.body)
process.exit(0);
});
how are you testing your webhook endpoint?
router.route('/swhabo') isn't that route /api/swhabo?
I change the customer name in the stripe platform and a request is send on my endpoint
it's the customer.updated event
Maybe it's because I use the express router object !
the express router isn't the problem
router.route('/swhabo') isn't that route /api/swhabo?
can you please confirm?
the correct endpoint is /api/rt/swhabo. I use the express router to split the endpoints to different folder and files. That's why the route /swhabo is correct. I receive the request on that endpoint in the JSON format as well, only the raw body is in this case undefined.
I express 4.17
req.body is undefined?
yes
what's your account ID?
acct_1JIrRcKxrILBeGDx
ok let's try something
could you please try to download this app https://stripe.com/docs/webhooks/quickstart
and see whether this code also is getting you an empty req.body?
ok, I think that is no stripe problem, the problem is me, the app.use function seems the problem. let's close this thread.
I can see that https://dashboard.stripe.com/test/events/evt_1NM7sYKxrILBeGDxIA7zdqwq was successfully processed by your webhook endpoint
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
yes that is working, but without signing.
now I would like to add the signing,
event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret)
ok
it's better to build this incrementally
with the docs I'm providing
Error: Webhook Error: No webhook payload was provided.
are you still using your own application, or did you use the application I asked you to download from https://stripe.com/docs/webhooks/quickstart
I have to use my own one.
the problem is, that expressjs does not give my the raw body with express.raw()
it gives we undefined
let's first make sure it works without any other logic