Create Order
there is two ways to create orders, authenticated customers & unauthenticated customers.
NOTE: the each time a method or an endpoint is mentioned the github link of the think that mentioned is included.
Unauthenticated Customers
this is a simple way, send all order details to this one endpoint to create a new order.
the endpoint validates the data sent and creates a new order.
Authenticated Customers
for an authenticated user, he had to make a cart first, the cart is stored as an order object but with the status Cart.
which means the checkout endpoint is validating the cart, and then changing the status of the order to New.
there are two ways this method could process the order, with online payment or cash on delivery.
Cash on Delivery
this is the original way to handle the order request, the client should define its a cash on delivery request.
when the request first hits the endpoint, the endpoint will do few checks before passing it to be handled as a Cash On Delivery checkout.
this way the endpoint will be handled by HandleCheckoutAsync.
this method will send it to OrderService.CheckoutAsync, which will do few validations, and then get the prices of items and prepare the order to change the status to New.
then calculates the total of the order, and calculate promo codes and update the order entity, and return the order response to the origial method.
in HandleCheckoutAsync after the response comes in
will record the order checked-out event and notify the business of the new order and saves the database, and return to the original endpoint method. which will return the response to the client.

Online Payment
in this way also will be the validation at the start of the request, but sense the user defined it as an online payment, the endpoint will not change the status of the order to be New until the payment is complete, so it will send it to HandleChangeCartToOrderEPaymentAsync
this method will check if the user has online payment subscription. and do few checks before checking the type of the online payment.
there are two types currently ZainCash and Switch each has seperate endpoints to handle preparing and paying.
for ZainCash see
for Switch see
after preparing the endpoints and details to be sent back for the client to handle the payment.
the method will call OrderService.PrepareCartForOnlinePaymentAsync.
this endpoint will do exactly what OrderService.CheckoutAsync but
without changing the status of the order to New and keep it as Cart.
it will validate address, inventory, prices, prepare the order, and validate shipping details, and validate total price and count in the promo codes. and update the order.
and then return to the original method. which will return to the endpoint method, that will validate if the process is success or not and return the details to preceed to the online payment or an error.
order process with online payment:
