[英]Stripe Webhook error 400 with netlify functions
I have set up payments with stripe using Netlify function by following this article https:\/\/www.netlify.com\/blog\/2020\/04\/22\/automate-order-fulfillment-w\/stripe-webhooks-netlify-functions\/<\/a> and in my Stripe dashboard I get error saying that: Webhook Error: No signatures found matching the expected signature for payload.<\/strong><\/em>我按照这篇文章
https:\/\/www.netlify.com\/blog\/2020\/04\/22\/automate-order-fulfillment-w\/stripe-webhooks-netlify-functions\/<\/a>并在我的 Stripe 仪表板我收到错误消息: Webhook 错误:未找到与有效负载的预期签名匹配的签名。<\/strong><\/em> Are you passing the raw request body you received from Stripe?<\/strong><\/em>
您是否传递了从 Stripe 收到的原始请求正文?<\/strong><\/em>
https:\/\/github.com\/stripe\/stripe-node#webhook-signing<\/a><\/strong><\/em>
https:\/\/github.com\/stripe\/stripe-node#webhook-signing<\/a><\/strong><\/em>
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
exports.handler = async ({ body, headers }) => {
try {
const stripeEvent = stripe.webhooks.constructEvent(
body,
headers["stripe-signature"],
process.env.STRIPE_WEBHOOK_SECRET
);
if (stripeEvent.type === "charge.succeeded") {
const emailTo = stripeEvent.data.object.billing_details.email;
const msg = {
to: emailTo,
from: process.env.FROM_EMAIL_ADDRESS,
subject: `Thanks!`,
html: `elox`,
};
await sgMail.send(msg);
}
return {
statusCode: 200,
body: JSON.stringify({ received: true }),
};
} catch (err) {
console.log(`Stripe webhook failed with ${err}`);
return {
statusCode: 400,
body: `Webhook Error: ${err.message}`,
};
}
};
I got the same issue.我遇到了同样的问题。 Locally with the stripes-cli everything works find.
在本地使用 stripes-cli 可以找到所有工作。 It seams that the lambda didn't handover the raw body to the
stripes.webhook.constructEvent.
似乎 lambda 没有将原始主体移交给
stripes.webhook.constructEvent.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.