#josephmalam - webhooks
1 messages · Page 1 of 1 (latest)
This basic hook is missing a lot of stuff
Try starting here: https://stripe.com/docs/webhooks/quickstart
Right, but I should at least receive the successful response each time,?
I did try that more complete example too, but I've simplified it to try and at least get a consistent pass response (it failed with the same errors with the complete example)
And you are looking at the events you listed above?
I'm looking at payment_intent.succeeded, which has given a fail response in the Dashboard all but once. I'm also looking at other events which are not listed, which fail almost always (not not always)
Okay have you tried adding logging steps right near the top of your funciton to examine the event object you have
You should configure the code to also return a response even when it fails that provides some information. That way you can review the response in your Stripe logs
When it gives the errors Failed to connect to remote host, and Timed out connecting to remote host, I'm not getting any logs at all. On the few instances it succeeds (around 1 in 20), it does give an expected output, e.g. Unhandled event type customer.subscription.created
Right, I'm saying you should return a response instead of just the console.log statement. You can use stripe listen and stripe trigger to simulate events and debug on your local machine. using the Stripe CLI
https://stripe.com/docs/cli
That way you can test different events, place more logging statements in your code, and find the edge cases you are missing
As a follow up, I know you wanted to simplify the code for testing but I would recommend not taking action on webhooks until you verify they are from Stripe (either use our recommended signature verification approach or make API requests using the object ID returned in the event data).
Could you please explain how I can return a response? I added a log to examine the event object, but I've not had any logs as no events have succeeded. I'm now wondering if the issue is instead related to my server set up — I found a page that suggests it may be because Stripe IPs are not whitelisted on my server, but I have no idea how to do that. Does that sound like it may be a possibility?
@thin yoke Snufkin had to head out, but give me a few minutes and I can help
Okay let's back up here for a minute - how are you running your server that accepts webhook events?
Hi @prime crown, I'm using Caddy on Ubuntu 18.04
Sure, but specifically your webhook endpoint. How is it accessed? Are you able to connect to it publicly?
Ie, can you send some test data to it successfully:
curl --request POST \
--url https://example.com/stripe/webhooks \
--header 'Content-Type: application/json' \
--data '{ "id": "evt_123", "object": "event", "type": "event.test" }'
Sorry, I'm not so familiar with this, do you mean express.Router();?
I'll try that
Yep, that works:
{"received":true}
OK and if you use the stripe CLI to trigger events, what happens with that delivery request?
ie, make sure you endpoint is set to receive customer.created events then run:
stripe trigger customer.created
Thank you, I'm just installing the CLI now
The following formula cannot be installed from bottle and must be
built from source.
stripe
😦 don't suppose you know how I can do this? I'll check online now
You can also just use a curl request to create a tst customer: https://stripe.com/docs/api/customers/create?lang=curl
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
curl https://api.stripe.com/v1/customers \
-u sk_test_123123: \
-d description="My First Test Customer (created for API docs)"
That gives the same error on the webhooks dashboard unfortunately:
Timed out connecting to remote host
And what about any logs on your side?
Can you share the event ID you're looking at?
No logs came through for that, I just tried again
The event ID:
evt_1KnpPvLmG1DihkghsmzEvdei
I just did this 3 more times, 1 succeeded and 2 failed. Strange!
Successful event ID: evt_1KnpXSLmG1Dihkgh2XuNvu54
Interesting!So, we are able to reach the endpoint. Intermittent issues point to a couple of different things:
1/ Make sure your network/host is allowing ingress from all of Stripe's webhook delivery server IPs: https://stripe.com/docs/ips#webhook-notifications
2/ Make sure your host is able to connect quickly (within 10s) to that connection request
3/ Intermittent failures after that are typically transient network issues, and for that we support retrying the delivery: https://stripe.com/docs/webhooks/best-practices#events-and-retries
I just added the IPs to iptables, e.g.
iptables -I INPUT -p tcp -s 3.18.12.63 -j ACCEPT
but it still fails unfortunately. For suggestion 2, do you have any ideas on how I can achieve that?
If your server is intermittently unavailable (eg, serverless server sometimes "sleep" and need to wake up) then this might prevent a connection in time. Unfortunately we can't really say much beyond that we cannot connect.
I have a VPS with Hostinger, that's not serverless, right?
I don't know anything about that unfortunately, i just meant as an example. It possible there is a slow network involved or some other issue with routing. I'd suggest you reach out to your hosting provider to support to see if they have logs of these connection attempts.
You can use the techniques we discussed to trigger webhook delivery attempts while they are diagnosing in order to produce logs in their system.
The host provider may need to allow Stripe's delivery IP address, too, FYI
they may be getting blocked before reaching your server
Okay, I will ask them about that. Thank you for your help and suggestions, I appreciate it
No problem - good luck with it!
This thread has been archived. If you need help with anything else please ask in #dev-help or contact Stripe Support: https://support.stripe.com/contact
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.