#Taylor

1 messages · Page 1 of 1 (latest)

hardy patioBOT
eager hearth
#

Are you listening to the events locally or through the endpoint set on Dashboard?

brittle burrow
#

Im trying both locally and resending the webhook through the dashboard in prod and getting the same errors

#

This is the only key im using in my express server, should I be using the publishable key somewhere also?

eager hearth
#

Ah! I see where the problem is. In stripe.webhooks.constructEvent(..) function, the third parameter is Webhook secret, not API secret key

brittle burrow
#

i never even realized those were two different keys will try it out quickly

eager hearth
#

If you use local listener, it should show Webhook secret in your console

#

Webhook secret is in the format of whsec_xxx

brittle burrow
#

Oh yeah I see it at the top when I start the listener

#

Hmm Im still getting the same signature errors. The signing secret in the dashboard and locally are different but Ive tried both but still getting the same errors

#

also just inputing them directly just to be sure instead of using .env variables

#

i did also restart the local test listener

eager hearth
#

Can you disable the one on Dashboard first and only use local listener with the webhook secret of local listener?

brittle burrow
#

Dashboard endpoint has been disabled, restarted everything

#

just trying to give all context

eager hearth
#

In your latest code, I don't see express.raw({type: 'application/json'} being added

#

You should be able to retrieve the request body directly

brittle burrow
#

will switch that back again one sec

eager hearth
brittle burrow
#

Now getting this error again im pulling my hair out lol

#

code is exactly the same unless im blind

eager hearth
#

Can you log req.body and share the value with this code?

brittle burrow
eager hearth
#

What is the default request parser in you Node app?

brittle burrow
#

is what youre referring to the api.use(express.json()) at the top of my file?

eager hearth
#

Ah yes! This is the problem!

#

It will go to express json parser first, then raw parse again

#

You should ensure that your webhook endpoint doesn't go through express json parser

brittle burrow
#

So fairly new to this stuff, so If I remove that will I have to add it as middleware in my other endpoints

eager hearth
#

For example,

app.use((req, res, next) => {
  if (endpoint === '/subscription') {
    express.raw({type: 'application/json',})(req, res, next);
  } else {
    express.json()(req, res, next);
  }
});
brittle burrow
#

I thought adding the express.raw would sort of override/undo that

eager hearth
#

Nope! It won't override

brittle burrow
#

in my /subscription endpoitn

eager hearth
#

It will parse again on top of the default parser

#

Above code is just a pseudo example. Your code should modify accordingly

brittle burrow
#

My god it worked

#

thank you so much lol

#

Helped with both issues I was having

#

the wrong key + middleware

eager hearth
#

Yay! Great to hear that everything is working now!

brittle burrow
#

Appreciate it, had spent like 6 hours on and off working on it before i asked in here

eager hearth
#

No problem! Happy to help 😄