0

I'm trying to set up a Stripe webhook in Sails, checking the webhook signature as described here. The signature is being returned in the same format as the Stripe example, but every test webhook returns:

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

To try and get the raw request body I've attempted to bypass the bodyParser middleware for this route in sails.config.http, as described here, but if I do that then this.req.body is:

undefined

As an aside, I can see there is some integration with Stripe in Sails, but I can't find a pre-built webhook. If i'm re-inventing the wheel, please let me know, there is very little documentation on integrating Stripe with Sails.

matt9292
  • 401
  • 2
  • 7
  • 19

1 Answers1

0

The answer was here: https://stackoverflow.com/a/68236261/6569847

Update the commented out bodyParser under config/http.js to:

bodyParser: function(req, res, next) {
  var skipper = require('skipper')();
  var rawParser = require("body-parser").raw({type: "*/*"});

  // Create and return the middleware function
  sails.log.debug(req.headers);
  if (req.headers && req.headers['stripe-signature']) {
    sails.log.info('request using raw parser middleware');
    return rawParser(req, res, next);
  }
  // Otherwise use Skipper to parse the body
  sails.log.info('request using skipper middleware');
  return skipper(req, res, next);  
},
matt9292
  • 401
  • 2
  • 7
  • 19