-
I'm using dj-stripe webhook-handlers to perform different operations on webhooks (e.g. sending mail to customer when subscription is updated).
The event-data contains e.g. all subscription-data event-specific data. But all event-data is a simple dict. How do i get the dj-stripe object from/inside the event handler? Can the dict be converted into a djstripe-object?
Is this how it is supposed to work? (Seems strange to perform another api-call for data that is already present in the web-handler) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Why sync the data from the stripe api if the webhook just received the latest data Heres my suggestion: from django.db import transaction
from djstripe import webhooks
from djstripe.models import Subscription
def do_something(subscription_id):
subscription = Subscription.objects.get(stripe_id=subscription_id)
# Do something with the subscription
@webhooks.handler("checkout.session.completed")
def checkout_session_completed(event, **kwargs):
session_data: Dict[str, Any] = event.data["object"]
subscription_id: Optional[str] = session_data["subscription"]
if subscription_id:
transaction.on_commit(do_something, subscription_id) (I did not test teh above code if it works) |
Beta Was this translation helpful? Give feedback.
-
I propose a solution in #2088 |
Beta Was this translation helpful? Give feedback.
Why sync the data from the stripe api if the webhook just received the latest data
Heres my suggestion:
(I did not test teh above code if i…