小编Ste*_*veW的帖子

NextJS Stripe Webhook 原始主体

试图在 NextJS 上传递 Stripe webhook 的原始主体时,我费尽心思!

\n

尝试了很多来自各地的解决方案,但我似乎无法使其发挥作用。

\n

打开具有超能力的开发人员(我仍在获取其中)。

\n

条纹测试错误:

\n
\n

未找到与负载的预期签名匹配的签名。您是否传递了从 Stripe 收到的原始请求正文

\n
\n

我的 NextJS webhook 端点测试:

\n
import { buffer } from 'micro';\nconst stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);\n\nexport default async function handler(req, res) {\n\n    console.log("Payment intent")\n\n    const event = req.body\n\n    console.log(event)\n\n    if (process.env.STRIPE_WEBHOOK_ENDPOINT_SECRET) {\n        // Get the signature sent by Stripe\n        const signature = req.headers['stripe-signature'];\n        console.log(signature)\n        try {\n          event = stripe.webhooks.constructEvent(\n            req.body,\n            signature,\n            process.env.STRIPE_WEBHOOK_ENDPOINT_SECRET\n          );\n        } catch (err) {\n          console.log(`\xe2\x9a\xa0\xef\xb8\x8f  Webhook signature verification failed.`, err.message);\n …
Run Code Online (Sandbox Code Playgroud)

javascript webhooks stripe-payments serverless-framework next.js

11
推荐指数
1
解决办法
4083
查看次数