#$david
1 messages · Page 1 of 1 (latest)
Metadata for the session will be in the session completed webhook. What metadata are you trying to inspect?
checkout.session.completed?
then it must be something wrong in my code
StripeSignatureVerificationError: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
i am getting this
Ok well that's a different issue, you're encountering issues with webhook signature verification
Can you share your webhook endpoint code where you try to verify?
And an example event ID
yes
const stripewebhook = async (req, res) => {
const sig = req.headers['stripe-signature']
console.log(sig)
let event;
try {
event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret)
} catch (err) {
console.log(err)
return res.status(400).send(`Webhook Error: ${err.message}`)
}
switch (event.type) {
case 'checkout.session.completed':
const session = event.data.object
console.log(session)
break
default:
console.log(`Unhandled event type ${event.type}`)
}
res.send(200)
}
2023-02-07 22:24:25 --> payment_intent.succeeded [evt_3MYxiDBUI5OPyd6p17po7g5q]
2023-02-07 22:24:25 <-- [400] POST http://localhost:3500/webhook/v1/stripe [evt_3MYxiDBUI5OPyd6p17po7g5q]
It looks like you're probably using Express. Are hyou sure you're passing in the raw request body, instead of parsed json?
oh
// MIDDLEWARE
connectDB()
app.use(logger)
app.use(credentials)
app.use(parseIp)
app.use(cors(corsOptions))
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use(cookieParser())
// ROUTES
app.use('/register', require('./routes/register'))
app.use('/auth', require('./routes/auth'))
app.use('/logout', require('./routes/logout'))
app.use('/webhook' , require('./routes/webhook'))
app.use(express.json())
Yea, you need to make sure the webhook route is excluded from any json parsing, or that you first preserve the raw request body
got it
Up to you how you want ot achieve that, there are many ways
it's still
not working
do i have to use
express.raw({type: 'application/json'})
app.use('/webhook', express.raw({type: 'application/json'}), require('./routes/webhook'))
works now
sweet
That's another option yes