#raulru

1 messages ยท Page 1 of 1 (latest)

steep krakenBOT
acoustic prism
#

hey there, can you share the code for your webhook handler?

#

it works fine in a indepent project
Can you explain more about this? I don't understand what you mean

#

There are a couple common issues here:
1/ Missing or incorrect webhook signing secret passed it
2/ Mutated request.body somewhere in your network stack, and signature verification requires the exact raw body string we originally sent

rough sentinel
rough sentinel
acoustic prism
#

What changed between those two?

#

Have you verified all your parameters for

stripe.webhooks.constructEvent(
         request.body,
         signature,
         endpointSecret
       );

have values

#

And are you testing with a live/public endpoint, or using the CLI and forwarding?

rough sentinel
rough sentinel
acoustic prism
#

Those snippets aren't the same, in particular the first one you shared does not have this piece from the second one:

app.use((req, res, next) => {
  if (req.originalUrl === "/webhook") {
    next();
  } else {
    express.json()(req, res, next);
  }
});

#

This logic looks to be skipping json parsing for webhook requests, which preserves the raw body

#

Do you have equivalent logc in the new code?

rough sentinel
#

I removed it just to see if get a different result but nope, the same, i added those lines again and still not working

acoustic prism
#

And you provided a new signing secret from the new endpoint being tested?

rough sentinel
#

yes, i dont think the endpoint secret is the issue, i think its something related to the request body

acoustic prism
#

yes, like i said thats the other common issue, because it get mutated somewhere

#

Is there any other express-related config code for this endpoint or is this all of this?

rough sentinel
#

Thats all the express-related code

acoustic prism
#

Actually, this suggests something is happening:

REQUEST BODY: [object Object]

#

body should be a string

#

So something is parsing it to an object

rough sentinel
#

yeah, i think thats the issue, i keep commenting lines to see if something is altering the request but i still getting an [object Object]

acoustic prism
#

What about the express.urlencoded middleware?

#

I don't see anything else that looks a likely culprit

rough sentinel
#

still the same error ๐Ÿฅฒ

golden locust
#

๐Ÿ‘‹ hopping in here since synthrider had to head out

golden locust
#

One key difference I see is that you seem to be using bodyParser in your new webhook handlr - that's likely causing issues here

rough sentinel
#

I already commented all those lines but still no success