stripe-cli icon indicating copy to clipboard operation
stripe-cli copied to clipboard

500 errors on webhook listen

Open GusBeare opened this issue 3 years ago • 23 comments

Hi

Not sure if this is a bug or something I don't understand.

I've been using the Stripe CLI on windows for testing my booking app. Like this.

stripe listen --forward-to  https://localhost:44383/webhooks/processpayment --skip-verify

After my booking is complete my web hook is fired and works just fine. The code is hit and I can step through in Visual Studio. However, I see some 500 errors in the CLI output in the console e.g.

    2022-04-25 21:23:02   --> product.created [evt_1KsYQzJYbfxqMZXs2DKNOsCp]
    2022-04-25 21:23:02  <--  [500] POST https://localhost:44383/webhooks/processpayment [evt_1KsYQzJYbfxqMZXs2DKNOsCp]
    2022-04-25 21:23:03   --> price.created [evt_1KsYR0JYbfxqMZXscT4aLkt8]
    2022-04-25 21:23:03  <--  [500] POST https://localhost:44383/webhooks/processpayment [evt_1KsYR0JYbfxqMZXscT4aLkt8]
    2022-04-25 21:23:03   --> payment_intent.created [evt_3KsYR0JYbfxqMZXs0iGlWy0w]
    2022-04-25 21:23:03  <--  [500] POST https://localhost:44383/webhooks/processpayment [evt_3KsYR0JYbfxqMZXs0iGlWy0w]
    2022-04-25 21:23:10   --> customer.created [evt_1KsYR7JYbfxqMZXstNP8ZMzj]
    2022-04-25 21:23:10  <--  [500] POST https://localhost:44383/webhooks/processpayment [evt_1KsYR7JYbfxqMZXstNP8ZMzj]
    2022-04-25 21:23:10   --> payment_intent.succeeded [evt_3KsYR0JYbfxqMZXs0b9517EU]
    2022-04-25 21:23:10  <--  [500] POST https://localhost:44383/webhooks/processpayment [evt_3KsYR0JYbfxqMZXs0b9517EU]
    2022-04-25 21:23:10   --> charge.succeeded [evt_3KsYR0JYbfxqMZXs0lkYXhqG]
    2022-04-25 21:23:10  <--  [500] POST https://localhost:44383/webhooks/processpayment [evt_3KsYR0JYbfxqMZXs0lkYXhqG]
    2022-04-25 21:23:10   --> checkout.session.completed [evt_1KsYR8JYbfxqMZXssbWLFCdz]
    2022-04-25 21:23:11  <--  [200] POST https://localhost:44383/webhooks/processpayment [evt_1KsYR8JYbfxqMZXssbWLFCdz]

Can anyone explain why I am seeing the 500 errors?

I don't appear to see these issues when the site is on a server and not using the CLI.

cheers Angus

GusBeare avatar Apr 25 '22 20:04 GusBeare

There is nothing in the logs in my Stripe account to indicate what's causing these 500 errors.

GusBeare avatar Apr 25 '22 21:04 GusBeare

Hi @GusBeare, thanks for getting in touch. Before we look into this on our end, could I confirm whether you experienced these 500 errors only while stepping through the debugger in Visual Studio? If so, there's a chance that a timeout occurs given the webhook route code won't immediately return a 200 as expected if the debugger has halted execution.

If you're seeing them outside of debugging let me know and we can try to reproduce this on our end. Thanks!

suz-stripe avatar Apr 25 '22 21:04 suz-stripe

Hi @suz-stripe

Thanks for responding. These errors occur when there are no breakpoints in my web hook code.

I am using the latest Stripe CLI (1.8.8) with Stripe.Net.

chees Gus

GusBeare avatar Apr 25 '22 21:04 GusBeare

@GusBeare thanks for the extra info, we'll look into this and will reach back out if we find anything.

suz-stripe avatar Apr 25 '22 21:04 suz-stripe

@GusBeare I've been experiencing this while integrating hooks on a Firebase project. The pattern is almost the same for my use case as well, a few 500 and then 200, also at times it does succeed all the way through.

2022-10-31 17:52:53   --> connect invoiceitem.created [evt_1LysKeIGRKWcFa2w0QdPDXNU]
2022-10-31 17:52:53   --> connect invoice.created [evt_1LysKfIGRKWcFa2wcGyNdI2Z]
2022-10-31 17:52:53  <--  [500] POST http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook [evt_1LysKfIGRKWcFa2wcGyNdI2Z]
2022-10-31 17:52:54   --> connect invoiceitem.updated [evt_1LysKfIGRKWcFa2w1AaFU4sE]
2022-10-31 17:52:54   --> connect payment_intent.created [evt_3LysKgIGRKWcFa2w0VdguJpi]
2022-10-31 17:52:54  <--  [500] POST http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook [evt_3LysKgIGRKWcFa2w0VdguJpi]
2022-10-31 17:52:54   --> connect invoice.updated [evt_1LysKgIGRKWcFa2wmrJxI9Mp]
2022-10-31 17:52:54   --> connect invoice.finalized [evt_1LysKgIGRKWcFa2wVhWFsgoJ]
2022-10-31 17:52:54  <--  [500] POST http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook [evt_1LysKgIGRKWcFa2wVhWFsgoJ]
2022-10-31 17:52:57   --> connect payment_intent.succeeded [evt_3LysKgIGRKWcFa2w0sK2Q9z4]
2022-10-31 17:52:57   --> connect charge.succeeded [evt_3LysKgIGRKWcFa2w0xEFDfeu]
2022-10-31 17:52:57   --> application_fee.created [evt_1LysKjIisHAWwPA8i8m18Acs]
2022-10-31 17:52:57  <--  [500] POST http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook [evt_3LysKgIGRKWcFa2w0xEFDfeu]
2022-10-31 17:52:57   --> connect invoice.updated [evt_1LysKjIGRKWcFa2wrUOJTUWk]
2022-10-31 17:52:57   --> connect invoice.paid [evt_1LysKjIGRKWcFa2wFrimidGV]
2022-10-31 17:52:57   --> connect invoice.payment_succeeded [evt_1LysKjIGRKWcFa2w3b2CaGl3]
2022-10-31 17:52:57  <--  [500] POST http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook [evt_1LysKjIGRKWcFa2wFrimidGV]
2022-10-31 17:52:58  <--  [200] POST http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook [evt_1LysKjIGRKWcFa2w3b2CaGl3]

for the most failed requests I also see:

2022-10-31 17:53:23 [ERROR] Failed to POST: Post "http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
2022-10-31 17:53:24 [ERROR] Failed to POST: Post "http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
2022-10-31 17:53:24 [ERROR] Failed to POST: Post "http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
2022-10-31 17:53:27 [ERROR] Failed to POST: Post "http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
2022-10-31 17:53:27 [ERROR] Failed to POST: Post "http://0.0.0.0:5001/app/us-central1/stripeConnectWebhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

On the server side (Firebase emulator) the ones that 500 don't even seem to make it to the web server as it never logs the receipt of the request.

I also tried to hit the endpoints (modified slightly) with httpie to see if the endpoints succeed and they always go through.

cli version 1.13.0 on macOS Ventura

devraj avatar Oct 31 '22 22:10 devraj

Glad to see I'm not alone. I still see those issues but fortunately it's not stopping me from testing my application. Still no idea what the cause/fix might be.

GusBeare avatar Oct 31 '22 23:10 GusBeare

Is it possibly indicating that the web hook is not posting for those events that return a 500? I have my web hook in Stripe set up to post only for checkout.session.completed and this returns a 200.

GusBeare avatar Oct 31 '22 23:10 GusBeare

If it helps, I don't see this on v1.12.4, but I do on v1.13.0.

noelmansour avatar Nov 02 '22 16:11 noelmansour

Update. Latest CLI (1.13.6) gives me the following. They seem to have changed to 400's.

2022-12-14 08:33:06 --> payment_intent.created [evt_3MEqOkJYbfxqMZXs0z5jhw0P] 2022-12-14 08:33:07 <-- [400] POST https://localhost:44383/webhooks/processpayment [evt_3MEqOkJYbfxqMZXs0z5jhw0P] 2022-12-14 08:33:12 --> payment_intent.succeeded [evt_3MEqOkJYbfxqMZXs0lMSI160] 2022-12-14 08:33:12 <-- [400] POST https://localhost:44383/webhooks/processpayment [evt_3MEqOkJYbfxqMZXs0lMSI160] 2022-12-14 08:33:13 --> charge.succeeded [evt_3MEqOkJYbfxqMZXs0Ct3Hgzf] 2022-12-14 08:33:13 <-- [400] POST https://localhost:44383/webhooks/processpayment [evt_3MEqOkJYbfxqMZXs0Ct3Hgzf] 2022-12-14 08:33:13 --> checkout.session.completed [evt_1MEqOqJYbfxqMZXsMhU3V6lI] 2022-12-14 08:33:14 <-- [200] POST https://localhost:44383/webhooks/processpayment [evt_1MEqOqJYbfxqMZXsMhU3V6lI]

GusBeare avatar Dec 14 '22 08:12 GusBeare

More than a year and the problem is still there. I'm getting this kind of response

[500] POST http://localhost:8000/payment/webhook

no matter during the debug session or just when the development server is running. My webhook_view does not run therefore I cannot change the order status to 'paid'. Hey Stripe people! Help us to solve this please.

alexstelmakh avatar Mar 01 '23 12:03 alexstelmakh

latest CLI version 1.13.12 seems to work for me:

>> stripe listen --forward-to  https://localhost:44383/webhooks/processpayment --skip-verify    
> Ready! You are using Stripe API Version [2022-11-15]. Your webhook signing secret is XXX
2023-03-02 08:49:21   --> payment_intent.created [evt_3Mh7pFJYbfxqMZXs0ak8U4HV]
2023-03-02 08:49:22  <--  [400] POST https://localhost:44383/webhooks/processpayment 
2023-03-02 08:49:44   --> payment_intent.succeeded [evt_3Mh7pFJYbfxqMZXs0DPoyI2w]
2023-03-02 08:49:44  <--  [400] POST https://localhost:44383/webhooks/processpayment 
2023-03-02 08:49:44   --> charge.succeeded [evt_3Mh7pFJYbfxqMZXs0tN2Ar3Y]
2023-03-02 08:49:44  <--  [400] POST https://localhost:44383/webhooks/processpayment 
2023-03-02 08:49:44   --> checkout.session.completed [evt_1Mh7pcJYbfxqMZXs7Niv8Za5]
2023-03-02 08:49:45  <--  [200] POST https://localhost:44383/webhooks/processpayment 

GusBeare avatar Mar 02 '23 10:03 GusBeare

Have you tried adding a trailing slash to your endpoint, as in http://localhost:8000/payment/webhook/? That works for Django.

EspritElf avatar Apr 17 '23 19:04 EspritElf

This is exactly what I did, long ago. Thanks for your answer, anyway.

On Mon, Apr 17, 2023, 20:32 EspritElf @.***> wrote:

Have you tried adding a trailing slash to your endpoint, as in http://localhost:8000/payment/webhook/? That works for Django.

— Reply to this email directly, view it on GitHub https://github.com/stripe/stripe-cli/issues/857#issuecomment-1511968718, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJ2XNYAB3KOP73EKXMXTSTXBWLDTANCNFSM5UJX5A5A . You are receiving this because you commented.Message ID: @.***>

alexstelmakh avatar Apr 17 '23 21:04 alexstelmakh

how to solve this error guys ?

2023-09-05 14:32:19 --> payment_intent.requires_action [evt_3Nmv9MSHc4kM5hqz08rx3V6x] 2023-09-05 14:32:19 --> payment_intent.created [evt_3Nmv9MSHc4kM5hqz0LAtUTyR] 2023-09-05 14:32:21 --> checkout.session.completed [evt_1Nmv9QSHc4kM5hqzGxwg0XSH] 2023-09-05 14:32:21 <-- [500] POST http://localhost:1900/webhook [evt_1Nmv9QSHc4kM5hqzGxwg0XSH] 2023-09-05 14:32:22 --> payment_intent.succeeded [evt_3Nmv9MSHc4kM5hqz0tJrjffe] 2023-09-05 14:32:22 --> charge.succeeded [evt_3Nmv9MSHc4kM5hqz0MH0LZOu] 2023-09-05 14:32:49 [ERROR] Failed to POST: Post "http://localhost:1900/webhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

2023-09-05 14:32:49 [ERROR] Failed to POST: Post "http://localhost:1900/webhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

2023-09-05 14:32:52 [ERROR] Failed to POST: Post "http://localhost:1900/webhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

2023-09-05 14:32:52 [ERROR] Failed to POST: Post "http://localhost:1900/webhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

CTKx7 avatar Sep 05 '23 09:09 CTKx7

Glad to see I'm not alone. I'm getting the same error. However, there hasn't been a solution even though the problem has been around for 1 year. I hope it will be fixed soon 😌

gokgokay avatar Sep 22 '23 14:09 gokgokay

It's been awhile since I looked at this, but I believe you have to add trailing slashes in the urls.py file in the stripe app. This is my urls file:

from django.urls import path 

from . import views
from . import webhooks

urlpatterns = [
    path("checkout/<token>/", 
         views.create_checkout_session, 
         name="create-checkout-session"),
    path("success/<token>/", views.payment_success, name="payment-success"),
    path("cancel/<token>/", views.payment_cancel, name="payment-cancel"),
    path("webhooks/stripe/", webhooks.stripe_webhook, name="stripe-webhook"),

]

EspritElf avatar Oct 12 '23 13:10 EspritElf

EspritElf, thank you, there were no problems in my code, my carelessness was the problem, I lost the latest slash when typed a command in the Stripe CLI, right there: stripe listen --forward-to localhost:8000/payment/webhook/ Although it's ironic that it was a slash issue again and you actually pointed me the direction, thank you

mps298 avatar Oct 12 '23 14:10 mps298

Ah yes, that's right, the trailing slash needs to be put in the CLI endpoint as well.

Glad to help. Cheers!

EspritElf avatar Oct 12 '23 14:10 EspritElf

Have you tried adding a trailing slash to your endpoint, as in http://localhost:8000/payment/webhook/? That works for Django.

I wasnt using django. It worked for me with nodejs

sojinsamuel avatar Nov 13 '23 08:11 sojinsamuel

Have you tried adding a trailing slash to your endpoint, as in http://localhost:8000/payment/webhook/? That works for Django.

this fixed for me for nextjs. why the hell does this work? postman works fine without slash, i was losing my mind.

roachadam avatar Nov 19 '23 00:11 roachadam