Last active
April 14, 2020 15:44
-
-
Save xaphod/715863b1b9a6304adcf8119e83497314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const { stripe, webhookSecret } = require('./index'); | |
const router = express(); | |
router.post('/stripe/webhook', bodyParser.raw({ type: 'application/json' }), async (req, res, next) => { | |
const sig = req.headers['stripe-signature']; | |
let event; | |
try { | |
event = stripe.webhooks.constructEvent(req.rawBody, sig, webhookSecret); // fails if changed to req.body | |
} catch (err) { | |
console.error('stripe webhook error during construct event:'); | |
console.error(err); | |
return res.status(400).send(`Webhook Error: ${err.message}`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment