json - Stripe 错误消息 405 -“将 .json 附加到 uri 以使用 rest api”
问题描述
我正在使用 Stripe,并尝试将测试 webhook 发送到我的 URL 和 Firebase 托管的数据库。当我“发送测试 webhook”时,我在 Stripe 控制台中收到以下错误消息:
测试 Webhook 错误:405
“将 .json 附加到您的请求 URI 以使用其余 API”
我的代码是教程的直接副本:https ://github.com/GaryH21/Stripe-Webhooks-Tutorial/blob/master/functions/index.js
这是我的 index.js 的代码:
const functions = require('firebase-functions');
const stripe = require("stripe")(functions.config().keys.webhooks);
const admin = require('firebase-admin')
admin.initializeApp();
const endpointSecret = functions.config().keys.signing;
exports.events = functions.https.onRequest((request, response) => {
let sig = request.headers["stripe-signature"];
try {
let event = stripe.webhooks.constructEvent(request.rawBody, sig, endpointSecret)
return admin.database().ref('/events').push(event)
.then((snapshot) => {
return response.json({ received: true, ref: snapshot.ref.toString() })
})
.catch((err) => {
console.error(err)
return response.status(500).end() // error saving to database
})
} catch (err) {
return response.status(400).end() // signing signature failed
}
})
exports.exampleDataBaseTrigger = functions.database.ref('/events/{eventId}').onCreate((snapshot, context) => {
return console.log({
eventId: context.params.eventid,
data: snapshot.val()
})
})
本教程和我的代码中唯一使用 .json 的时间是:return response.json({ received: true, ref: snapshot.ref.toString() })
我是否应该将 .json 附加到某处的“请求”上,例如在 request.RawBody 中?
签名密钥没有问题,因为这会给出 400 错误消息,我已经处理并修复了该消息。
我很乐意在我的应用程序中分享其他文件的代码,但据我所知,其余的都与问题无关。非常感谢。
解决方案
推荐阅读
- r - flextable 中的问题:函数:save_image
- python - 熊猫:在这里使用 apply() 的正确方法?
- apache-kafka - 如何在 Kafka 中查询 GlobalState Store
- console - mousedown mouseup 点击信息
- mobirise - 如何与他人一起编辑 mobirise 项目?
- apache-hudi - Apache Hudi 中 _hoodie_commit_time 列的时间戳格式是什么?
- java - 在我的在线多人问答游戏中,我怎样才能让玩家同时加入和竞争?
- java - 为 Kruskal 算法实现联合查找算法以在 Java 中查找最小生成树
- javascript - 如何使用普通记数法但不是科学记数法来控制台记录大数字?
- go - GoLand 未运行任何测试