#Taylor
1 messages · Page 1 of 1 (latest)
Are you listening to the events locally or through the endpoint set on Dashboard?
Im trying both locally and resending the webhook through the dashboard in prod and getting the same errors
This is the only key im using in my express server, should I be using the publishable key somewhere also?
Ah! I see where the problem is. In stripe.webhooks.constructEvent(..) function, the third parameter is Webhook secret, not API secret key
i never even realized those were two different keys will try it out quickly
You can get the Webhook secret by going to https://dashboard.stripe.com/test/webhooks > Choose webhook endpoint > Under Signing secret and click Reveal
If you use local listener, it should show Webhook secret in your console
Webhook secret is in the format of whsec_xxx
Oh yeah I see it at the top when I start the listener
Hmm Im still getting the same signature errors. The signing secret in the dashboard and locally are different but Ive tried both but still getting the same errors
also just inputing them directly just to be sure instead of using .env variables
i did also restart the local test listener
Can you disable the one on Dashboard first and only use local listener with the webhook secret of local listener?
Dashboard endpoint has been disabled, restarted everything
just trying to give all context
In your latest code, I don't see express.raw({type: 'application/json'} being added
You should be able to retrieve the request body directly
will switch that back again one sec
You can find the example here: https://stripe.com/docs/webhooks#verify-official-libraries
Now getting this error again im pulling my hair out lol
code is exactly the same unless im blind
Can you log req.body and share the value with this code?
What is the default request parser in you Node app?
is what youre referring to the api.use(express.json()) at the top of my file?
Ah yes! This is the problem!
It will go to express json parser first, then raw parse again
You should ensure that your webhook endpoint doesn't go through express json parser
So fairly new to this stuff, so If I remove that will I have to add it as middleware in my other endpoints
For example,
app.use((req, res, next) => {
if (endpoint === '/subscription') {
express.raw({type: 'application/json',})(req, res, next);
} else {
express.json()(req, res, next);
}
});
I thought adding the express.raw would sort of override/undo that
Nope! It won't override
in my /subscription endpoitn
It will parse again on top of the default parser
Above code is just a pseudo example. Your code should modify accordingly
My god it worked
thank you so much lol
Helped with both issues I was having
the wrong key + middleware
Yay! Great to hear that everything is working now!
Appreciate it, had spent like 6 hours on and off working on it before i asked in here
No problem! Happy to help 😄