Update routes/subscription.py
Browse files- routes/subscription.py +18 -7
routes/subscription.py
CHANGED
@@ -73,15 +73,26 @@ async def generate_dashboard_link(data: UserIDRequest):
|
|
73 |
try:
|
74 |
user_id = data.user_id # O ID do estilista ou cliente
|
75 |
|
|
|
76 |
if user_id.startswith("acct_"):
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
elif user_id.startswith("cus_"):
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
85 |
|
86 |
else:
|
87 |
raise HTTPException(status_code=400, detail="Invalid user ID format. Must start with 'acct_' for stylist or 'cus_' for customer.")
|
|
|
73 |
try:
|
74 |
user_id = data.user_id # O ID do estilista ou cliente
|
75 |
|
76 |
+
# Verifica se é um estilista (conta conectada)
|
77 |
if user_id.startswith("acct_"):
|
78 |
+
try:
|
79 |
+
# Cria o login link para o painel do estilista (Stripe Express)
|
80 |
+
login_link = stripe.Account.create_login_link(user_id)
|
81 |
+
|
82 |
+
return {
|
83 |
+
"status": "success",
|
84 |
+
"dashboard_link": login_link.url # Retorna o link gerado para o painel do estilista
|
85 |
+
}
|
86 |
+
except stripe.error.StripeError as e:
|
87 |
+
logger.error(f"Error creating login link for stylist account: {str(e)}")
|
88 |
+
raise HTTPException(status_code=500, detail="Error creating login link for stylist account.")
|
89 |
+
|
90 |
+
# Caso seja um cliente, não podemos criar um login link
|
91 |
elif user_id.startswith("cus_"):
|
92 |
+
return {
|
93 |
+
"status": "success",
|
94 |
+
"dashboard_link": f"https://billing.stripe.com/p/{user_id}"
|
95 |
+
}
|
96 |
|
97 |
else:
|
98 |
raise HTTPException(status_code=400, detail="Invalid user ID format. Must start with 'acct_' for stylist or 'cus_' for customer.")
|