Update routes/subscription.py
Browse files- routes/subscription.py +8 -10
routes/subscription.py
CHANGED
@@ -152,7 +152,7 @@ def create_checkout_session(
|
|
152 |
# 🔹 1. Validar o token e obter user_id
|
153 |
user_id = verify_token(user_token)
|
154 |
|
155 |
-
# 🔹 2. Buscar estilista no Supabase
|
156 |
response = requests.get(
|
157 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{data.id}",
|
158 |
headers=SUPABASE_HEADERS
|
@@ -165,11 +165,12 @@ def create_checkout_session(
|
|
165 |
stylist = stylist_data[0]
|
166 |
stylist_stripe_id = stylist.get("stripe_id")
|
167 |
consultations = stylist.get("consultations")
|
|
|
168 |
|
169 |
-
if not consultations or not stylist_stripe_id:
|
170 |
-
raise HTTPException(status_code=400, detail="Stylist profile is incomplete")
|
171 |
|
172 |
-
# 🔹 3. Buscar stripe_id
|
173 |
response_user = requests.get(
|
174 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{user_id}",
|
175 |
headers=SUPABASE_HEADERS
|
@@ -185,15 +186,12 @@ def create_checkout_session(
|
|
185 |
|
186 |
user = user_data[0]
|
187 |
user_stripe_id = user.get("stripe_id")
|
188 |
-
price_id = user.get("price_id")
|
189 |
|
190 |
-
# Depuração: Verificando o
|
191 |
-
logger.info(f"📌 Retrieved
|
192 |
|
193 |
if not user_stripe_id:
|
194 |
raise HTTPException(status_code=400, detail="User does not have a Stripe ID")
|
195 |
-
if not price_id:
|
196 |
-
raise HTTPException(status_code=400, detail="User does not have a valid price ID")
|
197 |
|
198 |
# 🔹 4. Criar Checkout Session no Stripe
|
199 |
session = stripe.checkout.Session.create(
|
@@ -204,7 +202,7 @@ def create_checkout_session(
|
|
204 |
customer=user.get("stripe_customer_id"), # Certifique-se de que isso retorna 'cus_...'
|
205 |
line_items=[
|
206 |
{
|
207 |
-
"price": price_id, #
|
208 |
"quantity": 1
|
209 |
}
|
210 |
],
|
|
|
152 |
# 🔹 1. Validar o token e obter user_id
|
153 |
user_id = verify_token(user_token)
|
154 |
|
155 |
+
# 🔹 2. Buscar estilista no Supabase usando o ID enviado na solicitação
|
156 |
response = requests.get(
|
157 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{data.id}",
|
158 |
headers=SUPABASE_HEADERS
|
|
|
165 |
stylist = stylist_data[0]
|
166 |
stylist_stripe_id = stylist.get("stripe_id")
|
167 |
consultations = stylist.get("consultations")
|
168 |
+
price_id = stylist.get("price_id") # Buscar o price_id do estilista
|
169 |
|
170 |
+
if not consultations or not stylist_stripe_id or not price_id:
|
171 |
+
raise HTTPException(status_code=400, detail="Stylist profile is incomplete or missing price_id")
|
172 |
|
173 |
+
# 🔹 3. Buscar stripe_id do usuário autenticado (cliente)
|
174 |
response_user = requests.get(
|
175 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{user_id}",
|
176 |
headers=SUPABASE_HEADERS
|
|
|
186 |
|
187 |
user = user_data[0]
|
188 |
user_stripe_id = user.get("stripe_id")
|
|
|
189 |
|
190 |
+
# Depuração: Verificando o stripe_id do usuário
|
191 |
+
logger.info(f"📌 Retrieved user stripe_id: {user_stripe_id}")
|
192 |
|
193 |
if not user_stripe_id:
|
194 |
raise HTTPException(status_code=400, detail="User does not have a Stripe ID")
|
|
|
|
|
195 |
|
196 |
# 🔹 4. Criar Checkout Session no Stripe
|
197 |
session = stripe.checkout.Session.create(
|
|
|
202 |
customer=user.get("stripe_customer_id"), # Certifique-se de que isso retorna 'cus_...'
|
203 |
line_items=[
|
204 |
{
|
205 |
+
"price": price_id, # Agora estamos usando o price_id do estilista
|
206 |
"quantity": 1
|
207 |
}
|
208 |
],
|