Example #1
0
        /// <summary>Call the POS for Order method</summary>
        /// <param name="request">The request</param>
        public OrderCreatePOSResponse OrderTransaction(OrderCreateRequest request)
        {
            OrderCreatePOSResponse response = new OrderCreatePOSResponse();

            // TODO: call (calls) to POS

            return(response);
        }
Example #2
0
        /// <summary>Call the POS for Order method</summary>
        /// <param name="request">The request</param>
        public OrderCreatePOSResponse OrderTransaction(OrderCreateRequest request)
        {
            OrderCreatePOSResponse response       = new OrderCreatePOSResponse();
            HttpStatusCode         httpStatusCode = response.HttpStatusCode;
            Order order = response.OrderCreateResponse.Order;

            string    responseStr = string.Empty;
            RestCalls restCalls   = new RestCalls();

            //TODO order time is invalid from test need to check if the kiosk
            //does the same thing
            DateTime orderTime    = DateTime.Now;
            string   orderTimeStr = orderTime.ToString("yyMMddHHmmss");

            request.DOTOrder.OrderTime = orderTimeStr;

            string requestStr = JsonConvert.SerializeObject(request.DOTOrder);

            //POST the JSON to the Server and get the response - load the url path
            LoadAPIUrls();
            //responseStr = restCalls.PostAsyncRequest(orderUrl, requestOrderStr);


            //call the APIs in order
            //Checkbasket

            responseStr = restCalls.PostRestSharpRequest();

            //Deserialize the string to an Object
            OrderCreateResponse jsonOrder = JsonConvert.DeserializeObject <OrderCreateResponse>(responseStr);

            //populate Order with the result from the POS
            response.OrderCreateResponse = jsonOrder;


            if (httpStatusCode == HttpStatusCode.Created)
            {
                Log.Info($"HTTP Status Code Created:{httpStatusCode}");
            }
            else
            {
                Log.Error($"HTTP Status Code:{httpStatusCode}");
            }

            return(response);
        }
        public RESTNancyModule()
            : base(ListenerConfig.Instance.POSRESTModuleBase)
        {
            Get["/status/{kiosk?}"] = parameters =>
            {
                // try to get the kiosk parameter
                string kiosk = null;

                try
                {
                    string kioskStr = parameters.kiosk;

                    if (!string.IsNullOrWhiteSpace(kioskStr))
                    {
                        kiosk = kioskStr;
                    }
                }
                catch
                {
                }

                // defines the function for calling GetStatus method
                Func <string, IPOSResponse> func = (bodyStr) =>
                {
                    StatusPOSResponse statusPOSResponse = new StatusPOSResponse();

                    if (string.IsNullOrWhiteSpace(kiosk))
                    {
                        // the kiosk parameter was not specified
                        statusPOSResponse.SetPOSError(Errors.KioskNotSpecified);
                    }
                    else
                    {
                        try
                        {
                            // call the POS and get the status for the specified kiosk
                            statusPOSResponse = GetStatus(kiosk);
                        }
                        catch (Exception ex)
                        {
                            statusPOSResponse = new StatusPOSResponse();
                            statusPOSResponse.SetPOSError(Errors.POSError, ex.Message);
                        }
                    }

                    return(statusPOSResponse);
                };

                // call GetStatus function
                IPOSResponse response = ExecuteRESTCall(func);

                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    return(new TextResponse(response.HttpStatusCode, response.ResponseContent));
                }
                else
                {
                    return(response.HttpStatusCode);
                }
            };

            Post["/order"] = parameters =>
            {
                // defines the function for calling OrderTransaction method
                Func <string, IPOSResponse> func = (bodyStr) =>
                {
                    OrderCreatePOSResponse posResponse = new OrderCreatePOSResponse();
                    Order order = posResponse.OrderCreateResponse.Order;
                    OrderCreateRequest request = null;

                    try
                    {
                        // deserialize request
                        request = JsonConvert.DeserializeObject <OrderCreateRequest>(bodyStr);
                    }
                    catch (Exception ex)
                    {
                        posResponse.SetPOSError(Errors.ErrorDeserializeRequest, ex.Message);
                    }

                    if (!order.HasErrors)
                    {
                        // no deserialize errors => check some elements
                        if (request.DOTOrder == null)
                        {
                            posResponse.SetPOSError(Errors.OrderMissing);
                        }
                        else if (string.IsNullOrWhiteSpace(request.DOTOrder.Kiosk))
                        {
                            posResponse.SetPOSError(Errors.KioskNotSpecified);
                        }
                        else if (string.IsNullOrWhiteSpace(request.DOTOrder.RefInt))
                        {
                            posResponse.SetPOSError(Errors.RefIntNotSpecified);
                        }
                        else if (request.DOTOrder.IsNewOrder && !request.DOTOrder.Items.Any())
                        {
                            posResponse.SetPOSError(Errors.ItemListNotSpecified);
                        }
                        else if (request.DOTOrder.IsTenderOrder &&
                                 ((request.DOTOrder.Tender == null) ||
                                  (request.DOTOrder.Tender.TenderItems == null) ||
                                  !request.DOTOrder.Tender.TenderItems.Any()))
                        {
                            posResponse.SetPOSError(Errors.TenderItemListNotSpecified);
                        }
                        else if (request.DOTOrder.IsExistingOrder && string.IsNullOrWhiteSpace(request.DOTOrder.OrderID))
                        {
                            posResponse.SetPOSError(Errors.OrderIDNotSpecified);
                        }
                    }

                    if (!order.HasErrors)
                    {
                        try
                        {
                            posResponse = OrderTransaction(request);
                        }
                        catch (Exception ex)
                        {
                            posResponse = new OrderCreatePOSResponse();
                            posResponse.SetPOSError(Errors.POSError, ex.Message);
                        }
                    }

                    return(posResponse);
                };

                // call OrderTransaction method
                IPOSResponse response = ExecuteRESTCall(func);

                if (response.HttpStatusCode == HttpStatusCode.Created)
                {
                    return(new TextResponse(response.HttpStatusCode, response.ResponseContent));
                }
                else
                {
                    return(response.HttpStatusCode);
                }
            };

            Get["/testdiag/{culturename?}"] = parameters =>
            {
                // try to get the culture name
                string culturename = null;

                try
                {
                    culturename = parameters.culturename;
                }
                catch
                {
                }

                // defines the function for calling TestDiag method
                Func <string, IPOSResponse> func = (bodyStr) =>
                {
                    TestDiagPOSResponse posResponse = new TestDiagPOSResponse();

                    if (string.IsNullOrWhiteSpace(culturename))
                    {
                        posResponse.SetPOSError(Errors.CultureNameNotSpecified);
                    }
                    else
                    {
                        try
                        {
                            posResponse = TestDiag(culturename);
                        }
                        catch (Exception ex)
                        {
                            posResponse = new TestDiagPOSResponse();
                            posResponse.SetPOSError(Errors.POSError, ex.Message);
                        }
                    }

                    return(posResponse);
                };

                // call TestDiag method
                IPOSResponse response = ExecuteRESTCall(func);

                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    return(new TextResponse(response.HttpStatusCode, response.ResponseContent));
                }
                else
                {
                    return(response.HttpStatusCode);
                }
            };
        }
Example #4
0
 /// <summary>
 /// Get the order request and populate the response and return it after processing the request
 /// </summary>
 /// <param name="orderRequest"></param>
 /// <param name="orderResponse"></param>
 public CallStoredProcs(OrderCreateRequest orderRequest, OrderCreatePOSResponse orderResponse)
 {
     this.request  = orderRequest;
     this.response = orderResponse;
 }
Example #5
0
        /// <summary>Call the POS for Order method</summary>
        /// <param name="request">The request</param>
        public OrderCreatePOSResponse OrderTransaction(OrderCreateRequest request)
        {
            OrderCreatePOSResponse response       = new OrderCreatePOSResponse();
            HttpStatusCode         httpStatusCode = response.HttpStatusCode;
            Order  order       = response.OrderCreateResponse.Order;
            string responseStr = string.Empty;
            string orderNum    = string.Empty;
            int    tax         = 0;
            int    basketId    = 0;

            //copy the TableServiceNumber to the tableNo
            if ((request.DOTOrder.Location == Location.EatIn) && (request.DOTOrder.TableServiceNumber != null))
            {
                request.DOTOrder.tableNo = Convert.ToInt32(request.DOTOrder.TableServiceNumber);
            }

            string requestStr = JsonConvert.SerializeObject(request.DOTOrder);

            /****************************
             * Load the API settings to use
             * ****************************/
            LoadAPIUrls();


            /**************************************************************
             * Functions
             * ***********************************************************/
            if (request.DOTOrder.FunctionNumber == FunctionNumber.PRE_CALCULATE)
            {
                //Do CheckBasket

                CallStoredProcs procs = new CallStoredProcs(request, response);
                response = procs.CheckBasketStoredProcs();

                if (response == null)
                {
                    Log.Error("Error in CheckBasket");
                    return(response);
                }
            }

            if (request.DOTOrder.FunctionNumber == FunctionNumber.EXT_OPEN_ORDER)
            {
                CallStoredProcs procs = new CallStoredProcs(request, response);
                //response = procs.();

                if (response == null)
                {
                    Log.Error("Error in CheckBasket");
                    return(response);
                }
            }


            if (request.DOTOrder.FunctionNumber == FunctionNumber.EXT_COMPLETE_ORDER)
            {
                response.OrderCreateResponse.Order.Kiosk             = request.DOTOrder.Kiosk;
                response.OrderCreateResponse.Order.RefInt            = request.DOTOrder.RefInt;
                response.OrderCreateResponse.Order.OrderID           = request.DOTOrder.OrderID;
                response.OrderCreateResponse.Order.Totals.AmountPaid = Convert.ToInt64(request.DOTOrder.PaidAmount);

                //TODO get the Order number and the tax from the database.
                using (SqlConnection con = new SqlConnection())
                {
                    con.ConnectionString = ConnectionString;
                    con.Open();
                    SqlCommand comm = new SqlCommand($"SELECT ID, APIPosOrderID, APItax from {TableName } where KioskRefInt = {Convert.ToInt32(request.DOTOrder.RefInt)}", con);
                    using (SqlDataReader reader = comm.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            basketId = reader.GetInt32(0);
                            orderNum = Convert.ToString(reader.GetInt32(1));
                            tax      = reader.GetInt32(2);
                        }
                    }

                    if (string.IsNullOrEmpty(orderNum))
                    {
                        Log.Error($"No Order Number returned from the database for Transaction {request.DOTOrder.RefInt}");
                    }
                    else
                    {
                        Log.Info($"Order number = {orderNum} for Transaction {request.DOTOrder.RefInt}");
                    }

                    //close the basket

                    //Console.WriteLine($"Basket for ID: {basketId} = " + ExecuteOrderBasketClose(con, basketId));
                }

                response.OrderCreateResponse.Order.OrderPOSNumber = Convert.ToInt64(orderNum);
            }

            //copy to Order Table Number
            if ((request.DOTOrder.Location == Location.EatIn) && (request.DOTOrder.TableServiceNumber != null))
            {
                response.OrderCreateResponse.Order.tableNo = Convert.ToInt32(request.DOTOrder.TableServiceNumber);
            }


            if (httpStatusCode == HttpStatusCode.Created)
            {
                Log.Info($"HTTP Status Code Created:{httpStatusCode}");
            }
            else
            {
                Log.Error($"HTTP Status Code:{httpStatusCode}");
            }

            return(response);
        }
Example #6
0
 public OrderCreatePOSResponse CheckBasket(OrderCreateRequest orderRequest, OrderCreatePOSResponse orderResponse)
 {
     return(orderResponse);
 }