SyntaxError: Unexpected token o in JSON at position 1
Now i understand it's a problem with parsing the req.body as it arrives in chunks probably. but, I thought that using the Express with body-parser should solve it.
Any help will be appreciated.
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
var stripe = require("stripe")("token");
// You can find your endpoint's secret in your webhook settings
const endpointSecret = 'secret';
// This example uses Express to receive webhooks
const app = require('express')();
// Retrieve the raw body as a buffer and match all content types
app.use(require('body-parser').raw({type: '*/*'}));
app.post('/webhook/example', (req, res) => {
let sig = req.headers["stripe-signature"];
try {
let event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
// Do something with event
}
catch (err) {
res.status(400).end()
}
// Return a response
res.json({received: true});
});
app.listen(8000, () => console.log('Running on port 8000'));
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/fe407fc5-73ad-4f1d-9b37-9ee198e2c97e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.