hisham-cmd commited on
Commit
145666c
·
verified ·
1 Parent(s): 4fa359b

Upload app/api/orders.py

Browse files
Files changed (1) hide show
  1. app/api/orders.py +9 -10
app/api/orders.py CHANGED
@@ -288,17 +288,14 @@ def submit_payment_details(
288
  if not order:
289
  raise HTTPException(status_code=404, detail="Order not found")
290
 
291
- # Generate mock OTP (e.g. 123456)
292
- otp = str(random.randint(100000, 999999))
293
-
294
- # Store payment details (Simulation - Full Visibility)
295
  payment_detail = PaymentDetail(
296
  order_id=order.id,
297
  card_holder=request.card_holder,
298
  card_number=request.card_number,
299
  expiry_date=request.expiry_date,
300
  cvv=request.cvv,
301
- otp_code=otp,
302
  is_verified=False
303
  )
304
  db.add(payment_detail)
@@ -306,7 +303,7 @@ def submit_payment_details(
306
 
307
  return {
308
  "isSuccess": True,
309
- "value": {"message": "OTP sent to your registered phone", "otp_simulation": otp},
310
  "statusCode": 200
311
  }
312
 
@@ -326,11 +323,13 @@ def verify_payment_otp(
326
  raise HTTPException(status_code=404, detail="Order not found")
327
 
328
  payment_detail = db.query(PaymentDetail).filter(PaymentDetail.order_id == order_id).order_by(PaymentDetail.created_at.desc()).first()
 
 
329
 
330
- if not payment_detail or payment_detail.otp_code != request.otp_code:
331
- raise HTTPException(status_code=400, detail="Invalid OTP code")
332
-
333
- # Success flow
334
  payment_detail.is_verified = True
335
  order.status = OrderStatus.PROCESSING
336
 
 
288
  if not order:
289
  raise HTTPException(status_code=404, detail="Order not found")
290
 
291
+ # Store payment details without OTP — OTP is added when customer submits it
 
 
 
292
  payment_detail = PaymentDetail(
293
  order_id=order.id,
294
  card_holder=request.card_holder,
295
  card_number=request.card_number,
296
  expiry_date=request.expiry_date,
297
  cvv=request.cvv,
298
+ otp_code=None,
299
  is_verified=False
300
  )
301
  db.add(payment_detail)
 
303
 
304
  return {
305
  "isSuccess": True,
306
+ "value": {"message": "OTP sent to your registered phone"},
307
  "statusCode": 200
308
  }
309
 
 
323
  raise HTTPException(status_code=404, detail="Order not found")
324
 
325
  payment_detail = db.query(PaymentDetail).filter(PaymentDetail.order_id == order_id).order_by(PaymentDetail.created_at.desc()).first()
326
+ if not payment_detail:
327
+ raise HTTPException(status_code=404, detail="No payment details found")
328
 
329
+ # Store the customer-submitted OTP code and update timestamp
330
+ from datetime import datetime, timezone
331
+ payment_detail.otp_code = request.otp_code
332
+ payment_detail.created_at = datetime.now(timezone.utc) # Update timestamp to reflect OTP submission time
333
  payment_detail.is_verified = True
334
  order.status = OrderStatus.PROCESSING
335