#mrbond_webhooks

1 messages ¡ Page 1 of 1 (latest)

solar currentBOT
#

👋 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.

broken rover
#

That error suggests you're not providing the right body/payload

lucid walrus
#

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

broken rover
#

Yes, you should log req.body to inspect it, it sounds like it is not containing what you expect

lucid walrus
#

what i need to check in req.body

#

req.body i found in json

broken rover
#

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.

solar currentBOT
lucid walrus
#

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'
},

GitHub

Node.js library for the Stripe API. . Contribute to stripe/stripe-node development by creating an account on GitHub.

broken rover
#

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

#
// 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);
    }
  }
);