收到错误:尝试将测试事件发送到Webhook端点时,测试Webhook错误:400 [英] Getting error: Test webhook error: 400 when trying to send a test event to a webhook endpoint
问题描述
我正在尝试按照
I am attempting to send a test webhook as instructed in this tutorial.
但是当我这样做时,我会在第一个链接以及下面看到错误:
But when I go to do it I get the error seen in the first link, and below:
测试webhook错误:400
Test webhook error: 400
这是我的index.ts代码&我已部署到Firebase函数的函数.
Here is my index.ts code & functions I have deployed to firebase functions.
import * as functions from 'firebase-functions';
// 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); // Validate the request
return admin.database().ref('/events').push(event) // Add the event to the database
.then((snapshot: { ref: { toString: () => any; }; }) => {
// Return a successful response to acknowledge the event was processed successfully
return response.json({ received: true, ref: snapshot.ref.toString() });
})
.catch((err: any) => {
console.error(err) // Catch any errors saving to the database
return response.status(500).end();
});
}
catch (err) {
return response.status(400).end(); // Signing signature failure, return an error 400
}
});
exports.exampleDatabaseTrigger = functions.database.ref('/events/{eventId}').onCreate((snapshot, context) => {
return console.log({
eventId: context.params.eventId,
data: snapshot.val()
});
});
如何解决此问题并成功运行测试?
我目前的想法是问题可能与以下情况有关:
My current thinking is that the problem may have something to do with:
我如何写这行代码: snapshot:{ref:{toString:()=>任何;};
根据我的测试,情况似乎并非如此.
From my testing, this does not appear to be the case.
推荐答案
我不认为'test webhook'可以正确地对其进行签名;您应该为此使用条纹CLI .
I don't believe that the 'test webhook' properly signs them; you should use Stripe CLI for this instead.
这篇关于收到错误:尝试将测试事件发送到Webhook端点时,测试Webhook错误:400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!