#JDesignV2-webhooks
1 messages · Page 1 of 1 (latest)
have you tried using the example code at https://github.com/stripe/stripe-node/blob/master/examples/webhook-signing/node-express/express.js directly in your server application? I would start with that.
const raw = Buffer.from(JSON.stringify(req.body) is definitely not going to work, since that call to stringify will modify the incoming request body
Yes... I already tried that...
yeah that was one of my last trys to get it to work hahaha
not the best ^^
The weird thing now is when I implement app.use((req, res, next) => { if (req.originalUrl === '/webhook') { next(); } else { express.json()(req, res, next); } }); this for example... my Server doesn't even get to the constructEvent method...
ok, so when you try that, log the value of req.body and then compare it to the raw body on your Stripe dashboard https://dashboard.stripe.com/test/events/evt_1JcW8OKBPpELGMIU63zjXLPM
it has to match exactly including the whitespace(that is part of the raw string we send)
hmmm ok i will try...
also make sure you're actually using the right secret
i.e. log it out and compare it to the whsec_xxx emitted when running stripe listen if that's how you're forwarding the event, or to the secret on the dashboard page for the endpoint you created
Hmmm... to the right is the request.body and on the left the original...
It just 'over-jumps' the req.on() Methods completely...
The weird thing now is that the Server gets stuck in this Method (above)
It does not even 'reach' this part anymore...
ok on the right that is wrong
you can see it has [Object] for example
that means what you are looking at has already been parsed into a JS object by middleware in Express
hmmm... ok i thaught that is only because of the consol.log in the terminal...
well if you log an object it will look that way yes
the problem is you have an object. You should have a string
why do you have this thing with rawBody and chunk ? can you use the code at https://github.com/stripe/stripe-node/blob/master/examples/webhook-signing/node-express/express.js ?
it gets parsed for you before your code can run
ok i'll try it again... one sek.
Express sees that an incoming request is JSON so it helpfully converts it to a JS object, but you want to avoid that happening here
hmmm ok
I tried it now but the output I get seems to be exactly the same as before...
Also with [Object]
This is my implementation now ...
can you share the full code you have?(in text not a screenshot)
can you do express.raw({type: 'application/json'}) like in the example?
yes one sec.
same result... 😦
app.post('/webhook', express.raw({type: 'application/json'}), (req, res) => {...});
Does it maybe has something todo with Google Cloud App Engine?
possibly, but I have no experience with that platform. Seems unlikely
are you 100% sure you're actually running that code, i.e. the file is definitely saved and 'deployed' ? It should just work as far as I can tell
I am only currently trying it out with the Stripe CLI... I am always restarting the node Server with npm start... Is there another way? Like f.ex. a 'hard reload' or smth?
WTF ok wait
no way
I have these lines of code inside my server.js... from one of your tutorials to create a checkout session for a subsrciption... when I comment them out it. works... 🤯
is it the app.use(express.json()) that killed the 'getting the raw body'?
it works now lol ^^
ah yeah
same issue I found a couple of years ago https://github.com/stripe/stripe-node/issues/341#issuecomment-413952457
for some reason that overrides the route config which seems backwards but oh well! glad you got it working!
happy to help!