Update routes/subscription.py
Browse files- routes/subscription.py +14 -15
routes/subscription.py
CHANGED
@@ -68,23 +68,22 @@ async def stripe_webhook(request: Request):
|
|
68 |
|
69 |
if event_type == "invoice.payment_succeeded":
|
70 |
invoice = payload.get("data", {}).get("object", {})
|
71 |
-
amount_paid = invoice.get("amount_paid", 0) # Valor total pago (em centavos)
|
72 |
|
73 |
-
# 🔹
|
74 |
metadata = invoice.get("metadata", {})
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
logger.info(f"
|
88 |
|
89 |
return {"status": "success"}
|
90 |
|
|
|
68 |
|
69 |
if event_type == "invoice.payment_succeeded":
|
70 |
invoice = payload.get("data", {}).get("object", {})
|
|
|
71 |
|
72 |
+
# 🔹 Verifica metadata na invoice principal
|
73 |
metadata = invoice.get("metadata", {})
|
74 |
+
|
75 |
+
# 🔹 Verifica metadata na assinatura associada
|
76 |
+
subscription_metadata = invoice.get("subscription_details", {}).get("metadata", {})
|
77 |
+
|
78 |
+
# 🔹 Verifica metadata dentro dos itens da fatura (invoice.line_items)
|
79 |
+
line_items = invoice.get("lines", {}).get("data", [])
|
80 |
+
line_item_metadata = line_items[0].get("metadata", {}) if line_items else {}
|
81 |
+
|
82 |
+
# 🔹 Agora pegamos os valores
|
83 |
+
stylist_id = metadata.get("stylist_id") or subscription_metadata.get("stylist_id") or line_item_metadata.get("stylist_id")
|
84 |
+
user_id = metadata.get("user_id") or subscription_metadata.get("user_id") or line_item_metadata.get("user_id")
|
85 |
+
|
86 |
+
logger.info(f"✅ Invoice processada! Stylist ID: {stylist_id}, User ID: {user_id}")
|
87 |
|
88 |
return {"status": "success"}
|
89 |
|