Exemplo n.º 1
0
 /// <summary>
 /// Validates that the given order is complete. Throws an exception if it's not
 /// </summary>
 /// <param name="order"></param>
 void ValidateOrderComplete(Order order)
 {
     var uri = String.Format("{0}/api/orders/{1}?key={2}", BaseUri, order.Id, ApiKey);
     var r = JsonConvert.DeserializeObject<PATResponse>(GetJsonString(uri, DebugTrace));
     if (r.Order == null)
         throw new Exception("No order");
     if (r.Order.AmountOwing != 0)
         throw new Exception("Order amount <> 0");
     if (r.Order.OrderState != OrderState.Complete)
         throw new Exception("Order state <> complete");
 }
Exemplo n.º 2
0
 /// <summary>
 /// Updates tender as complete. Throws an exception if data is invalid
 /// </summary>
 /// <param name="tender"></param>
 /// <param name="order"></param>
 void UpdateTender(ref Tender tender, Order order)
 {
     var uri = String.Format("{0}/api/tenders/{1}?key={2}", BaseUri, tender.Id, ApiKey);
     tender.TenderState = TenderState.CompleteSuccessful;
     var r = JsonConvert.DeserializeObject<PATResponse>(PutJsonString(uri, JsonConvert.SerializeObject(new PATRequest() { Tender = tender }), DebugTrace));
     if (r.Tender == null)
         throw new Exception("No tender in PUT response");
     // Update our tender with the details from the response
     tender = r.Tender;
     Console.WriteLine("Tender updated");
 }
Exemplo n.º 3
0
 /// <summary>
 /// Get first available order from tables, throws an exception if data is invalid
 /// </summary>
 /// <param name="tables"></param>
 /// <param name="order"></param>
 /// <param name="table"></param>
 void GetFirstOrderFromTables(List<Table> tables, ref Order order, ref Table table)
 {
     // Loop through tables until we find an order
     foreach (var t in tables)
     {
         var uri = String.Format("{0}/api/tables/{1}/orders?key={2}", BaseUri, t.Id, ApiKey);
         var r = JsonConvert.DeserializeObject<PATResponse>(GetJsonString(uri, DebugTrace));
         if (r.Orders != null && r.Orders.Count() > 0)
         {
             order = r.Orders.First();
             table = t;
             break;
         }
     }
     // Check if we have an order
     if (order == null)
         throw new Exception("Order == null");
     Console.WriteLine("Order {0} found on Table {1}", order.DisplayName, table.DisplayName);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Get default receipt, throws an exception if data is invalid
 /// </summary>
 /// <param name="order"></param>
 /// <param name="receiptOption"></param>
 void GetReceipt(Order order, ReceiptOption receiptOption)
 {
     var uri = String.Format("{0}/api/orders/{1}/receipt?key={2}", BaseUri, order.Id, ApiKey);
     var r = JsonConvert.DeserializeObject<PATResponse>(GetJsonString(uri, DebugTrace));
     if (r.Receipt == null || r.Receipt.Lines == null || r.Receipt.Lines.Count == 0)
         throw new Exception("No receipt");
     foreach (var l in r.Receipt.Lines)
         Console.WriteLine(l);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Create a tender, throws an exception if data is invalid
 /// </summary>
 /// <param name="tender"></param>
 /// <param name="tenderOption"></param>
 void CreateTender(ref Tender tender, TenderOption tenderOption, Order order)
 {
     tender = new Tender() { AmountPurchase = order.AmountOwing, OriginalAmountPurchase = order.AmountOwing, TenderState = TenderState.Pending, OrderId = order.Id };
     var uri = String.Format("{0}/api/tenders?key={1}", BaseUri, ApiKey);
     var r = JsonConvert.DeserializeObject<PATResponse>(PostJsonString(uri, JsonConvert.SerializeObject(new PATRequest() { Tender = tender }), DebugTrace));
     if (r.Tender == null)
         throw new Exception("No tender in POST response");
     // Update our tender with the details from the response
     tender = r.Tender;
     Console.WriteLine("Tender created");
 }