stripe / stripe-cli

A command-line tool for Stripe
https://stripe.com/docs/stripe-cli
Apache License 2.0
1.57k stars 363 forks source link

500 errors on webhook listen #857

Open GusBeare opened 2 years ago

GusBeare commented 2 years ago

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 commented 2 years ago

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

suz-stripe commented 2 years ago

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!

GusBeare commented 2 years ago

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

suz-stripe commented 2 years ago

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

devraj commented 1 year ago

@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

GusBeare commented 1 year ago

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 commented 1 year ago

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.

noelmansour commented 1 year ago

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

GusBeare commented 1 year ago

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]

alexstelmakh commented 1 year ago

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.

GusBeare commented 1 year ago

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 
EspritElf commented 1 year ago

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

alexstelmakh commented 1 year ago

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: @.***>

CTKx7 commented 10 months ago

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)

gokgokay commented 9 months ago

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 😌

EspritElf commented 9 months ago

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"),

]
mps298 commented 9 months ago

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

EspritElf commented 9 months ago

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

Glad to help. Cheers!

sojinsamuel commented 7 months ago

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

roachadam commented 7 months ago

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.

kerimovok commented 1 week ago

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

That is fixed for Nest.js too, thx!