#mrbond_webhooks
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1265303698838651032
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hey there, please take a look here first: https://docs.stripe.com/webhooks/signature
That error suggests you're not providing the right body/payload
router.post('/service-webhook', express.raw({ type: 'application/json' }), controller.stripewebhookData);
exports.stripewebhookData = async (req, res) => {
const endpointSecret = 'secretid';
let event;
console.log(req.headers,"???????????????????")
const sig = req.headers['stripe-signature'];
try {
event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
}
catch (err) {
console.log("err",err)
return response.serverHttpResponse({
response: res,
message: err.message,
});
//response.status(400).send(Webhook Error: ${err.message});
}} this is my code please help me on this
Yes, you should log req.body to inspect it, it sounds like it is not containing what you expect
This shoul be a raw string, not parsed json
I see you have express.raw({ type: 'application/json' }) in the route handler, but is something in your router parsing json earlier? This is a common issue.
this is my on app.js app.use(express.json({ limit: "100mb" }));
app.use(express.urlencoded({ limit: "100mb", extended: true }));
and this is my route router.post('/service-webhook', controller.stripewebhookData); exports.stripewebhookData = async (req, res) => {
const endpointSecret = 'secretid';
let event;
const requestBody = JSON.stringify(req.body);
console.log(req.headers,"???????????????????")
const signature = req.headers['stripe-signature'];
try {
// const requestBody=req.body;
event = stripe.webhooks.constructEvent(requestBody, signature, endpointSecret);
}
catch (err) {
console.log("err",err)
return response.serverHttpResponse({
response: res,
message: err.message,
});
}
now the error found is raw: {
message: 'No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? \n' +
' If a webhook request is being forwarded by a third-party tool, ensure that the exact request body, including JSON formatting and new line style, is preserved.\n' +
'\n' +
'Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing\n'
},
yea that app.use(express.json({ limit: "100mb" })); is likely the issue
its going to parse json body on all requests
you need to exclude your webhook endpoint from that
We have an example that should how you can do this: https://github.com/stripe/stripe-node/blob/master/examples/webhook-signing/express/main.ts#L17-L29
// Use JSON parser for all non-webhook routes
app.use(
(
req: express.Request,
res: express.Response,
next: express.NextFunction
): void => {
if (req.originalUrl === '/webhook') {
next();
} else {
express.json()(req, res, next);
}
}
);