stripe-payments - Stripe Webhook - 无法读取未定义的属性“类型”
问题描述
我刚刚在 node.js 中集成了条带 webhook。
我能够实现简单的 webhook 端点,它工作得非常好。
但是,如果我尝试“检查 webhook 签名”,则会收到错误消息:“无法读取未定义的属性‘类型’”
我的代码看起来就像条带提供的一样:
app.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) => {
const sig = request.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret);
// event = request.body;
} catch (err) {
response.status(400).send(`Webhook Error: ${err.message}`);
}
// Handle the event
switch (event.type) {
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
console.log('PaymentIntent was successful!');
break;
default:
console.log(`Unhandled event type ${event.type}`);
// Unexpected event type
return response.status(400).end();
}
// Return a 200 response to acknowledge receipt of the event
response.json({ received: true });
});
我在“事件”中没有得到任何东西
请帮我!!!
解决方案
尝试使用
bodyParser.raw({type: '*/*'})
https://github.com/stripe/stripe-node/issues/331
我的问题是我正在使用 NextJS 和
我正在使用 Stripe 为 Next.js 应用程序的支付网关供电,并开始验证 webhook 签名密钥。起初我遇到了一些问题,因为 Stripe 需要原始请求正文,而 Next.js 在将请求正文传递给处理程序之前对其进行解析。
https://maxkarlsson.dev/blog/2020/12/verify-stripe-webhook-signature-in-next-js-api-routes/
推荐阅读
- flutter - Flutter sharedPreferences 初始化
- laravel - Laravel - LogicException:App\Models\User::token 必须返回一个关系实例,但返回了“null”
- python - 将 find_all() 结果转换为文本,以便可以在 pandas 数据框中使用
- r - 求 95% 分布相加的 x 值 - CDF 的 0.95
- node.js - 代理无法打印从 Dialogflow 中的 Axion 库请求收到的所有结果
- amazon-web-services - SageMaker Lifecycle configuration script - LR CF characters added when trying to copy into AWS on mac
- neural-network - Python Lightning for sine wave simulation
- python - 如何使用来自单独 JSON 文件的数据填充我正在构建的 FastAPI?
- node.js - Socket.io 为客户端创建第二个网络连接
- excel - VBA - 后期绑定与早期绑定错误 - xml 响应的差异