Update routes/subscription.py
Browse files- routes/subscription.py +24 -3
routes/subscription.py
CHANGED
@@ -431,11 +431,32 @@ async def stripe_webhook(request: Request):
|
|
431 |
logger.info(f"📝 Chat ID: {chat_id}")
|
432 |
|
433 |
if chat_id:
|
434 |
-
# 🔹
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
message_data = {
|
436 |
"chat_id": chat_id,
|
437 |
"sender_id": user_id,
|
438 |
-
"content": "subscribed for 1 month",
|
439 |
"type": "warning"
|
440 |
}
|
441 |
|
@@ -451,7 +472,7 @@ async def stripe_webhook(request: Request):
|
|
451 |
|
452 |
if response_message.status_code == 201:
|
453 |
logger.info(f"✅ Initial message created for chat {chat_id}")
|
454 |
-
logger.info(f"📝 Message
|
455 |
else:
|
456 |
logger.error(f"❌ Failed to create initial message: {response_message.status_code} - {response_message.text}")
|
457 |
else:
|
|
|
431 |
logger.info(f"📝 Chat ID: {chat_id}")
|
432 |
|
433 |
if chat_id:
|
434 |
+
# 🔹 Buscar nome do usuário
|
435 |
+
user_response = requests.get(
|
436 |
+
f"{SUPABASE_URL}/rest/v1/User?id=eq.{user_id}&select=name",
|
437 |
+
headers=SUPABASE_ROLE_HEADERS
|
438 |
+
)
|
439 |
+
|
440 |
+
formatted_name = "User" # Nome padrão caso não encontre
|
441 |
+
|
442 |
+
if user_response.status_code == 200:
|
443 |
+
user_data = user_response.json()
|
444 |
+
if user_data and len(user_data) > 0:
|
445 |
+
full_name = user_data[0].get('name', '').strip()
|
446 |
+
name_parts = full_name.split()
|
447 |
+
|
448 |
+
if len(name_parts) > 1:
|
449 |
+
# Primeiro nome + primeira letra do segundo nome
|
450 |
+
formatted_name = f"{name_parts[0]} {name_parts[1][0]}"
|
451 |
+
else:
|
452 |
+
# Apenas primeiro nome
|
453 |
+
formatted_name = name_parts[0]
|
454 |
+
|
455 |
+
# 🔹 Criando mensagem inicial com nome formatado
|
456 |
message_data = {
|
457 |
"chat_id": chat_id,
|
458 |
"sender_id": user_id,
|
459 |
+
"content": f"{formatted_name} subscribed for 1 month",
|
460 |
"type": "warning"
|
461 |
}
|
462 |
|
|
|
472 |
|
473 |
if response_message.status_code == 201:
|
474 |
logger.info(f"✅ Initial message created for chat {chat_id}")
|
475 |
+
logger.info(f"📝 Message: {formatted_name} subscribed for 1 month")
|
476 |
else:
|
477 |
logger.error(f"❌ Failed to create initial message: {response_message.status_code} - {response_message.text}")
|
478 |
else:
|