Home > Net >  Stripe webhooks error "No signatures found matching the expected signature for payload"
Stripe webhooks error "No signatures found matching the expected signature for payload"

Time:04-16

Been stuck on this error for a while now and I've followed stripes documentation and express example on github, but still have no success.

I am using express in Firebase functions:

export const app = express();

/* -------------------------------------------------------------------------- */
/*                                 Middleware                                 */
/* -------------------------------------------------------------------------- */
app.use(cors({ origin: true }));
app.use(favicon(__dirname   '/public/favicon.ico'));
app.use(helmet());
app.use(
  (
    req: express.Request,
    res: express.Response,
    next: express.NextFunction
  ): void => {
    functions.logger.log('ORIGINAL URL:', req.originalUrl);
    if (req.originalUrl === '/stripe/webhooks/account/update') {
      functions.logger.log('THIS IS THE WEBHOOK, USING RAW');
      next();
    } else {
      express.json({ strict: false })(req, res, next);
    }
  }
);
// #####################################################################
app.post(
  '/stripe/webhooks/account/update',
  express.raw({ type: 'application/json' }),
  (req: express.Request, res: express.Response): void => {

    functions.logger.log('IN STRIPE ACCOUNT UPDATE WEBHOOK');
    const sig = req.headers['stripe-signature'];
    let event: Stripe.Event;
    try {
      event = stripe.webhooks.constructEvent(
        req.body,
        sig,
        functions.config().stripe.webhooks.account.update.test
      );
    } catch (err) {
      const message = `❌ Webhook Error: ${err.message}`;
      functions.logger.error(message);
      res.status(400).send(message);
      return;
    }

    functions.logger.log('STRIPE WEBHOOK EVENT: ', event);

    // Handle the event
    switch (event.type) {
      case 'account.updated': {
        const account = event.data.object;
        console.log(account);
        // Then define and call a function to handle the event account.updated
        break;
      }
      default:
        functions.logger.error(`           
  • Related