Update routes/subscription.py
Browse files- routes/subscription.py +14 -20
routes/subscription.py
CHANGED
@@ -163,14 +163,14 @@ def create_checkout_session(
|
|
163 |
raise HTTPException(status_code=404, detail="Stylist not found")
|
164 |
|
165 |
stylist = stylist_data[0]
|
166 |
-
stylist_stripe_id = stylist.get("stripe_id") #
|
167 |
-
price_id = stylist.get("price_id") #
|
168 |
-
consultations = stylist.get("consultations")
|
169 |
|
170 |
-
# 🔹 3.
|
171 |
-
logger.info(f"📌 Stylist
|
172 |
-
|
173 |
-
|
|
|
174 |
|
175 |
# 🔹 4. Buscar dados do cliente (cliente autenticado) usando o user_id
|
176 |
response_user = requests.get(
|
@@ -180,33 +180,28 @@ def create_checkout_session(
|
|
180 |
|
181 |
user_data = response_user.json()
|
182 |
|
183 |
-
#
|
184 |
logger.info(f"📌 Client Data from Supabase: {user_data}")
|
185 |
|
186 |
if not user_data:
|
187 |
raise HTTPException(status_code=404, detail="Client not found")
|
188 |
|
189 |
user = user_data[0]
|
190 |
-
customer_stripe_id = user.get("stripe_id") #
|
191 |
-
stripe_customer_id = user.get("stripe_customer_id") # Garantir que o campo customer_id esteja presente
|
192 |
|
193 |
-
#
|
194 |
-
logger.info(f"📌
|
195 |
-
logger.info(f"📌 Retrieved Client stripe_customer_id: {stripe_customer_id}")
|
196 |
|
197 |
if not customer_stripe_id:
|
198 |
-
raise HTTPException(status_code=400, detail="Client does not have a Stripe ID")
|
199 |
-
|
200 |
-
if not stripe_customer_id:
|
201 |
raise HTTPException(status_code=400, detail="Client does not have a Stripe Customer ID")
|
202 |
|
203 |
-
# 🔹
|
204 |
session = stripe.checkout.Session.create(
|
205 |
success_url="https://yourdomain.com/success",
|
206 |
cancel_url="https://yourdomain.com/cancel",
|
207 |
payment_method_types=["card"],
|
208 |
mode="subscription",
|
209 |
-
customer=
|
210 |
line_items=[
|
211 |
{
|
212 |
"price": price_id, # Usando o price_id do estilista
|
@@ -214,9 +209,8 @@ def create_checkout_session(
|
|
214 |
}
|
215 |
],
|
216 |
metadata={
|
217 |
-
"stylist_id": stylist_stripe_id, # ID da conta do estilista
|
218 |
"user_id": user_id,
|
219 |
-
"consultations_per_month": consultations
|
220 |
}
|
221 |
)
|
222 |
|
|
|
163 |
raise HTTPException(status_code=404, detail="Stylist not found")
|
164 |
|
165 |
stylist = stylist_data[0]
|
166 |
+
stylist_stripe_id = stylist.get("stripe_id") # Pega o stripe_id do estilista
|
167 |
+
price_id = stylist.get("price_id") # Pega o price_id do estilista
|
|
|
168 |
|
169 |
+
# 🔹 3. Verificar dados do estilista
|
170 |
+
logger.info(f"📌 Stylist Stripe ID: {stylist_stripe_id}")
|
171 |
+
logger.info(f"📌 Stylist Price ID: {price_id}")
|
172 |
+
if not stylist_stripe_id or not price_id:
|
173 |
+
raise HTTPException(status_code=400, detail="Stylist profile is incomplete")
|
174 |
|
175 |
# 🔹 4. Buscar dados do cliente (cliente autenticado) usando o user_id
|
176 |
response_user = requests.get(
|
|
|
180 |
|
181 |
user_data = response_user.json()
|
182 |
|
183 |
+
# Verificando dados do cliente
|
184 |
logger.info(f"📌 Client Data from Supabase: {user_data}")
|
185 |
|
186 |
if not user_data:
|
187 |
raise HTTPException(status_code=404, detail="Client not found")
|
188 |
|
189 |
user = user_data[0]
|
190 |
+
customer_stripe_id = user.get("stripe_id") # Pega o stripe_id do cliente
|
|
|
191 |
|
192 |
+
# 🔹 5. Logar os stripe_ids para debugging
|
193 |
+
logger.info(f"📌 Customer Stripe ID: {customer_stripe_id}")
|
|
|
194 |
|
195 |
if not customer_stripe_id:
|
|
|
|
|
|
|
196 |
raise HTTPException(status_code=400, detail="Client does not have a Stripe Customer ID")
|
197 |
|
198 |
+
# 🔹 6. Criar Checkout Session no Stripe
|
199 |
session = stripe.checkout.Session.create(
|
200 |
success_url="https://yourdomain.com/success",
|
201 |
cancel_url="https://yourdomain.com/cancel",
|
202 |
payment_method_types=["card"],
|
203 |
mode="subscription",
|
204 |
+
customer=customer_stripe_id, # Usando o customer_stripe_id do cliente
|
205 |
line_items=[
|
206 |
{
|
207 |
"price": price_id, # Usando o price_id do estilista
|
|
|
209 |
}
|
210 |
],
|
211 |
metadata={
|
212 |
+
"stylist_id": stylist_stripe_id, # ID da conta do estilista
|
213 |
"user_id": user_id,
|
|
|
214 |
}
|
215 |
)
|
216 |
|