Connection refused error when using Stripe webhooks

I'm constantly getting a connection refused error when trying to receive webhooks.

(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)

The port is enabled through my firewall:

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)

My webapp is running on Ubuntu 20.10

After running curl -v -X POST http://localhost:5000/webhook/ as suggested by Justin Michael in the comments I got the following :

*   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

Upvotes: 4

Views: 9001

Answers (1)

Justin Michael
Justin Michael

Reputation: 6495

Based on your latest comment it sounds like you have Stripe CLI running on your local machine and you're trying to use it to forward Stripe Events to the code running on your Linode.

Stripe CLI is designed for local testing only, and while forwarding from your local machine to your Linode can probably work, it's not recommended.

The best approach here would be to set up an actual webhook endpoint in your Stripe Dashboard or create one using the Stripe API and point it to your Linode.

Alternatively you could install Stripe CLI on the Linode itself and forward locally there, but the actual webhook endpoint will be a better way to test as you'll get actual webhook endpoint behavior, such as retries.

Upvotes: 2

Related Questions