Update routes/subscription.py
Browse files- routes/subscription.py +16 -5
routes/subscription.py
CHANGED
@@ -87,13 +87,24 @@ async def generate_dashboard_link(data: UserIDRequest):
|
|
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,
|
91 |
elif user_id.startswith("cus_"):
|
92 |
-
|
93 |
-
|
94 |
-
|
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.")
|
99 |
|
|
|
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, criamos uma sessão do portal de cobrança
|
91 |
elif user_id.startswith("cus_"):
|
92 |
+
try:
|
93 |
+
# Cria uma sessão do portal de cobrança para o cliente
|
94 |
+
session = stripe.billing_portal.Session.create(
|
95 |
+
customer=user_id,
|
96 |
+
return_url="https://your-website.com/account" # URL para onde o cliente será redirecionado após sair do portal
|
97 |
+
)
|
98 |
+
|
99 |
+
return {
|
100 |
+
"status": "success",
|
101 |
+
"dashboard_link": session.url # Retorna o link para o painel do cliente
|
102 |
+
}
|
103 |
|
104 |
+
except stripe.error.StripeError as e:
|
105 |
+
logger.error(f"Error creating billing portal session for customer: {str(e)}")
|
106 |
+
raise HTTPException(status_code=500, detail="Error creating billing portal session for customer.")
|
107 |
+
|
108 |
else:
|
109 |
raise HTTPException(status_code=400, detail="Invalid user ID format. Must start with 'acct_' for stylist or 'cus_' for customer.")
|
110 |
|