Update routes/users.py
Browse files- routes/users.py +7 -19
routes/users.py
CHANGED
|
@@ -238,26 +238,14 @@ async def get_user_transfer_history(
|
|
| 238 |
product_name = None
|
| 239 |
invoice_id = charge.get("invoice")
|
| 240 |
|
|
|
|
| 241 |
if invoice_id and isinstance(invoice_id, str):
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
if price:
|
| 249 |
-
product = price.get("product")
|
| 250 |
-
# Caso product seja apenas o ID, buscar o nome do produto
|
| 251 |
-
if isinstance(product, str):
|
| 252 |
-
try:
|
| 253 |
-
product_obj = stripe.Product.retrieve(product)
|
| 254 |
-
product_name = product_obj.get("name")
|
| 255 |
-
except Exception as e:
|
| 256 |
-
logger.warning(f"⚠️ Erro ao buscar produto: {e}")
|
| 257 |
-
elif isinstance(product, dict):
|
| 258 |
-
product_name = product.get("name")
|
| 259 |
-
except Exception as e:
|
| 260 |
-
logger.warning(f"⚠️ Erro ao expandir invoice ou obter produto: {e}")
|
| 261 |
|
| 262 |
transfers.append({
|
| 263 |
"id": charge["id"],
|
|
|
|
| 238 |
product_name = None
|
| 239 |
invoice_id = charge.get("invoice")
|
| 240 |
|
| 241 |
+
# Se houver fatura, tentar obter o nome do produto
|
| 242 |
if invoice_id and isinstance(invoice_id, str):
|
| 243 |
+
invoice = stripe.Invoice.retrieve(invoice_id, expand=["lines.data.price.product"])
|
| 244 |
+
if invoice and invoice["lines"]["data"]:
|
| 245 |
+
first_line = invoice["lines"]["data"][0]
|
| 246 |
+
product = first_line.get("price", {}).get("product")
|
| 247 |
+
if isinstance(product, dict):
|
| 248 |
+
product_name = product.get("name")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
transfers.append({
|
| 251 |
"id": charge["id"],
|