protected void PostDisplayEvent(string uri, bool delayEftposCommands, bool debugTrace, string tenderId, string originalEftposCommandId, string dataField, string csdReservedString1, string csdReservedString5) { var eftposEventCommand = new EftposCommand() { EftposCommandType = EftposCommandType.DisplayEvent, TenderId = tenderId, OriginalEftposCommandId = originalEftposCommandId, DataField = dataField, CsdReservedString1 = csdReservedString1, CsdReservedString5 = csdReservedString5 }; var r = JsonConvert.DeserializeObject <PatResponse>(PostJsonString(uri, JsonConvert.SerializeObject(new PatRequest() { EftposCommand = eftposEventCommand }), debugTrace)); if (r.EftposCommand == null) { throw new Exception("No EftposCommand in POST response"); } if (delayEftposCommands) { System.Threading.Thread.Sleep(1000); } }
public void Run() { //PatResponse r = null; List <Table> tables = null; Order order = null; Table table = null; Tender tender = null; Settings settings = null; string uri = null; EftposCommand eftposRequestCommand = null, eftposEventCommand = null; string EftposCommandId = string.Empty; // Get our settings GetSettings(ref settings); // Get tables GetTables(ref tables); // Find the first available order GetFirstOrderFromTables(tables, ref order, ref table); // Grab a receipt for this order if (settings.ReceiptOptions != null && settings.ReceiptOptions.Count > 0) { GetReceipt(order, settings.ReceiptOptions[0]); } // Create a tender (we can't continue without a default tender option) if (settings.TenderOptions == null || settings.TenderOptions.Count == 0) { throw new Exception("Can't continue without a tender option"); } CreateTender(ref tender, settings.TenderOptions[0], order); // Send our txn request EFTPOS command\ CreateEFTPOSRequest(ref eftposRequestCommand, tender); EftposCommandId = eftposRequestCommand.Id; // Send some display events uri = String.Format("{0}/api/eftpos/commands?key={1}", BaseUri, ApiKey); PostDisplayEvent(uri, DelayEftposCommands, DebugTrace, tender.Id, eftposRequestCommand.Id, " SWIPE CARD ", "100000003", "0"); PostDisplayEvent(uri, DelayEftposCommands, DebugTrace, tender.Id, eftposRequestCommand.Id, " SELECT ACCOUNT ", "100000004", "0"); PostDisplayEvent(uri, DelayEftposCommands, DebugTrace, tender.Id, eftposRequestCommand.Id, " ENTER PIN ", "100000005", "0"); PostDisplayEvent(uri, DelayEftposCommands, DebugTrace, tender.Id, eftposRequestCommand.Id, " PROCESSING PLEASE WAIT ", "000000000", "0"); PostDisplayEvent(uri, DelayEftposCommands, DebugTrace, tender.Id, eftposRequestCommand.Id, " TRANSACTION APPROVED ", "100000005", "0"); // Send the transaction event CreateEFTPOSEvent(ref eftposEventCommand, eftposRequestCommand, tender); // Update the tender UpdateTender(ref tender, order); // Check the order details. It should be complete. ValidateOrderComplete(order); Console.WriteLine("Complete"); }
/// <summary> /// Create a "TransactionEvent" EFTPOS command, throws an exception if data is invalid /// </summary> /// <param name="eftposEventCommand"></param> /// <param name="eftposRequestCommand"></param> /// <param name="tender"></param> void CreateEFTPOSEvent(ref EftposCommand eftposEventCommand, EftposCommand eftposRequestCommand, Tender tender) { var uri = String.Format("{0}/api/eftpos/commands?key={1}", BaseUri, ApiKey); eftposEventCommand = new EftposCommand() { EftposCommandType = EftposCommandType.TransactionEvent, TenderId = tender.Id, OriginalEftposCommandId = eftposRequestCommand.Id, AmtPurchase = eftposRequestCommand.AmtPurchase, TxnType = "P", STAN = "26", ResponseType = "210", Caid = "000008156005003", Catid = "00000000", Date = "000000", Time = "000000", ResponseCode = "00", ResponseText = "APPROVED", Merchant = "0", Success = true, AccountType = "Credit", CardType = "DEBIT CARD AC", CardName = "00", TxnRef = eftposRequestCommand.TxnRef, DateSettlement = "000000", AuthCode = "000023", CsdReservedBool1 = false, Rrn = "000000000023", Track2 = "4343000000000005=0101?", Pan = "4343000000000005" }; var r = JsonConvert.DeserializeObject <PatResponse>(PostJsonString(uri, JsonConvert.SerializeObject(new PatRequest() { EftposCommand = eftposEventCommand }), DebugTrace)); if (r.EftposCommand == null) { throw new Exception("No EftposCommand in POST response"); } Console.WriteLine("TransactionEvent EftposCommand Created"); }
/// <summary> /// Create a "DoTransaction" EFTPOS command, throws an exception if data is invalid /// </summary> /// <param name="eftposRequestCommand"></param> /// <param name="tender"></param> void CreateEFTPOSRequest(ref EftposCommand eftposRequestCommand, Tender tender) { var uri = String.Format("{0}/api/eftpos/commands?key={1}", BaseUri, ApiKey); eftposRequestCommand = new EftposCommand() { EftposCommandType = EftposCommandType.DoTransaction, TenderId = tender.Id, AmtPurchase = tender.AmountPurchase, TxnType = "P", TxnRef = String.Format("{0:yyddMMHHmmsszzz}", DateTime.Now) }; var r = JsonConvert.DeserializeObject <PatResponse>(PostJsonString(uri, JsonConvert.SerializeObject(new PatRequest() { EftposCommand = eftposRequestCommand }), DebugTrace)); if (r.EftposCommand == null) { throw new Exception("No EftposCommand in POST response"); } Console.WriteLine("DoTransaction EftposCommand Created"); }