habulaj commited on
Commit
3c6bfef
·
verified ·
1 Parent(s): 4835bd1

Update routes/stylist.py

Browse files
Files changed (1) hide show
  1. routes/stylist.py +48 -0
routes/stylist.py CHANGED
@@ -96,6 +96,45 @@ def get_weekly_revenue(account_id: str) -> List[Dict[str, Any]]:
96
  logger.error(f"❌ Error getting weekly revenue: {str(e)}")
97
  return []
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  @router.get("/dashboard")
100
  def get_dashboard(user_token: str = Header(None, alias="User-key")):
101
  try:
@@ -126,14 +165,23 @@ def get_dashboard(user_token: str = Header(None, alias="User-key")):
126
  if not stripe_id:
127
  return {
128
  "stripe_id": None,
 
 
 
129
  "weekly_revenue": []
130
  }
131
 
 
 
 
132
  # Buscar valores recebidos nas últimas 6 semanas
133
  weekly_revenue = get_weekly_revenue(stripe_id)
134
 
135
  return {
136
  "stripe_id": stripe_id,
 
 
 
137
  "weekly_revenue": weekly_revenue
138
  }
139
 
 
96
  logger.error(f"❌ Error getting weekly revenue: {str(e)}")
97
  return []
98
 
99
+ def get_account_balance(account_id: str) -> Dict[str, Any]:
100
+ """
101
+ Busca o saldo disponível e pendente da conta Stripe.
102
+ """
103
+ try:
104
+ balance = stripe.Balance.retrieve(stripe_account=account_id)
105
+
106
+ # Inicializar valores
107
+ available_balance = 0
108
+ pending_balance = 0
109
+ currency = "BRL" # Default para BRL
110
+
111
+ # Calcular saldo disponível
112
+ for balance_item in balance.available:
113
+ if balance_item.currency.upper() == "BRL":
114
+ available_balance = balance_item.amount
115
+ currency = "BRL"
116
+ break
117
+
118
+ # Calcular saldo pendente
119
+ for balance_item in balance.pending:
120
+ if balance_item.currency.upper() == "BRL":
121
+ pending_balance = balance_item.amount
122
+ break
123
+
124
+ return {
125
+ "available_balance": available_balance,
126
+ "pending_balance": pending_balance,
127
+ "currency": currency
128
+ }
129
+
130
+ except Exception as e:
131
+ logger.error(f"❌ Error getting account balance: {str(e)}")
132
+ return {
133
+ "available_balance": 0,
134
+ "pending_balance": 0,
135
+ "currency": "BRL"
136
+ }
137
+
138
  @router.get("/dashboard")
139
  def get_dashboard(user_token: str = Header(None, alias="User-key")):
140
  try:
 
165
  if not stripe_id:
166
  return {
167
  "stripe_id": None,
168
+ "available_balance": 0,
169
+ "pending_balance": 0,
170
+ "currency": "BRL",
171
  "weekly_revenue": []
172
  }
173
 
174
+ # Buscar saldo da conta
175
+ balance_info = get_account_balance(stripe_id)
176
+
177
  # Buscar valores recebidos nas últimas 6 semanas
178
  weekly_revenue = get_weekly_revenue(stripe_id)
179
 
180
  return {
181
  "stripe_id": stripe_id,
182
+ "available_balance": balance_info["available_balance"],
183
+ "pending_balance": balance_info["pending_balance"],
184
+ "currency": balance_info["currency"],
185
  "weekly_revenue": weekly_revenue
186
  }
187