Update routes/subscription.py
Browse files- routes/subscription.py +24 -1
routes/subscription.py
CHANGED
@@ -71,6 +71,7 @@ async def stripe_webhook(request: Request):
|
|
71 |
|
72 |
# 🔹 Capturando valores da fatura
|
73 |
amount_paid = invoice.get("amount_paid", 0) # Valor total pago (em centavos)
|
|
|
74 |
|
75 |
# 🔹 Buscando metadados
|
76 |
metadata = invoice.get("metadata", {})
|
@@ -95,6 +96,27 @@ async def stripe_webhook(request: Request):
|
|
95 |
logger.info(f"💰 Estilista recebe: R$ {stylist_amount / 100:.2f}")
|
96 |
logger.info(f"🏛️ Plataforma fica com: R$ {platform_amount / 100:.2f}")
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
return {
|
99 |
"status": "success",
|
100 |
"total_paid": amount_paid / 100,
|
@@ -103,7 +125,8 @@ async def stripe_webhook(request: Request):
|
|
103 |
"user_id": user_id,
|
104 |
"user_stripe_id": user_stripe_id,
|
105 |
"stylist_amount": stylist_amount / 100,
|
106 |
-
"platform_amount": platform_amount / 100
|
|
|
107 |
}
|
108 |
|
109 |
except Exception as e:
|
|
|
71 |
|
72 |
# 🔹 Capturando valores da fatura
|
73 |
amount_paid = invoice.get("amount_paid", 0) # Valor total pago (em centavos)
|
74 |
+
currency = invoice.get("currency", "usd") # Moeda do pagamento (ajuste se necessário)
|
75 |
|
76 |
# 🔹 Buscando metadados
|
77 |
metadata = invoice.get("metadata", {})
|
|
|
96 |
logger.info(f"💰 Estilista recebe: R$ {stylist_amount / 100:.2f}")
|
97 |
logger.info(f"🏛️ Plataforma fica com: R$ {platform_amount / 100:.2f}")
|
98 |
|
99 |
+
# 🔹 Transferindo 80% para o estilista via Stripe Connect
|
100 |
+
try:
|
101 |
+
transfer = stripe.Transfer.create(
|
102 |
+
amount=stylist_amount, # Valor em centavos
|
103 |
+
currency=currency,
|
104 |
+
destination=stylist_stripe_id, # Conta do estilista no Stripe Connect
|
105 |
+
description=f"Pagamento para Stylist ID: {stylist_id}",
|
106 |
+
metadata={
|
107 |
+
"stylist_id": stylist_id,
|
108 |
+
"user_id": user_id,
|
109 |
+
"total_paid": amount_paid / 100,
|
110 |
+
"stylist_amount": stylist_amount / 100,
|
111 |
+
"platform_amount": platform_amount / 100
|
112 |
+
}
|
113 |
+
)
|
114 |
+
|
115 |
+
logger.info(f"✅ Transferência realizada! ID da Transferência: {transfer.id}")
|
116 |
+
except Exception as e:
|
117 |
+
logger.error(f"❌ Erro na transferência: {str(e)}")
|
118 |
+
return {"status": "error", "message": "Erro ao transferir pagamento ao estilista"}
|
119 |
+
|
120 |
return {
|
121 |
"status": "success",
|
122 |
"total_paid": amount_paid / 100,
|
|
|
125 |
"user_id": user_id,
|
126 |
"user_stripe_id": user_stripe_id,
|
127 |
"stylist_amount": stylist_amount / 100,
|
128 |
+
"platform_amount": platform_amount / 100,
|
129 |
+
"transfer_id": transfer.id # Retorna o ID da transferência
|
130 |
}
|
131 |
|
132 |
except Exception as e:
|