2

Using Node.js and Stripe. Stripe connects to the endpoint on my localhost but throws the error when it gets to stripe.webhooks.ConstructEvent. I can see req.body and the stripe signature in console.log.

Code:

**require('dotenv').config()
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY)

module.exports = {
    stripe: async(req, res) => {
        console.log('req.body: ', req.body)
        const sig = req.headers["stripe-signature"];
        console.log('req.headers: ', req.headers)
        let event;
        try {
                event = stripe.webhooks.ConstructEvent(
                req.body,
                sig,
                process.env.STRIPE_WEBHOOKS_SECRET
            )
            return res.status(420).send("ok")
        } catch (err) {
            console.error(err)
            return res.status(400).send(err.message)
        }
    }
}**

1 Answer 1

4

Should be stripe.webhooks.constructEvent. See: https://stripe.com/docs/webhooks/quickstart.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.