From 3c24f18b01e6eca8ca9817f1859d3dd90789b5ed Mon Sep 17 00:00:00 2001 From: suro Date: Fri, 27 Mar 2026 21:44:29 +0100 Subject: [PATCH] Fix: Handle null customer_email in stripe session --- AzA march 2026/stripe_routes.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/AzA march 2026/stripe_routes.py b/AzA march 2026/stripe_routes.py index 1c3c90f..da1e89e 100644 --- a/AzA march 2026/stripe_routes.py +++ b/AzA march 2026/stripe_routes.py @@ -336,13 +336,17 @@ async def stripe_webhook( customer_id = obj.get("customer") client_reference_id = obj.get("client_reference_id") - # Email can be in customer_details.email or customer_email - customer_email = None - cd = obj.get("customer_details") or {} - if isinstance(cd, dict): - customer_email = cd.get("email") or None - if not customer_email: - customer_email = obj.get("customer_email") or None + customer_email = ( + obj.get("customer_email") + or (obj.get("customer_details") or {}).get("email") + ) + if not customer_email and customer_id: + try: + cust = stripe.Customer.retrieve(customer_id).to_dict_recursive() + customer_email = cust.get("email") + except Exception: + pass + customer_email = (customer_email or "").strip() or None if subscription_id and customer_id: sub = stripe.Subscription.retrieve(subscription_id, expand=["items.data.price"]).to_dict_recursive() @@ -367,6 +371,11 @@ async def stripe_webhook( except Exception: return None + if lookup_key and not allowed_users: + policy = _policy_for_lookup_key(lookup_key) + allowed_users = allowed_users or str(policy.allowed_users) + devices_per_user = devices_per_user or str(policy.devices_per_user) + _upsert_license( subscription_id=subscription_id, customer_id=customer_id,