Reputation: 4418
I've been trying to listen to Stripe webhooks with firebase functions. here is my code:
exports.stripeEvents = functions.https.onRequest((request, response) =>
{
try
{
const stripesignature = request.headers['stripe-signature'] as string;
let stripeevent:Stripe.Event;
try
{
stripeevent = stripe.webhooks.constructEvent(request.rawBody, stripesignature, config.stripewebhooksecretkey);
}
catch (error)
{
sentry.captureException(error);
response.status(400).end();
return;
}
response.sendStatus(200);
}
catch(error)
{
sentry.captureException(error);
throw error;
}
});
and I keep getting this error:
No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing
I have tried changing request.rawBody
to request.rawBody.toString()
but of no avail. The same firebase function works perfectly when I do a test webhook run from the stripe website.
What could I be missing?
Stripe official documentation on how to do it: https://stripe.com/docs/webhooks/signatures
Upvotes: 0
Views: 1114
Reputation: 1497
This may not be an immediate solution, but here are a few suggestions to try:
const stripesignature
to a variable produces different behaviourSee if you can narrow it down to which input is causing the issue (e.g. request.rawBody, or stripesignature).
On the other hand, although an incorrect webhook secret would be expected to produce a different error, there may be little harm checking it is propagating correctly from config and matching the one in the configured endpoint setting in the dashboard.
Upvotes: 0