Fix: Handle null customer_email in stripe session
This commit is contained in:
@@ -336,13 +336,17 @@ async def stripe_webhook(
|
|||||||
customer_id = obj.get("customer")
|
customer_id = obj.get("customer")
|
||||||
client_reference_id = obj.get("client_reference_id")
|
client_reference_id = obj.get("client_reference_id")
|
||||||
|
|
||||||
# Email can be in customer_details.email or customer_email
|
customer_email = (
|
||||||
customer_email = None
|
obj.get("customer_email")
|
||||||
cd = obj.get("customer_details") or {}
|
or (obj.get("customer_details") or {}).get("email")
|
||||||
if isinstance(cd, dict):
|
)
|
||||||
customer_email = cd.get("email") or None
|
if not customer_email and customer_id:
|
||||||
if not customer_email:
|
try:
|
||||||
customer_email = obj.get("customer_email") or None
|
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:
|
if subscription_id and customer_id:
|
||||||
sub = stripe.Subscription.retrieve(subscription_id, expand=["items.data.price"]).to_dict_recursive()
|
sub = stripe.Subscription.retrieve(subscription_id, expand=["items.data.price"]).to_dict_recursive()
|
||||||
@@ -367,6 +371,11 @@ async def stripe_webhook(
|
|||||||
except Exception:
|
except Exception:
|
||||||
return None
|
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(
|
_upsert_license(
|
||||||
subscription_id=subscription_id,
|
subscription_id=subscription_id,
|
||||||
customer_id=customer_id,
|
customer_id=customer_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user