Todd Eagle
Todd Eagle

Reputation: 23

TypeError: stripe.webhooks.ConstructEvent is not a function

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)
        }
    }
}**

Upvotes: 2

Views: 5137

Answers (1)

codename_duchess
codename_duchess

Reputation: 921

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

Upvotes: 4

Related Questions