Esewa integration of Restaurant management
This Django-based food delivery web application includes a basic implementation of payment
functionality using eSewa as the payment method. The user must first log in to access the payment
features. Once logged in, the user can add items to their cart and proceed to place an order. The order is
created by visiting the /place_order/ endpoint, which accepts a POST request containing the selected
payment method—typically "esewa" in this case. Upon submission, the system calculates the total price
of the cart, creates an Order object with a status of "PENDING", and stores this information in the
database. A corresponding Payment object is also created to store the payment method, amount, and a
transaction ID. Once the order is placed, the cart is cleared.
After placing the order, the user is redirected to the order detail page at /order_detail/<order_id>/, where
they can view the summary of their order. To proceed with the payment, the user submits a POST request
to the /make_payment/<order_id>/ endpoint, selecting "esewa" as the payment method. This action
creates a Payment object with the amount equal to the order total. Since this is a simulated environment,
the is_successful field is manually set to True, and a fake transaction ID is generated in the format TXN-
<order_id>-<user_id>. The system then redirects the user to a confirmation page at
/payment/success/<payment_id>/, displaying the payment success message and order details.
Internally, the application uses three main models for this feature: Order, Payment, and Cart (along with
CartItem). The Order model keeps track of user orders, Payment stores the method and transaction
status, and the cart models manage the temporary list of items before an order is finalized. Although the
current implementation simulates a successful eSewa payment, it lays the foundation for real-world
integration. In the future, this system can be expanded by connecting to the official eSewa API, redirecting
users to the eSewa payment gateway and verifying transactions via their provided parameters such as
amt, pid, scd, and txRef.
Overall, this documentation outlines the core logic for placing orders and simulating payments using
eSewa within a Django application, providing a clear path for future enhancements involving real-time
payment verification.