#bkrnetic

1 messages · Page 1 of 1 (latest)

willow basalt
maiden relic
#

Hmm, I've followed these steps and I got no luck fixing the issue.

willow basalt
#

can you clarify the exact error message you're getting?

also, when you add some logging, what are the values you're passing to constructEvent, are any of them null?
can you share the evt_xxx ID evt_xxx of the event where you're getting the error?

your value wh_2425tsg seems wrong to me also, that looks like the ID of a webhook. What you want is the 'signing secret', which looks like whsec_xxxx

maiden relic
#

Ok, I will do it, sec

maiden relic
#

You were right, I had the webhook ID instead of secret. I've changed it and this is the same error I'm getting:

"message": "//github.com/stripe/stripe-node#webhook-signing"

This is the data of the request:

Header: t=1662389366,v1=63b3e2444dfd5ea79d0c68b6dca9539ec3a8a54b3b74204c70558b37eca877ea,v0=b2f45d7786bf0dcdb4728e4a07081620e3cddcb7bc7d9be9349d7d43270b0d32

Webhook secret: whsec_jS0Fg9kJfIXwLPwlcIkdQo3hRlkXWkRj

#

If you expand my file you can see the request body data (it's an event object)

willow basalt
#

automatic_tax: [Object],

#

that means it's being parsed into an object already and is not the raw JSON

#

so you need to use an approach like the one in the example repo I posted to use things like bodyParser's raw mode to get the raw POST body from the request and not the parsed version

maiden relic
#

Okey, thanks a lot. I will look into them

willow basalt
#

feel free to share your exact full code for the endpoint too if that would help

maiden relic
#

I might, but let me first try to fix the issue, I need to try few things now

#

thanks!

willow basalt
#

yep that looks correct

maiden relic
#

Instead of the approach of many, I've used JSON.stringify(request.body) method which is much cleaner.

Still I'm getting the same error.

#

This is the part of code that handle event creation

#

This is the header:
t=1662391012,v1=25a4f0f6b569aacb3b2b5477ead59584fd55cf05ae04f6a46e78327a1075de5b,v0=d3d36b1a407b2d79fa2575cda63715a0b5f6eecc7f02fb5087b0ffaf2d3ae286

#

This is whsec: whsec_jS0Fg9kJfIXwLPwlcIkdQo3hRlkXWkRj

willow basalt
#

JSON.stringify(request.body) method which is much cleaner
that won't work though

#

since it it will e.g. change the order of the keys on the JSON and change the whitespace. Stringifying the raw JSON we post will not give you the same JSON, so the signature computed is not the same since it's not computed against the same thing

#

the only option is to get the exact raw HTTP POST body from the incoming request, that's the only option that will work

maiden relic
#

ok, thx! I'm working through the exmaples you've provided before.

maiden relic
#

Finally done it. Thanks a lot..

willow basalt
#

great! so it's working now?

maiden relic
#

Yes it does. I've replaced app.use(bodyParses.json(); with conditionally parser:

app.use(bodyParser.json({
        // Because Stripe needs the raw body, we compute it but only when hitting the Stripe webhook URL.
        verify: (req: Request, res, buf) => {
            const url = req.originalUrl;
            if (url.startsWith('/webhooks/payment')) {
                req["rawBody"] = buf.toString()
            }
        }}));

and then I accessed it like this:

//@ts-ignore
request.rawBody, //This is manually set in app.ts
willow basalt
#

awesome, thanks for following up!