Update routes/stylist.py
Browse files- routes/stylist.py +47 -1
routes/stylist.py
CHANGED
|
@@ -62,6 +62,48 @@ def get_account_balance(account_id: str) -> Dict[str, Any]:
|
|
| 62 |
logger.error(f"❌ Error getting account balance: {str(e)}")
|
| 63 |
return {"available_balance": 0, "pending_balance": 0, "currency": "BRL"}
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
def get_connected_account_details(account_id: str) -> Dict[str, Any]:
|
| 66 |
try:
|
| 67 |
account = stripe.Account.retrieve(account_id)
|
|
@@ -243,7 +285,7 @@ def get_total_subscribers(user_id: str) -> int:
|
|
| 243 |
subscribers = response.json()
|
| 244 |
return len(subscribers)
|
| 245 |
return 0
|
| 246 |
-
|
| 247 |
@router.post("/bank_account_dashboard_link")
|
| 248 |
async def generate_bank_account_dashboard_link(data: UserIDRequest):
|
| 249 |
try:
|
|
@@ -284,6 +326,9 @@ def get_dashboard(user_token: str = Header(None, alias="User-key"), page: int =
|
|
| 284 |
# Obter detalhes da conta conectada
|
| 285 |
account_details = get_connected_account_details(stripe_id)
|
| 286 |
|
|
|
|
|
|
|
|
|
|
| 287 |
return {
|
| 288 |
"stripe_id": stripe_id,
|
| 289 |
"available_balance": get_account_balance(stripe_id),
|
|
@@ -292,6 +337,7 @@ def get_dashboard(user_token: str = Header(None, alias="User-key"), page: int =
|
|
| 292 |
"total_followers": get_total_followers(user_id),
|
| 293 |
"total_subscribers": get_total_subscribers(user_id),
|
| 294 |
"account_details": account_details,
|
|
|
|
| 295 |
**get_active_subscribers(user_id, page)
|
| 296 |
}
|
| 297 |
except Exception as e:
|
|
|
|
| 62 |
logger.error(f"❌ Error getting account balance: {str(e)}")
|
| 63 |
return {"available_balance": 0, "pending_balance": 0, "currency": "BRL"}
|
| 64 |
|
| 65 |
+
def get_payout_history(account_id: str, limit: int = 10) -> List[Dict[str, Any]]:
|
| 66 |
+
try:
|
| 67 |
+
payouts = stripe.Payout.list(
|
| 68 |
+
stripe_account=account_id,
|
| 69 |
+
limit=limit,
|
| 70 |
+
expand=["data.destination"]
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
payout_history = []
|
| 74 |
+
for payout in payouts.data:
|
| 75 |
+
arrival_date = datetime.fromtimestamp(payout.arrival_date) if payout.arrival_date else None
|
| 76 |
+
|
| 77 |
+
payout_entry = {
|
| 78 |
+
"id": payout.id,
|
| 79 |
+
"amount": payout.amount,
|
| 80 |
+
"currency": payout.currency,
|
| 81 |
+
"status": payout.status,
|
| 82 |
+
"type": payout.type,
|
| 83 |
+
"method": payout.method,
|
| 84 |
+
"created": datetime.fromtimestamp(payout.created).isoformat(),
|
| 85 |
+
"arrival_date": arrival_date.isoformat() if arrival_date else None,
|
| 86 |
+
"description": payout.description,
|
| 87 |
+
"failure_code": payout.failure_code,
|
| 88 |
+
"failure_message": payout.failure_message,
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
# Adicionar detalhes da conta bancária, se disponíveis
|
| 92 |
+
if hasattr(payout, 'destination') and payout.destination:
|
| 93 |
+
bank = payout.destination
|
| 94 |
+
payout_entry["bank_details"] = {
|
| 95 |
+
"bank_name": getattr(bank, 'bank_name', None),
|
| 96 |
+
"last4": getattr(bank, 'last4', None),
|
| 97 |
+
"account_holder_name": getattr(bank, 'account_holder_name', None)
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
payout_history.append(payout_entry)
|
| 101 |
+
|
| 102 |
+
return payout_history
|
| 103 |
+
except Exception as e:
|
| 104 |
+
logger.error(f"❌ Error getting payout history: {str(e)}")
|
| 105 |
+
return []
|
| 106 |
+
|
| 107 |
def get_connected_account_details(account_id: str) -> Dict[str, Any]:
|
| 108 |
try:
|
| 109 |
account = stripe.Account.retrieve(account_id)
|
|
|
|
| 285 |
subscribers = response.json()
|
| 286 |
return len(subscribers)
|
| 287 |
return 0
|
| 288 |
+
|
| 289 |
@router.post("/bank_account_dashboard_link")
|
| 290 |
async def generate_bank_account_dashboard_link(data: UserIDRequest):
|
| 291 |
try:
|
|
|
|
| 326 |
# Obter detalhes da conta conectada
|
| 327 |
account_details = get_connected_account_details(stripe_id)
|
| 328 |
|
| 329 |
+
# Obter histórico de repasses (payouts)
|
| 330 |
+
payout_history = get_payout_history(stripe_id)
|
| 331 |
+
|
| 332 |
return {
|
| 333 |
"stripe_id": stripe_id,
|
| 334 |
"available_balance": get_account_balance(stripe_id),
|
|
|
|
| 337 |
"total_followers": get_total_followers(user_id),
|
| 338 |
"total_subscribers": get_total_subscribers(user_id),
|
| 339 |
"account_details": account_details,
|
| 340 |
+
"payout_history": payout_history,
|
| 341 |
**get_active_subscribers(user_id, page)
|
| 342 |
}
|
| 343 |
except Exception as e:
|