Fred808 commited on
Commit
b3f38b0
·
verified ·
1 Parent(s): 93221cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -37
app.py CHANGED
@@ -425,7 +425,7 @@ def send_email_notification(order_details):
425
  # Construct the email payload. Adjust values as needed.
426
  payload = {
427
  "from": "yungdml31@gmail.com",
428
- "to": "samyung05@gmail.com, angelofoodcourt@gmail.com", # You can also use a comma-separated list for multiple recipients.
429
  "subject": f"New Order Received: {order_details['order_id']}",
430
  "body": (
431
  f"New Order Received:\n"
@@ -624,36 +624,50 @@ async def process_order_flow(user_id: str, message: str) -> str:
624
  f"Your delivery address is: {state.data['address']}.\n"
625
  f"Your delivery cost is N{shipping_cost}. Would you like extras (yes/no)?")
626
 
627
- # 5) Step 5: Ask about extras.
628
  if state and state.flow == "order" and state.step == 5:
629
- if message.lower() in ["yes", "y"]:
 
630
  state.step = 6
631
  return "Please list the extras you'd like (e.g., drinks, sides)."
632
- elif message.lower() in ["no", "n"]:
633
  state.data["extras"] = ""
634
  state.step = 7
635
- # Prepare order summary for confirmation.
636
- if "orders" in state.data:
637
- # Multi-dish order summary:
638
  summary = "\n".join([f"{qty} serving(s) of {dish}" for dish, qty in state.data["orders"].items()])
639
  quantity_total = sum(state.data["orders"].values())
640
  dish_summary = ", ".join(state.data["orders"].keys())
641
- else:
642
  summary = f"{state.data.get('quantity', 1)} serving(s) of {state.data.get('dish', '')}"
643
  quantity_total = state.data.get("quantity", 1)
644
  dish_summary = state.data.get("dish", "")
645
- price_per_serving = get_dish_price(state.data.get("dish", "")) if "dish" in state.data else 0
646
- total_price = (quantity_total * price_per_serving) + state.data.get("shipping_cost", 0)
647
- confirmation = (f"Order Summary:\nDish(es): {dish_summary}\nQuantity: {quantity_total}\n"
648
- f"Phone: {state.data.get('phone_number', '')}\n"
649
- f"Address: {state.data.get('address', '')}\n"
650
- f"Shipping Cost: N{state.data.get('shipping_cost', 0)}\n"
651
- f"Total Price: N{total_price}\n"
652
- f"Extras: None\nConfirm order? (yes/no)")
 
 
 
 
 
 
 
 
 
 
 
 
 
653
  return confirmation
654
  else:
655
  return "Please respond with 'yes' or 'no' regarding extras."
656
 
 
657
  # 6) Step 6: Process extras list.
658
  if state and state.flow == "order" and state.step == 6:
659
  state.data["extras"] = message
@@ -712,27 +726,6 @@ async def process_order_flow(user_id: str, message: str) -> str:
712
  asyncio.create_task(save_order())
713
  asyncio.create_task(log_order_tracking(order_id, "Order Placed", "Order placed and awaiting payment."))
714
 
715
- # Send email notification to admin via SMTP (using your SMTP integration)
716
- admin_emails = os.getenv("ADMIN_EMAILS", "samyung05@gmail.com").split(",")
717
- email_subject = f"New Order Received: {order_id}"
718
- email_body = (
719
- f"New Order Received:\n"
720
- f"Order ID: {order_id}\n"
721
- f"Dish(es): {dish_summary}\n"
722
- f"Quantity: {quantity_total}\n"
723
- f"Total Price: N{total_price}\n"
724
- f"Phone: {state.data.get('phone_number', '')}\n"
725
- f"Delivery Address: {state.data.get('address', 'Not Provided')}\n"
726
- f"Extras: {state.data.get('extras', 'None')}\n"
727
- f"Status: Pending Payment"
728
- )
729
- # Call your SMTP API or use a helper to send email:
730
- email_sent = send_email_notification(admin_emails, email_subject, email_body)
731
- if email_sent:
732
- print("Email notification sent successfully.")
733
- else:
734
- print("Failed to send email notification.")
735
-
736
  email_for_paystack = "customer@example.com" # Replace with actual email if available
737
  payment_data = create_paystack_payment_link(email_for_paystack, total_price * 100, order_id)
738
  state.reset()
 
425
  # Construct the email payload. Adjust values as needed.
426
  payload = {
427
  "from": "yungdml31@gmail.com",
428
+ "to": "samyung05@gmail.com", # You can also use a comma-separated list for multiple recipients.
429
  "subject": f"New Order Received: {order_details['order_id']}",
430
  "body": (
431
  f"New Order Received:\n"
 
624
  f"Your delivery address is: {state.data['address']}.\n"
625
  f"Your delivery cost is N{shipping_cost}. Would you like extras (yes/no)?")
626
 
627
+ # Step 5: Ask about extras.
628
  if state and state.flow == "order" and state.step == 5:
629
+ normalized = message.strip().lower()
630
+ if normalized in ["yes", "y"]:
631
  state.step = 6
632
  return "Please list the extras you'd like (e.g., drinks, sides)."
633
+ elif normalized in ["no", "n"]:
634
  state.data["extras"] = ""
635
  state.step = 7
636
+ # Build order summary for confirmation:
637
+ if "orders" in state.data: # Multiple-dish order
 
638
  summary = "\n".join([f"{qty} serving(s) of {dish}" for dish, qty in state.data["orders"].items()])
639
  quantity_total = sum(state.data["orders"].values())
640
  dish_summary = ", ".join(state.data["orders"].keys())
641
+ else: # Single-dish order
642
  summary = f"{state.data.get('quantity', 1)} serving(s) of {state.data.get('dish', '')}"
643
  quantity_total = state.data.get("quantity", 1)
644
  dish_summary = state.data.get("dish", "")
645
+ # Determine the price correctly
646
+ if "dish" in state.data:
647
+ price_per_serving = get_dish_price(state.data["dish"])
648
+ total_price = (quantity_total * price_per_serving) + state.data.get("shipping_cost", 0)
649
+ elif "orders" in state.data:
650
+ total_price = 0
651
+ for dish, qty in state.data["orders"].items():
652
+ total_price += get_dish_price(dish) * qty
653
+ total_price += state.data.get("shipping_cost", 0)
654
+ else:
655
+ total_price = state.data.get("shipping_cost", 0)
656
+ confirmation = (
657
+ f"Order Summary:\n"
658
+ f"Dish(es): {dish_summary}\n"
659
+ f"Quantity: {quantity_total}\n"
660
+ f"Phone: {state.data.get('phone_number', '')}\n"
661
+ f"Address: {state.data.get('address', '')}\n"
662
+ f"Shipping Cost: N{state.data.get('shipping_cost', 0)}\n"
663
+ f"Total Price: N{total_price}\n"
664
+ f"Extras: None\nConfirm order? (yes/no)"
665
+ )
666
  return confirmation
667
  else:
668
  return "Please respond with 'yes' or 'no' regarding extras."
669
 
670
+
671
  # 6) Step 6: Process extras list.
672
  if state and state.flow == "order" and state.step == 6:
673
  state.data["extras"] = message
 
726
  asyncio.create_task(save_order())
727
  asyncio.create_task(log_order_tracking(order_id, "Order Placed", "Order placed and awaiting payment."))
728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
  email_for_paystack = "customer@example.com" # Replace with actual email if available
730
  payment_data = create_paystack_payment_link(email_for_paystack, total_price * 100, order_id)
731
  state.reset()