#krisgardiner - webhook signature verification
1 messages · Page 1 of 1 (latest)
Hello, can you send me the snippet of your code where you are trying to verify the signature?
webhooksRouter.post("/stripe", (req, res) => {
const sig = req.headers["stripe-signature"] as string;
if (!sig) {
return res.sendStatus(400);
}
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(
req.body,
sig,
process.env.STRIPE_WEBHOOK_SECRET || ""
);
} catch (err) {
const error = err as Error;
return res.status(400).send(`Webhook Error: ${error.message}`);
}
Thank you. Looking in to this. Getting the raw body can be tough
Have you double checked that process.env.STRIPE_WEBHOOK_SECRET is being read properly?
yes
And is in the same live/test mode as your events?
yes I believe so
n/m found issue.
bodyParser.json() is not the same as
express.raw({ type: "application/json" })
thanks for your time @tranquil pasture
Ah there we go. Yeah getting the raw body is often the hardest part. Very easy to accidentally use a method that manipulates the json a bit