I'm setting up a stripe webhook to fulfill my order with stripe after a payment while hosting it with firebase functions.
Webhook Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
Code of my function firebase :
const functions = require('firebase-functions');
const stripe = require('stripe')('***********');
const cors = require('cors')({origin: true});
const webhookSecret = "*********";
exports.stripeWebhook = functions.region('europe-west1').https.onRequest((req, res) => {
cors(req, res, () => {
let event;
const sig = req.headers['stripe-signature'];
const rawBody = Buffer.from(req.rawBody).toString('utf8');
try {
event = stripe.webhooks.constructEvent(rawBody, sig, webhookSecret);
} catch (err) {
res.status(400).send(`Webhook Error: ${err.message}`);
return;
}
// Handle the event
if (event.type === 'customer.subscription.created') {
const subscription = event.data.object;
// Handle the new subscription
} else if (event.type === 'customer.subscription.deleted') {
const subscription = event.data.object;
// Handle the subscription cancellation
} else {
res.status(400).end();
return;
}
// Return a response to Stripe to acknowledge receipt of the event
res.json({received: true});
});
});
Anyone has an idea on how to make it work ? Thanks