Stripe webhooks 的错误率为 92%,响应不可预测

发布于 2025-01-20 18:29:25 字数 1379 浏览 2 评论 0原文

我是第一次设置 Stripe webhooks。我已经发出了数十次测试请求,错误率为 92%。失败发生的原因是不可预测的。

仪表板上的失败响应是:

Timed out connecting to remote host

Failed to connect to remote host

我的 webhook(我已将其简化以进行测试)。 8% 的情况下,我会收到带有 {received: true} 的 200 响应:

expressRouter.route('/hooks').post( async (req, res) => {

  const event = req.body;

  console.log("Event:");
  console.log(event);

  // Handle the event
  switch (event.type) {
    case 'payment_intent.succeeded':
      const paymentIntent = event.data.object;
      // Then define and call a method to handle the successful payment intent.
      // handlePaymentIntentSucceeded(paymentIntent);
      break;
    case 'payment_method.attached':
      const paymentMethod = event.data.object;
      // Then define and call a method to handle the successful attachment of a PaymentMethod.
      // handlePaymentMethodAttached(paymentMethod);
      break;
    // ... handle other event types
    default:
      console.log(`Unhandled event type ${event.type}`);
  }

  // Return a response to acknowledge receipt of the event
  res.json({received: true});
})

我已将 Stripe 的 IP 添加到 iptables。我在 Ubuntu 18.04 上使用 Caddy 运行我的服务器。非常感谢任何建议。

I'm setting up Stripe webhooks for the first time. I've made dozens of test requests and I've had an error rate of 92%. It's unpredictable as to why the failures occur.

The failure responses on the dashboard are either:

Timed out connecting to remote host

or

Failed to connect to remote host

My webhook (I've simplified it for testing). 8% of the time, I get a 200 response with {received: true}:

expressRouter.route('/hooks').post( async (req, res) => {

  const event = req.body;

  console.log("Event:");
  console.log(event);

  // Handle the event
  switch (event.type) {
    case 'payment_intent.succeeded':
      const paymentIntent = event.data.object;
      // Then define and call a method to handle the successful payment intent.
      // handlePaymentIntentSucceeded(paymentIntent);
      break;
    case 'payment_method.attached':
      const paymentMethod = event.data.object;
      // Then define and call a method to handle the successful attachment of a PaymentMethod.
      // handlePaymentMethodAttached(paymentMethod);
      break;
    // ... handle other event types
    default:
      console.log(`Unhandled event type ${event.type}`);
  }

  // Return a response to acknowledge receipt of the event
  res.json({received: true});
})

I have added Stripe's IPs to iptables. I'm running my server with Caddy on Ubuntu 18.04. Any advice is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文