habulaj commited on
Commit
59615d0
·
verified ·
1 Parent(s): 75a84ba

Update routes/subscription.py

Browse files
Files changed (1) hide show
  1. routes/subscription.py +22 -5
routes/subscription.py CHANGED
@@ -23,20 +23,37 @@ class SubscriptionRequest(BaseModel):
23
  class CancelSubscriptionRequest(BaseModel):
24
  subscription_id: str
25
 
26
- ### 1. CRIAR PREÇO DINÂMICO ###
27
  @router.post("/create_price")
28
- def create_price(data: PriceRequest):
29
  try:
30
- product = stripe.Product.create(name="Stylist Subscription")
 
 
 
 
 
 
 
31
  price = stripe.Price.create(
32
  unit_amount=data.amount,
33
  currency="brl",
34
  recurring={"interval": "month"},
35
  product=product.id,
36
  )
37
- return {"price_id": price.id}
 
 
 
 
 
 
 
 
 
38
  except Exception as e:
39
- raise HTTPException(status_code=500, detail=str(e))
 
40
 
41
  ### 2. INICIAR O CHECKOUT COM UM PREÇO EXISTENTE ###
42
  @router.post("/create_checkout_session")
 
23
  class CancelSubscriptionRequest(BaseModel):
24
  subscription_id: str
25
 
26
+ ### 1. CREATE DYNAMIC PRICE ###
27
  @router.post("/create_price")
28
+ def create_price(data: PriceRequest, stylist_name: str):
29
  try:
30
+ product_name = f"{stylist_name}'s Subscription"
31
+ product_description = f"Monthly plan to access exclusive services from {stylist_name}."
32
+
33
+ product = stripe.Product.create(
34
+ name=product_name,
35
+ description=product_description,
36
+ )
37
+
38
  price = stripe.Price.create(
39
  unit_amount=data.amount,
40
  currency="brl",
41
  recurring={"interval": "month"},
42
  product=product.id,
43
  )
44
+
45
+ return {
46
+ "message": "Price created successfully!",
47
+ "price_id": price.id,
48
+ "product_id": product.id,
49
+ "product_name": product_name,
50
+ "product_description": product_description,
51
+ "amount": data.amount / 100, # Converting to real currency
52
+ "currency": "BRL",
53
+ }
54
  except Exception as e:
55
+ logger.error(f"Error creating price: {e}")
56
+ raise HTTPException(status_code=500, detail="Error creating price.")
57
 
58
  ### 2. INICIAR O CHECKOUT COM UM PREÇO EXISTENTE ###
59
  @router.post("/create_checkout_session")