AkashKumarave commited on
Commit
71357ea
·
verified ·
1 Parent(s): db93c5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -27,10 +27,11 @@ app = FastAPI(title="Kling AI Multi-Image Generator API with Razorpay")
27
  app.add_middleware(
28
  CORSMiddleware,
29
  allow_origins=[
30
- "https://hivili.web.app",
31
  "http://localhost:3000",
32
  "https://*.lovable.dev",
33
  "https://*.sandbox.lovable.dev",
 
34
  ],
35
  allow_origin_regex=r"https://.*\.lovable\.dev|https://.*\.sandbox\.lovable\.dev",
36
  allow_credentials=True,
@@ -147,12 +148,8 @@ def create_razorpay_order(amount: int):
147
  try:
148
  if amount <= 0:
149
  raise ValueError("Amount must be a positive integer")
150
- # Validate supported plan amounts
151
- valid_amounts = [10, 1400, 2200] # INR amounts for plans
152
- if amount not in valid_amounts:
153
- raise ValueError(f"Invalid amount. Must be one of: {valid_amounts}")
154
  order_data = {
155
- "amount": amount * 100, # Convert INR to paise for Razorpay
156
  "currency": "INR",
157
  "payment_capture": 1 # Auto-capture payment
158
  }
@@ -271,20 +268,15 @@ async def create_order_endpoint(
271
  except:
272
  pass
273
 
274
- if not amount:
275
- logger.error("Missing 'amount' parameter")
276
- raise HTTPException(status_code=422, detail="Missing 'amount' parameter")
277
-
278
- if not isinstance(amount, int) or amount <= 0:
279
- logger.error(f"Invalid amount: {amount}")
280
- raise HTTPException(status_code=422, detail="Amount must be a positive integer (10, 1400, or 2200 INR)")
281
 
282
- logger.info(f"Creating order with amount: {amount} INR")
283
  order = create_razorpay_order(amount)
284
 
285
  response_data = {
286
  "id": order["id"],
287
- "amount": order["amount"], # Amount in paise (e.g., 1000 for 10 INR)
288
  "currency": order["currency"],
289
  "key_id": RAZORPAY_KEY_ID
290
  }
 
27
  app.add_middleware(
28
  CORSMiddleware,
29
  allow_origins=[
30
+ "https://hivili.web.app",
31
  "http://localhost:3000",
32
  "https://*.lovable.dev",
33
  "https://*.sandbox.lovable.dev",
34
+ # Add pattern matching for Lovable subdomains
35
  ],
36
  allow_origin_regex=r"https://.*\.lovable\.dev|https://.*\.sandbox\.lovable\.dev",
37
  allow_credentials=True,
 
148
  try:
149
  if amount <= 0:
150
  raise ValueError("Amount must be a positive integer")
 
 
 
 
151
  order_data = {
152
+ "amount": amount * 100, # Convert INR to paise
153
  "currency": "INR",
154
  "payment_capture": 1 # Auto-capture payment
155
  }
 
268
  except:
269
  pass
270
 
271
+ if not amount or amount <= 0:
272
+ raise HTTPException(status_code=422, detail="Missing or invalid 'amount' parameter")
 
 
 
 
 
273
 
274
+ logger.info(f"Creating order with amount: {amount}")
275
  order = create_razorpay_order(amount)
276
 
277
  response_data = {
278
  "id": order["id"],
279
+ "amount": order["amount"],
280
  "currency": order["currency"],
281
  "key_id": RAZORPAY_KEY_ID
282
  }