使用 Stripe webhook 时出现连接被拒绝错误

Connection refused error when using Stripe webhooks

我在尝试接收 webhook 时经常遇到连接被拒绝的错误。

(venv) alexa@main:/etc/nginx/sites-available$ stripe listen --forward-to localhost:5000/webhook/
go package net: built with netgo build tag; using Go's DNS resolver
> Ready! Your webhook signing secret is whsec_************************* (^C to quit)
2021-04-05 18:13:03   --> customer.subscription.updated [evt_1Icwv5HrsuAsSZROjKy4Z5CK]
2021-04-05 18:13:03            [ERROR] Failed to POST: Post "http://localhost:5000/webhook/": dial tcp 127.0.0.1:5000: connect: connection refused)

端口已通过我的防火墙启用:

To                         Action      From
--                         ------      ----
5000                       ALLOW       Anywhere
5000/tcp                   ALLOW       Anywhere
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
5555                       ALLOW       Anywhere
5000 (v6)                  ALLOW       Anywhere (v6)
5000/tcp (v6)              ALLOW       Anywhere (v6)
22/tcp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)
5555 (v6)                  ALLOW       Anywhere (v6)

我的网络应用程序 运行 Ubuntu 20.10

按照 Justin Michael 在评论中的建议 运行 curl -v -X POST http://localhost:5000/webhook/ 之后,我得到了以下信息:

*   Trying 127.0.0.1:5000...
* TCP_NODELAY set
* connect to 127.0.0.1 port 5000 failed: Connection refused
* Failed to connect to localhost port 5000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 5000: Connection refused

根据您的最新评论,听起来您的本地计算机上安装了 Stripe CLI 运行,并且您正在尝试使用它来将 Stripe 事件转发到您的 Linode 上的代码 运行。

Stripe CLI 专为本地测试而设计,虽然从本地计算机转发到 Linode 可能可行,但不推荐这样做。

此处最好的方法是 set up an actual webhook endpoint in your Stripe Dashboard or create one using the Stripe API 并将其指向您的 Linode。

或者,您可以在 Linode 本身上安装 Stripe CLI 并在那里本地转发,但实际的 webhook 端点将是更好的测试方式,因为您将获得实际的 webhook 端点行为,例如 retries