Update app.py
Browse files
app.py
CHANGED
|
@@ -557,10 +557,9 @@ async def process_order_flow(user_id: str, message: str) -> str:
|
|
| 557 |
state.data["order_id"] = order_id
|
| 558 |
price_per_serving = 1500
|
| 559 |
quantity = state.data.get("quantity", 1)
|
| 560 |
-
|
| 561 |
-
total_price = (quantity * price_per_serving) + shipping_cost
|
| 562 |
state.data["price"] = str(total_price)
|
| 563 |
-
|
| 564 |
async def save_order():
|
| 565 |
async with async_session() as session:
|
| 566 |
order = Order(
|
|
@@ -574,9 +573,12 @@ async def process_order_flow(user_id: str, message: str) -> str:
|
|
| 574 |
)
|
| 575 |
session.add(order)
|
| 576 |
await session.commit()
|
| 577 |
-
|
|
|
|
|
|
|
|
|
|
| 578 |
asyncio.create_task(log_order_tracking(order_id, "Order Placed", "Order placed and awaiting payment."))
|
| 579 |
-
|
| 580 |
async def notify_management_order(order_details: dict):
|
| 581 |
message_body = (
|
| 582 |
f"New Order Received:\n"
|
|
@@ -590,6 +592,7 @@ async def process_order_flow(user_id: str, message: str) -> str:
|
|
| 590 |
f"Status: Pending Payment"
|
| 591 |
)
|
| 592 |
await asyncio.to_thread(send_whatsapp_message, MANAGEMENT_WHATSAPP_NUMBER, message_body)
|
|
|
|
| 593 |
order_details = {
|
| 594 |
"order_id": order_id,
|
| 595 |
"dish": state.data["dish"],
|
|
@@ -598,7 +601,7 @@ async def process_order_flow(user_id: str, message: str) -> str:
|
|
| 598 |
"address": state.data.get("address", "")
|
| 599 |
}
|
| 600 |
asyncio.create_task(notify_management_order(order_details))
|
| 601 |
-
|
| 602 |
email = "customer@example.com"
|
| 603 |
payment_data = create_paystack_payment_link(email, total_price * 100, order_id)
|
| 604 |
dish_name = state.data.get("dish", "")
|
|
|
|
| 557 |
state.data["order_id"] = order_id
|
| 558 |
price_per_serving = 1500
|
| 559 |
quantity = state.data.get("quantity", 1)
|
| 560 |
+
total_price = quantity * price_per_serving # Removed shipping cost
|
|
|
|
| 561 |
state.data["price"] = str(total_price)
|
| 562 |
+
|
| 563 |
async def save_order():
|
| 564 |
async with async_session() as session:
|
| 565 |
order = Order(
|
|
|
|
| 573 |
)
|
| 574 |
session.add(order)
|
| 575 |
await session.commit()
|
| 576 |
+
|
| 577 |
+
# Await the save_order task to ensure the order is committed before proceeding.
|
| 578 |
+
await save_order()
|
| 579 |
+
|
| 580 |
asyncio.create_task(log_order_tracking(order_id, "Order Placed", "Order placed and awaiting payment."))
|
| 581 |
+
|
| 582 |
async def notify_management_order(order_details: dict):
|
| 583 |
message_body = (
|
| 584 |
f"New Order Received:\n"
|
|
|
|
| 592 |
f"Status: Pending Payment"
|
| 593 |
)
|
| 594 |
await asyncio.to_thread(send_whatsapp_message, MANAGEMENT_WHATSAPP_NUMBER, message_body)
|
| 595 |
+
|
| 596 |
order_details = {
|
| 597 |
"order_id": order_id,
|
| 598 |
"dish": state.data["dish"],
|
|
|
|
| 601 |
"address": state.data.get("address", "")
|
| 602 |
}
|
| 603 |
asyncio.create_task(notify_management_order(order_details))
|
| 604 |
+
|
| 605 |
email = "customer@example.com"
|
| 606 |
payment_data = create_paystack_payment_link(email, total_price * 100, order_id)
|
| 607 |
dish_name = state.data.get("dish", "")
|