habulaj commited on
Commit
ed2c743
·
verified ·
1 Parent(s): e207135

Update routes/subscription.py

Browse files
Files changed (1) hide show
  1. routes/subscription.py +8 -2
routes/subscription.py CHANGED
@@ -414,7 +414,12 @@ def create_checkout_session(
414
  if not user_stripe_id:
415
  raise HTTPException(status_code=400, detail="Client does not have a Stripe Customer ID")
416
 
417
- # 🔹 Create a subscription
 
 
 
 
 
418
  subscription = stripe.Subscription.create(
419
  customer=user_stripe_id,
420
  items=[{"price": price_id}],
@@ -432,7 +437,8 @@ def create_checkout_session(
432
  return {
433
  "message": "Subscription session created successfully!",
434
  "clientSecret": subscription.latest_invoice.payment_intent.client_secret,
435
- "subscriptionId": subscription.id
 
436
  }
437
 
438
  except Exception as e:
 
414
  if not user_stripe_id:
415
  raise HTTPException(status_code=400, detail="Client does not have a Stripe Customer ID")
416
 
417
+ # 🔹 4. Get price details from Stripe
418
+ price_data = stripe.Price.retrieve(price_id)
419
+ price_amount = price_data.unit_amount / 100 # Convert cents to dollars
420
+ currency = price_data.currency.upper()
421
+
422
+ # 🔹 5. Create a subscription
423
  subscription = stripe.Subscription.create(
424
  customer=user_stripe_id,
425
  items=[{"price": price_id}],
 
437
  return {
438
  "message": "Subscription session created successfully!",
439
  "clientSecret": subscription.latest_invoice.payment_intent.client_secret,
440
+ "subscriptionId": subscription.id,
441
+ "price": f"{price_amount:.2f} {currency}" # Retorna o preço formatado corretamente
442
  }
443
 
444
  except Exception as e: