private void HandleGetTablesWithOrders(POSAPIMsg request)
 {
     HandleRequest(request, () => new PATResponse()
     {
         Tables = tablesRepository.GetTablesWithOrders()
     });
 }
Exemple #2
0
        private async Task ProcessRequest()
        {
            do
            {
                _logger.Log("Awaiting message...");
                var r = await eft.ReadResponseAsync();

                if (r == null) // stream is busy
                {
                    _logger.Log("Received null response. Waiting 3 secs...");
                    await Task.Delay(3000); // wait 3 sec?

                    continue;
                }

                _logger.Log($"Message received! {r}");
                if (r is EFTPayAtTableResponse)
                {
                    try
                    {
                        var response = (EFTPayAtTableResponse)r;
                        var msg      = new POSAPIMsg();
                        msg.ParseFromString(response);

                        _logger.Log(new LogData(msg.ToString(), $"RX (Handling message): {msg.ToString()}"));

                        switch (msg.Header.RequestMethod)
                        {
                        case RequestMethod.Settings:
                            if (msg.Header.RequestType == RequestType.GET)
                            {
                                await HandleRequest(msg, () => new PATResponse()
                                {
                                    Settings = _settingsRepository.GetSettings(Data.Options)
                                });
                            }
                            break;

                        case RequestMethod.Tables:
                            if (msg.Header.RequestType == RequestType.GET)
                            {
                                await HandleRequest(msg, () => new PATResponse()
                                {
                                    Tables = _tablesRepository.GetTables()
                                });
                            }
                            break;

                        case RequestMethod.TablesWithOrders:
                            if (msg.Header.RequestType == RequestType.GET)
                            {
                                await HandleRequest(msg, () => new PATResponse()
                                {
                                    Tables = _tablesRepository.GetTablesWithOrders()
                                });
                            }
                            break;

                        case RequestMethod.TableOrders:
                            if (msg.Header.RequestType == RequestType.GET)
                            {
                                await HandleRequest(msg, () => new PATResponse()
                                {
                                    Orders = _ordersRepository.GetOrdersFromTable(msg.Header.TableId)
                                });
                            }
                            break;


                        case RequestMethod.Order:
                            if (msg.Header.RequestType == RequestType.GET)
                            {
                                await HandleRequest(msg, () => new PATResponse()
                                {
                                    Order = _ordersRepository.GetOrder(msg.Header.OrderId)
                                });
                            }
                            break;

                        case RequestMethod.OrderReceipt:
                            if (msg.Header.RequestType == RequestType.GET)
                            {
                                await HandleRequest(msg, () => new PATResponse()
                                {
                                    Receipt = _ordersRepository.GetCustomerReceiptFromOrderId(msg.Header.OrderId, msg.Header.ReceiptOptionId)
                                });
                            }
                            break;

                        case RequestMethod.Tender:
                            if (msg.Header.RequestType == RequestType.POST)
                            {
                                await HandleCreateTender(msg);
                            }
                            else if (msg.Header.RequestType == RequestType.PUT)
                            {
                                await HandleUpdateTender(msg);
                            }
                            break;

                        case RequestMethod.EFTPOSCommand:
                            if (msg.Header.RequestType == RequestType.POST)     //looks like there are 3 of them to handle
                            {
                                await HandleEFTPOSCommand(msg);
                            }
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Log(ex.Message, LogType.ERROR);
                    }
                }
                else if (r is EFTStatusResponse)
                {
                    var response = (EFTStatusResponse)r;
                    _logger.Log($"Status response. {response.ResponseCode} {response.ResponseText}", (response.Success ? LogType.INFO : LogType.ERROR));
                    _logger.Log($"Pinpad online: {response.Success}");
                }
            }while (true);
        }