nagasurendra commited on
Commit
a7c0298
·
verified ·
1 Parent(s): 7a42b14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -424,15 +424,19 @@ def checkout():
424
  customer = customer_record.get("records", [])[0] if customer_record else None
425
 
426
  if customer:
427
- # Check if 'Id' exists in the customer record before attempting to update
428
- if 'Id' not in customer:
429
- return jsonify({"success": False, "message": "'Id' not found for customer record."})
430
-
431
- # Calculate 10% of the subtotal
432
- reward_points_to_add = total_price * 0.10
433
-
434
- # Add the new reward points to the existing value
435
- new_reward_points = customer['Reward_Points__c'] + reward_points_to_add if customer.get('Reward_Points__c') else reward_points_to_add
 
 
 
 
436
 
437
  # Update the Reward_Points__c field in Salesforce
438
  try:
@@ -453,6 +457,7 @@ def checkout():
453
  return jsonify({"success": False, "error": str(e)})
454
 
455
 
 
456
  @app.route("/order", methods=["GET"])
457
  def order_summary():
458
  email = session.get('user_email') # Fetch logged-in user's email
 
424
  customer = customer_record.get("records", [])[0] if customer_record else None
425
 
426
  if customer:
427
+ # Get the checkbox status from the frontend
428
+ use_reward_points = request.json.get("useRewardPoints", False)
429
+
430
+ if use_reward_points:
431
+ # Subtract 500 points if checkbox is selected
432
+ if customer['Reward_Points__c'] >= 500:
433
+ new_reward_points = customer['Reward_Points__c'] - 500
434
+ else:
435
+ return jsonify({"success": False, "message": "Insufficient reward points to apply."})
436
+ else:
437
+ # Add 10% of the subtotal if checkbox is not selected
438
+ reward_points_to_add = total_price * 0.10
439
+ new_reward_points = customer['Reward_Points__c'] + reward_points_to_add
440
 
441
  # Update the Reward_Points__c field in Salesforce
442
  try:
 
457
  return jsonify({"success": False, "error": str(e)})
458
 
459
 
460
+
461
  @app.route("/order", methods=["GET"])
462
  def order_summary():
463
  email = session.get('user_email') # Fetch logged-in user's email