Node.JS Express Stripe CLI Project to Create Webhooks for Payment Checkout Event in Javascript

You are currently viewing Node.JS Express Stripe CLI Project to Create Webhooks for Payment Checkout Event in Javascript

Node.js Express Stripe CLI Project to Create Webhooks For Payment Checkout Event in Javascript

const stripe = require("stripe")("##secretkey##");
 
const express = require('express')
 
const bodyparser = require('body-parser')
const app = express()
 
 
app.post('/hooks',bodyparser.raw({type:'application/json'}),async(req, res) => {
    const payload = req.body
    const sig = req.headers['stripe-signature']
    const endpointsecret = "##endpointsecret##";
    let event;
 
    try {
 
        event = stripe.webhooks.constructEvent(payload,sig,endpointsecret)
        
    } catch (error) {
        console.log(error.message)
        res.status(400).json({ success: false })
        return;
    }
    console.log(event.type)
    console.log(event.data.object)
    console.log(event.data.object.id)
    res.json({
     success:true
    })
})
 
app.listen(5000, () => {
    console.log("App is listening on port 5000")
})

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply