![](/img/trans.png)
[英]Stripe Webhook testing throwing … Test webhook error: 500
[英]configuring stripe webhook, Test webhook error: Unable to connect
所以我正在尝试实现一个条纹 webhook 来监听各种事件。 基本上我的 php 应用程序正在实时运行,比如在“http://example.com”上。 我已经安装了条带 CLI 并拥有所有类。 我已经在条纹仪表板上创建了一个 webhook。 但是当我测试一个 webhook 时,它给了我这个错误:
“测试 webhook 错误:无法连接。连接到远程主机超时”
我在 PhpStorm 上进行编码,从那里保存文件,它们会反映在我的网站“abc.com”上。 这是我的 php 文件代码
require_once 'abc.com/httpdocs/includes/classes/stripe-sdk/vendor/stripe/stripe-php/configuration.php';
require_once 'abc.com/httpdocs/includes/classes/stripe-sdk/vendor/stripe/stripe-php/init.php';
$endpoint_secret = 'whsec_...';
$payload = file_get_contents('php://input');
$event = null;
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
echo '⚠️ Webhook error while validating signature.';
http_response_code(400);
exit();
}
// Handle the event
switch ($event->type) {
case 'account.updated':
$paymentIntent = $event->data->object;
break;
default:
// Unexpected event type
error_log('Received unknown event type');
}
http_response_code(200);
我认为我不必在本地主机上运行 php 服务器。 我需要“条纹听……”吗? 希望得到答案:提前谢谢。)如果您需要任何其他信息,请告诉我。
看起来任何试图连接到您的 webhook 端点 URL 的东西都无法到达所述端点。 你能澄清以下...
如果您正在测试本地代码:确保您的本地 PHP 服务器已启动并正在运行,并记下它正在运行的端口。 然后,运行stripe listen --forward-to http://localhost:<PHP server's port>
。 从那里您可以从新的 CLI window 触发示例事件,如下所示: stripe trigger invoice.payment_succeeded
invoice.payment_succeeded。 看看这里的文档。
如果您要设置实时端点:我首先建议使用 Postman 之类的东西来验证您确实可以访问部署 webhook 代码的服务器。 然后,我会仔细检查仪表板中该 webhook 端点 URL 的条目。
如果您可以查明卡在哪里,我可以提供更详细的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.