Update routes/subscription.py
Browse files- routes/subscription.py +5 -5
routes/subscription.py
CHANGED
@@ -64,22 +64,22 @@ def verify_token(user_token: str) -> str:
|
|
64 |
async def stripe_webhook(request: Request):
|
65 |
try:
|
66 |
payload = await request.json()
|
67 |
-
|
68 |
event_type = payload.get("type")
|
|
|
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 |
-
# Recuperar metadata do
|
74 |
-
metadata = invoice.get("
|
75 |
stylist_id = metadata.get("stylist_id", "N/A") # ID do estilista
|
76 |
user_id = metadata.get("user_id", "N/A") # ID do usuário
|
77 |
|
78 |
-
# Cálculo da divisão
|
79 |
stylist_amount = int(amount_paid * 0.8) # 80% para o estilista
|
80 |
platform_amount = int(amount_paid * 0.2) # 20% para a plataforma
|
81 |
|
82 |
-
# Logando os valores
|
83 |
logger.info(f"✅ Pagamento bem-sucedido! Valor total: R$ {amount_paid / 100:.2f}")
|
84 |
logger.info(f"👤 Stylist ID: {stylist_id}")
|
85 |
logger.info(f"👥 User ID: {user_id}")
|
|
|
64 |
async def stripe_webhook(request: Request):
|
65 |
try:
|
66 |
payload = await request.json()
|
|
|
67 |
event_type = payload.get("type")
|
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 |
+
# 🔹 Recuperar metadata corretamente do nível do invoice
|
74 |
+
metadata = invoice.get("metadata", {})
|
75 |
stylist_id = metadata.get("stylist_id", "N/A") # ID do estilista
|
76 |
user_id = metadata.get("user_id", "N/A") # ID do usuário
|
77 |
|
78 |
+
# 🔹 Cálculo da divisão
|
79 |
stylist_amount = int(amount_paid * 0.8) # 80% para o estilista
|
80 |
platform_amount = int(amount_paid * 0.2) # 20% para a plataforma
|
81 |
|
82 |
+
# 🔹 Logando os valores
|
83 |
logger.info(f"✅ Pagamento bem-sucedido! Valor total: R$ {amount_paid / 100:.2f}")
|
84 |
logger.info(f"👤 Stylist ID: {stylist_id}")
|
85 |
logger.info(f"👥 User ID: {user_id}")
|