【发布时间】:2020-07-07 11:52:36
【问题描述】:
错误:
"message": "没有找到与负载的预期签名匹配的签名。您是否传递了从 Stripe 收到的原始请求正文?https://github.com/stripe/stripe-node#webhook-signing",
我试过req.rawBody,但结果相同。我还尝试了堆栈溢出和 github 上可用的所有解决方案。
server.js
// use express body parser
app.use(bodyParse.json());
stripe.js
router
.route('/payment/hook')
.post(bodyParser.raw({
type: 'application/json'
}), paymentsController.transactionHook);
paymentsController.js
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 });
}
}
响应
【问题讨论】:
标签: javascript node.js express ecmascript-6 stripe-payments