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")
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user