[英]Node.js: Stripe error No signatures found matching the expected signature for payload
Error:错误:
"message": "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 ", "message": "没有找到与负载的预期签名匹配的签名。您是否正在传递从 Stripe 收到的原始请求正文? https://github.com/stripe/stripe-node#webhook-signing ",
I've tried req.rawBody
, but the same result.我试过req.rawBody
,但结果相同。 I ve also tried all the solutions available on stack overflow and github.我还尝试了堆栈溢出和 github 上可用的所有解决方案。
// use express body parser
app.use(bodyParse.json());
router
.route('/payment/hook')
.post(bodyParser.raw({
type: 'application/json'
}), paymentsController.transactionHook);
transactionHook: async(req, res, next) => {
const sig = req.headers['stripe-signature'];
let event;
try {
event = await stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
} catch (err) {
return res.status(400).json({ message: err.message, detail: err.detail });
}
}
Using bodyParser.json()
will modify the body such that the signatures are not verifiable.使用bodyParser.json()
将修改正文,使签名无法验证。 You need to ensure this middleware is not being applied for your webhook /hook
endpoint.您需要确保此中间件未应用于您的 webhook /hook
端点。
One way to do this with Express is to simply define the webhook endpoint before you apply the middleware (in the sequence of building your routes).使用 Express 执行此操作的一种方法是在应用中间件之前(按照构建路由的顺序)简单地定义 webhook 端点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.