Update routes/subscription.py
Browse files- routes/subscription.py +10 -2
routes/subscription.py
CHANGED
@@ -186,20 +186,25 @@ def create_checkout_session(
|
|
186 |
|
187 |
user = user_data[0]
|
188 |
user_stripe_id = user.get("stripe_id")
|
|
|
189 |
|
190 |
-
#
|
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(
|
198 |
success_url="https://yourdomain.com/success",
|
199 |
cancel_url="https://yourdomain.com/cancel",
|
200 |
payment_method_types=["card"],
|
201 |
mode="subscription",
|
202 |
-
customer=
|
203 |
line_items=[
|
204 |
{
|
205 |
"price": price_id, # Agora estamos usando o price_id do estilista
|
@@ -212,6 +217,9 @@ def create_checkout_session(
|
|
212 |
"consultations_per_month": consultations
|
213 |
}
|
214 |
)
|
|
|
|
|
|
|
215 |
return {
|
216 |
"message": "Checkout session created successfully!",
|
217 |
"checkout_url": session.url
|
|
|
186 |
|
187 |
user = user_data[0]
|
188 |
user_stripe_id = user.get("stripe_id")
|
189 |
+
stripe_customer_id = user.get("stripe_customer_id") # Garantir que o campo customer_id esteja presente
|
190 |
|
191 |
+
# Verificar o stripe_customer_id
|
192 |
logger.info(f"📌 Retrieved user stripe_id: {user_stripe_id}")
|
193 |
+
logger.info(f"📌 Retrieved user stripe_customer_id: {stripe_customer_id}")
|
194 |
|
195 |
if not user_stripe_id:
|
196 |
raise HTTPException(status_code=400, detail="User does not have a Stripe ID")
|
197 |
|
198 |
+
if not stripe_customer_id:
|
199 |
+
raise HTTPException(status_code=400, detail="User does not have a Stripe Customer ID")
|
200 |
+
|
201 |
# 🔹 4. Criar Checkout Session no Stripe
|
202 |
session = stripe.checkout.Session.create(
|
203 |
success_url="https://yourdomain.com/success",
|
204 |
cancel_url="https://yourdomain.com/cancel",
|
205 |
payment_method_types=["card"],
|
206 |
mode="subscription",
|
207 |
+
customer=stripe_customer_id, # Agora estamos passando o stripe_customer_id
|
208 |
line_items=[
|
209 |
{
|
210 |
"price": price_id, # Agora estamos usando o price_id do estilista
|
|
|
217 |
"consultations_per_month": consultations
|
218 |
}
|
219 |
)
|
220 |
+
|
221 |
+
logger.info(f"📌 Checkout session created successfully: {session.url}")
|
222 |
+
|
223 |
return {
|
224 |
"message": "Checkout session created successfully!",
|
225 |
"checkout_url": session.url
|