Hello, I'm having some issues with the final part of the (very comprehensive) tutorial regarding webhooks.
elabdesunil opened this issue · comments
Hello, I'm having some issues with the final part of the (very comprehensive) tutorial regarding webhooks.
I can successfully click the 'Subscribe' button on my website - this redirects me to Stripe and I fill out the checkout page with the dummy card details. I then get redirected to localhost:8000/success. I can see that the order has gone through successfully on Stripe as I can see the new customer in my Stripe Dashboard. Further, I do get what appears to be a successful trace on Stripe CLI:
2021-02-13 17:45:44 --> charge.succeeded [evt_1IKSBfEXbllwxHYyPpTdrmTw]
2021-02-13 17:45:44 --> payment_method.attached [evt_1IKSBfEXbllwxHYy4v0LWTiS]
2021-02-13 17:45:44 --> customer.created [evt_1IKSBfEXbllwxHYyTIyC9CFQ]
2021-02-13 17:45:44 --> invoice.created [evt_1IKSBgEXbllwxHYyvVIw9QP1]
2021-02-13 17:45:44 --> checkout.session.completed [evt_1IKSBfEXbllwxHYy2UF9xEJL]
2021-02-13 17:45:44 --> customer.subscription.created [evt_1IKSBgEXbllwxHYyCXsH7bq7]
2021-02-13 17:45:44 --> invoice.updated [evt_1IKSBgEXbllwxHYyklknXtBn]
2021-02-13 17:45:44 --> invoice.finalized [evt_1IKSBgEXbllwxHYyJn6e8Wd6]
2021-02-13 17:45:44 --> invoice.updated [evt_1IKSBgEXbllwxHYyTHAt7vaa]
2021-02-13 17:45:44 --> customer.subscription.updated [evt_1IKSBgEXbllwxHYy047BvrHK]
2021-02-13 17:45:44 --> invoice.payment_succeeded [evt_1IKSBgEXbllwxHYylv9YsxDs]
2021-02-13 17:45:44 --> invoice.updated [evt_1IKSBgEXbllwxHYyEC6xIeF9]
2021-02-13 17:45:45 --> payment_intent.succeeded [evt_1IKSBgEXbllwxHYyrA3WfJZc]
2021-02-13 17:45:45 --> invoice.paid [evt_1IKSBgEXbllwxHYyYAxl8YRy]
2021-02-13 17:45:45 --> payment_intent.created [evt_1IKSBgEXbllwxHYyL5tlzsqp]
After some time (perhaps 20 seconds or so) Stripe CLI then presents me with:
2021-02-13 18:46:24 [ERROR] Failed to POST: Post http://locahost:8000/app/webhook/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
...
My webserver console looks like this after submitting the order on the Stripe website:
app | [13/Feb/2021 18:19:02] "GET /app/create-checkout-session/ HTTP/1.1" 200 83
app | [13/Feb/2021 18:19:26] "GET /app/success?session_id=cs_test_a1wL6vrOUwLNkkE3WuKTpUUomIb5ZuaE7qZTZpsSKXH9KvFJhpcSGxIhcu HTTP/1.1" 301 0
app | [13/Feb/2021 18:19:26] "GET /app/success/?session_id=cs_test_a1wL6vrOUwLNkkE3WuKTpUUomIb5ZuaE7qZTZpsSKXH9KvFJhpcSGxIhcu HTTP/1.1" 200 974
I took the liberty of visiting /app/webhook and saw the following error:
KeyError at /app/webhook/
'HTTP_STRIPE_SIGNATURE'
Request Method: | GET
http://localhost:8000/app/webhook/
3.1.5
KeyError
'HTTP_STRIPE_SIGNATURE'
/src/app/views.py, line 94, in stripe_webhook
/usr/local/bin/python3
3.9.1
['/src', '/usr/local/lib/python39.zip', '/usr/local/lib/python3.9', '/usr/local/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/site-packages', '/src']
Sun, 14 Feb 2021 10:30:04 +0000
I'm not sure if this URL is supposed to be anything but error if you're not in the middle of a subscription transaction (I suspect not) but I thought it might be useful information to help debug.
The result of this is that the Stripe order isn't linked to the signed in user - the model StripeCustomer
remains blank and doesn't populate with the new subscription details . Do you know why this final link between Stripe and my DB model isn't working?
From what I can tell, I have all the necessary code from your repo incorporated into my website.
Thank you for putting this guide together, it's been an excellent learning guide so far!
Originally posted by @simon-tarr in #3