Reputation: 21
router.post(
"/",
bodyParser.raw({ type: "application/json" }),
async (req, res) => {
// Retrieve the event by verifying the signature using the raw body and secret.
let event;
const signature = req.headers["stripe-signature"]
const endPointSecret = "whsec_***"
console.log(signature)
console.log(req.body)
try {
event = stripe.webhooks.constructEvent(
req.body,
signature,
endPointSecret
);
} catch (err) {
console.log(err);
return res.sendStatus(400);
}
// Extract the object from the event.
const dataObject = event.data.object;
console.log(dataObject)
res.sendStatus(200)
}
);
I am testing Webhook on localhost by listening and forwarding event fromStripe CLI
to localhost. And I am using endpoint secret (from stripe cli provided after "stripe listen" command).Still having signature verification error!!
Upvotes: 1
Views: 968
Reputation: 1459
Make sure you are using the right webhook secret key.
You may have defined that key just for the online webhook endpoint, and not for local usage. Set it up in your local env vars as instance.
Upvotes: 0