Stripe Webhook のエラー率が約 90% で、応答が予測できません。サーバーの問題でしょうか?

Stripe Webhook のエラー率が約 90% で、応答が予測できません。サーバーの問題でしょうか?

初めて Stripe Webhook を設定しています。何百ものテスト リクエストを実行しましたが、エラー率は約 90% でした。失敗の原因は予測できません。

Stripe ダッシュボードの失敗応答は次のいずれかです。

Timed out connecting to remote host

または

Failed to connect to remote host

私のウェブフック(テスト用に簡略化しました)。およそ 10% の確率で、次のような 200 応答が返されます{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});
})

フックを定義する次の 2 つの方法と、非同期の有無を試しました。

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

私は Stripe サポートに連絡し、彼らの提案をすべて試しました。彼らは私に次の可能性を残しました:

ネットワークが遅いか、ルーティングに何らかの問題がある可能性があります。

ホストプロバイダーはStripeの配信IPアドレスも許可する必要があるかもしれません。参考までに、サーバーに到達する前にブロックされている可能性があります。

Stripe の IP を iptables に追加しました。例:

iptables -I INPUT -p tcp -s 3.18.12.63 -j ACCEPT

私は Ubuntu 18.04 で Caddy を使用して Hostinger VPS サーバーを実行しています。これはサーバーの設定に問題があるのでしょうか? アドバイスをいただければ幸いです。

答え1

動作しているようです。

ngrokをapt経由でインストールしました(https://ngrok.com/download

次に、youtube.com/watch?v=S1uExj7mMgM&ab_channel=Twilio にアクセスし、ngrok を設定して localhost:4000 に転送します。

ngrok http 4000

大量のリクエストを送信したところ、すべて成功しました。これがどのように機能するのか、なぜ必要なのかはよくわかりませんが、機能していてとても満足しています。これがないと機能しなかった理由を説明できる方がいらっしゃいましたら、ぜひ教えてください。

関連情報