我是 Firebase Cloud Functions 第二代的新手 我在 Stripe 中创建了一个付款链接,我希望当用户购买该商品并完成时, Stipe Webhooks 会将信息发送到我的云功能,以便我可以将信息更新到 Firestore
我已按照云功能中的说明进行操作,但无法找出问题所在 npm 安装 stripe 完成
我尝试从 stripe 中的付款链接购买商品
来自 stripe webhooks 的错误是 403 ERR 片名:403禁区 错误:您的客户端无权从该服务器获取 URL
/
。
(我的脚步) 条纹
Stipe Webhooks 添加端点 https://stripewebhook-kfxoivwllq-uc.a.run.app 上面是我输入的端点 url url 来自:exports.stripeWebhook = onRequest((req, res)=>{})
配置环境 firebase 函数:秘密:设置 SECRET_NAME
下面是我在functions/index.js文件中的代码
const {logger} = require("firebase-functions");
const {onRequest} = require("firebase-functions/v2/https");
const {initializeApp} = require("firebase-admin/app");
initializeApp();
exports.stripeWebhook = onRequest({secrets: ["SECRET_NAME"]}, async (req, res) => {
const sig = req.headers["stripe-signature"];
const endpointSecret = "whsec_XP7qiexIKzYwp8fHYFx0k9XXXXT";
const stripe = require("stripe")(process.env.SECRET_NAME);
let event;
try {
event = stripe.webhooks.constructEvent(req.rawBody, sig, endpointSecret);
} catch (err) {
res.status(400).send(`Webhook Error: ${err.message}`);
return;
}
// Handle the event
switch (event.type) {
case "checkout.session.async_payment_failed": {
const checkoutSessionAsyncPaymentFailed = event.data.object;
logger.log("payment_failed", checkoutSessionAsyncPaymentFailed);
break;
}
case "checkout.session.completed": {
const checkoutSessionCompleted = event.data.object;
logger.log("completed", checkoutSessionCompleted);
break;
}
// ... handle other event types
default: {
logger.log("Unhandled event type", event.type);
}
}
// Return a 200 response to acknowledge receipt of the event
res.send();
});
来自云函数日志的错误: textPayload:“请求未经身份验证。要么允许未经身份验证的调用,要么设置正确的授权标头。了解更多信息,请访问 https://cloud.google.com/run/docs/securing/authenticating 其他故障排除文档可以在以下位置找到: https://cloud.google.com/run/docs/troubleshooting#unauthorized-client”
Stripe Webhooks 响应错误 stripe webhooks 的错误是 403 ERR 片名:403禁区 错误:您的客户端无权从该服务器获取 URL
/
。
过去几年我使用第一代和functions.config()来让环境一切正常 现在第二代我无法弄清楚。 我的代码有问题吗?
我在 Stripe 中创建了一个付款链接,我希望当用户购买该商品并完成时, Stipe Webhook 会将信息发送到我的云功能,以便我可以将信息更新到 Firestore
我遇到了同样的问题,对我有用的是删除云功能并重新部署它