Skip to content

Commit

Permalink
Addressed feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
paulasjes-stripe committed Apr 25, 2019
1 parent 62aad3c commit 5c1494a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions examples/webhook-signing/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ const bodyParser = require('body-parser');
const webhookSecret = process.env.WEBHOOK_SECRET;
const app = express();

app.use(bodyParser.raw({type: '*/*'}));

app.post('/webhooks', (req, res) => {
// Stripe requires the raw body to construct the event
app.post('/webhooks', bodyParser.raw({type: 'application/json'}), (req, res) => {
const sig = req.headers['stripe-signature'];

try {
const event = stripe.webhooks.constructEvent(req.body, sig, webhookSecret);

// Do something with event
let event;

try {
event = stripe.webhooks.constructEvent(req.body, sig, webhookSecret);
} catch (err) {
// On error, return the error message
return res.status(400).send(`Webhook Error: ${err.message}`);
}

// Do something with event
console.log('Success:', event.id);

// Return a response to acknowledge receipt of the event
res.json({received: true});
});
Expand Down

0 comments on commit 5c1494a

Please sign in to comment.