#RGRTHAT

1 messages · Page 1 of 1 (latest)

ashen vergeBOT
shrewd vessel
#

hello, running into a webhook signature verification issue with Node?

lost jasper
#

yes

#

im trying to do like so ```js
stripe listen --events=payment_intent.succeeded

#

I got my endpoint secret by doing ```js
stripe listen

#

route: ```js
router.post(
"/webhooks",
express.raw({ type: "application/json" }),
payment.webhook
);

#

This is where the error must come from I suppose```js
const signature = req.headers["stripe-signature"];

      event = stripe.webhooks.constructEvent(
        req.body,
        signature,
        endpointSecret
      );
#

@shrewd vessel isnt that the right secret to pass to "constructEvent"?

shrewd vessel
#

this is a common issue with express frameworks

#

that you can try

#

but basically, you pass the full raw request body to your /webhooks endpoint

#

I think you're doing that in your code, not fully sure, I'm not a node expert

lost jasper
#

I THINK I KNOW!

#

its this ```js
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

#

middleware

#

u have to send raw

shrewd vessel
lost jasper
#

I use this middleware for ALL requests except this one request that requires raw

#

how am I suppose to solve this problem

shrewd vessel
#

the link I sent you

#

shows how to do that

lost jasper
#

oh yes

#

that should work

#

let me try

shrewd vessel
#

you're allowlisting /webhooks for raw requests only

#

and everything else uses express.json() for example

lost jasper
#

@shrewd vessel This works!

shrewd vessel
#

great!

lost jasper
#

What server u use?

#

framework

shrewd vessel
#

who, me?

lost jasper
#

yes

#

I thought node was very popular

#

haha

shrewd vessel
#

node is super popular

for the Stripe integrations I have built in the past, I've used node, ruby as the two main ones