#leak-webhook-questions
1 messages · Page 1 of 1 (latest)
Hello
Basically you just want to handle this in your Webhook handler.
So first thing you do when you receive these Events is you respond with a 200 to let Stripe know you received them.
Then, based on the data in the Event you can check if you already have that customer in your database or whether you need to create a new one.
i am not already sending the a respond with a 200, for example this:
.completed [evt_1O05DXHUc73tzQsMPsczpcpf]
2023-10-11 18:25:04 <-- [200] POST http://localhost:8000/api/payment/webhook-test/ [evt_1O05DXHUc73tzQsMPsczpcpf]
Okay. So what error are you seeing exactly?
error:
File "/Users/lauri/Desktop/company_full/django_rest_api/api/views.py", line 480, in post
subscription = Subscription.objects.get(customer_id=customer_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/lauri/Desktop/company_full/venv/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/lauri/Desktop/company_full/venv/lib/python3.11/site-packages/django/db/models/query.py", line 637, in get
raise self.model.DoesNotExist(
api.models.Subscription.DoesNotExist: Subscription matching query does not exist.
[11/Oct/2023 16:25:02] "POST /api/payment/webhook-test/ HTTP/1.1" 500 132727
Okay that is an issue with your database interaction.
That's not a Stripe-specific issue so it isn't really something I can help with
on which event_type should i create a user in my database
because then i should be getting this error anymore when the user is already created in the database.
what do you mean with the flow
I mean what API requests you make.
Like you could create a Customer object before you redirect to Checkout
If you want
So you could store them in your database at that point potentially
All depends on what you want really
i want to create a customer and store there their customer_id and supscription_id and the price_id
Then I would still recommend doing that upon checkout.session.completed
but why is it calling the customer.subscription.updated before that ?
Because there are updates to the Subscription happening as well, but you should have your code ignore that in these cases.
You look at the Subscription object that is returned in the Event and determine whether it is a renewal of an active Subscription or a new Subscription
The best way to figure that out is to test out both things so you know what the Event will look like
You can use test clocks to test out renewals: https://stripe.com/docs/billing/testing/test-clocks
so i should look at every event_type if the subscription is new or already in the database, and based on that create a new subscrption
do you have some example code only for a finished webhook that updates the database on the events. i am working on the stripe intergration for a 4 days and i am always getting new errors it would help me to get on the right track.