public PrintReceipt ( Context context, long invoiceNumber, int splitCheckNumber ) : bool | ||
context | Context | The store id, station id, and cashier id the information should be restricted to. |
invoiceNumber | long | The number of the invoice that should be printed |
splitCheckNumber | int | The split check number, 0-based. Provide -1 if there are no split checks. |
Результат | bool |
static void TestSales() { try { SalesAPI api = new SalesAPI(); DateTime startDateTime = DateTime.Parse("1/1/2010"); DateTime endDateTime = DateTime.Parse("12/31/2010"); SalesTotals totals = api.GetTotals(startDateTime, endDateTime); Console.WriteLine( String.Format("Sales totals between {0}-{1} -- NetSales:{2} TotalTax:{3} GrandTotal:{4}", startDateTime, endDateTime, totals.NetSales, totals.TotalTax, totals.GrandTotal)); List<ItemSale> sales = api.GetItemsSold(startDateTime, endDateTime); Console.WriteLine(String.Format("Between {0}-{1}, there are {2} records of items being sold", startDateTime, endDateTime, sales.Count)); pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context(); context.CashierID = "100101"; context.StoreID = "1001"; context.StationID = "01"; // StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal Invoice inv = api.StartNewInvoice(context, "ROB" + DateTime.Now.Second.ToString(), "XXOPEN TABS"); Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber)); // Unlock Invoice if (api.UnLockInvoice(context, inv.InvoiceNumber)) Console.WriteLine(String.Format("Unlocked invoice # {0}", inv.InvoiceNumber)); else Console.WriteLine(String.Format("Failed to unlock invoice # {0}", inv.InvoiceNumber)); // Lock Invoice if (api.LockInvoice(context, inv.InvoiceNumber)) Console.WriteLine(String.Format("Locked invoice # {0}", inv.InvoiceNumber)); else Console.WriteLine(String.Format("Failed to lock invoice # {0}", inv.InvoiceNumber)); // GetInvoiceHeader inv = api.GetInvoiceHeader(context, inv.InvoiceNumber); Console.WriteLine(String.Format("GetInvoiceHeader with #: {0}", inv.InvoiceNumber)); // GetInvoice inv = api.GetInvoice(context, inv.InvoiceNumber); Console.WriteLine(String.Format("GetInvoice with #: {0}", inv.InvoiceNumber)); // ModifyItems inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "Non Inventory", ItemNumber = "Non_Inventory", Price = 1, Quantity = 1, State = EntityState.Added }); inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "Non Inventory", ItemNumber = "Non_Inventory", Price = 2, Quantity = 1, State = EntityState.Added }); inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "Non Inventory", ItemNumber = "Non_Inventory", Price = 3, Quantity = 1, State = EntityState.Added, ParentId = inv.LineItems[1].Id }); inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems); Console.WriteLine(String.Format("ModifyItems new invoice value: {0}", inv.GrandTotal)); inv.LineItems[0].State = EntityState.Deleted; inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems); Console.WriteLine(String.Format("ModifyItems DELETED 1st item, new invoice value: {0}", inv.GrandTotal)); inv.LineItems[0].Quantity = 2; inv.LineItems[0].State = EntityState.Modified; inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems); Console.WriteLine(String.Format("ModifyItems CHANGED 1st item QUANTITY, new invoice value: {0}", inv.GrandTotal)); inv.LineItems.Add(new LineItem() { ItemNumber = "Non_Inventory", ItemName = "Hot dog", Price = 1, Quantity = 1, State = EntityState.Added }); inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems); Console.WriteLine(String.Format("ModifyItems ADDED item # 1, new invoice value: {0}", inv.GrandTotal)); // SendToKitchen if (api.SendToKitchen(context, inv.InvoiceNumber)) Console.WriteLine("Invoice was printed in kitchen"); else Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen"); if (api.SendToKitchen(context, inv.InvoiceNumber)) Console.WriteLine( "Invoice was printed in kitchen, it should not have printed anything out the 2nd time"); else Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen"); // Splitcheck inv = api.SplitInvoice(context, inv.InvoiceNumber, 2); if (inv.SplitInfo.NumberOfSplitChecks == 2) Console.WriteLine("Split invoice 2 ways"); else Console.WriteLine("***ERROR*** Invoice could be split"); // CombineSplits inv = api.CombineSplits(context, inv.InvoiceNumber); if (inv.SplitInfo.NumberOfSplitChecks == 0) Console.WriteLine("Combined split checks"); else Console.WriteLine("***ERROR*** Invoice could be split"); // GetAllOnHoldInvoices List<OnHoldInfo> onHoldInfos = api.GetAllOnHoldInvoices(context); if (onHoldInfos == null) Console.WriteLine("***ERROR*** Could not retrieve GetAllOnHoldInvoices"); else { Console.WriteLine(String.Format("Retrieved {0} OnHoldInfo from GetAllOnHoldInvoices", onHoldInfos.Count)); foreach (OnHoldInfo onHoldInfo in onHoldInfos) { if (onHoldInfo.Locked == true) { Console.WriteLine(String.Format("Invoice {0} is locked by Station {1}", onHoldInfo.InvoiceNumber, onHoldInfo.LockedByStation)); } } } // GetOnHoldInvoicesForCashier onHoldInfos = api.GetOnHoldInvoicesForCashier(context); if (onHoldInfos == null) Console.WriteLine("***ERROR*** Could not retrieve GetOnHoldInvoicesForCashier"); else { Console.WriteLine(String.Format("Retrieved {0} OnHoldInfo from GetOnHoldInvoicesForCashier", onHoldInfos.Count)); foreach (OnHoldInfo onHoldInfo in onHoldInfos) { if (onHoldInfo.Locked == true) { Console.WriteLine(String.Format("Invoice {0} is locked by Station {1}", onHoldInfo.InvoiceNumber, onHoldInfo.LockedByStation)); } } } // ApplyCashPayment - applying grand total minus 1 dollar AppliedPaymentResponse payResponse = api.ApplyCashPayment(context, inv.InvoiceNumber, -1, inv.GrandTotal - 1); if (payResponse.Success) Console.WriteLine(String.Format("Applied cash payment, change due {0}", payResponse.ChangeAmount)); else Console.WriteLine("***ERROR*** Could not apply payment"); // ApplyCardPayment - applying remaining 1 dollar as a credit card payResponse = api.ApplyCardPayment(context, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = 1, CardNumber = "4***********1", ReferenceNumber = "123456", Result = true, TipAmount = 1, TransactionNumber = 1234 }, -1); if (payResponse.Success) Console.WriteLine(String.Format("Applied card payment, change due {0}", payResponse.ChangeAmount)); else Console.WriteLine("***ERROR*** Could not apply card payment"); // EndInvoice if (api.EndInvoice(context, inv.InvoiceNumber)) Console.WriteLine("Ended invoice successfully"); else Console.WriteLine("***ERROR*** Could not end invoice"); // PrintReceipt - providing -1 for the split check # when there are no split checks if (api.PrintReceipt(context, inv.InvoiceNumber, -1)) Console.WriteLine("Receipt was printed"); else Console.WriteLine("***ERROR*** Receive was NOT printed"); // EmailReceipt - providing -1 for the split check # when there are no split checks if (api.EmailReceipt(context, inv.InvoiceNumber, -1, "*****@*****.**")) Console.WriteLine("Receipt was emailed"); else Console.WriteLine("***ERROR*** Receipt was NOT emailed"); } catch (Exception ex) { Console.WriteLine(ex); } finally { Console.WriteLine("PRESS ENTER TO CONTINUE..."); Console.ReadLine(); } }
static void deleteItemsTest() { try { SalesAPI api = new SalesAPI(); pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context(); context.CashierID = "100101"; context.StoreID = "1001"; context.StationID = "01"; // StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal Invoice inv = api.StartNewInvoice(context, "ROB" + DateTime.Now.Ticks.ToString(), "XXOPEN TABS"); Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber)); // Unlock Invoice /*if (api.UnLockInvoice(context, inv.InvoiceNumber)) Console.WriteLine(String.Format("Unlocked invoice # {0}", inv.InvoiceNumber)); else Console.WriteLine(String.Format("Failed to unlock invoice # {0}", inv.InvoiceNumber));*/ // Lock Invoice if (api.LockInvoice(context, inv.InvoiceNumber)) Console.WriteLine(String.Format("Locked invoice # {0}", inv.InvoiceNumber)); else Console.WriteLine(String.Format("Failed to lock invoice # {0}", inv.InvoiceNumber)); // GetInvoiceHeader inv = api.GetInvoiceHeader(context, inv.InvoiceNumber); Console.WriteLine(String.Format("GetInvoiceHeader with #: {0}", inv.InvoiceNumber)); // GetInvoice inv = api.GetInvoice(context, inv.InvoiceNumber); Console.WriteLine(String.Format("GetInvoice with #: {0}", inv.InvoiceNumber)); InventoryAPI InvApi = new InventoryAPI(); pcAmerica.DesktopPOS.API.Client.InventoryService.Context InvContext = new pcAmerica.DesktopPOS.API.Client.InventoryService.Context(); InvContext.CashierID = "100101"; InvContext.StationID = "01"; InvContext.StoreID = "1001"; Guid parentGuid = new Guid(); // ModifyItems inv.LineItems.Add(new LineItem() { Id = parentGuid, ItemName = "BURGER", ItemNumber = "SAND1", Price = 1.99M, Quantity = 2, State = EntityState.Added }); inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "Add Tomato", ItemNumber = "SANDMod3", Price = 0.10M, Quantity = 1, State = EntityState.Added, ParentId = parentGuid }); inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "BURGER", ItemNumber = "SAND1", Price = 1.99M, Quantity = 1, State = EntityState.Added }); api.UnLockInvoice(context, inv.InvoiceNumber); api.LockInvoice(context, inv.InvoiceNumber); inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems); Invoice inv2 = api.GetInvoice(context, inv.InvoiceNumber); Console.WriteLine(String.Format("ModifyItems new invoice value: {0}", inv2.GrandTotal)); //inv2.LineItems[0].State = EntityState.Deleted; //inv2.LineItems[1].State = EntityState.Deleted; inv2 = api.ModifyItems(context, inv2.InvoiceNumber, inv2.LineItems); Console.WriteLine(String.Format("ModifyItems new invoice value after deleting burger with tomato: {0}", inv2.GrandTotal)); api.LockInvoice(context, inv2.InvoiceNumber); // ApplyCashPayment - applying grand total minus 1 dollar AppliedPaymentResponse payResponse = api.ApplyCashPayment(context, inv2.InvoiceNumber, -1, inv2.GrandTotal); if (payResponse.Success) Console.WriteLine(String.Format("Applied cash payment, change due {0}", payResponse.ChangeAmount)); else Console.WriteLine("***ERROR*** Could not apply payment"); // EndInvoice if (api.EndInvoice(context, inv2.InvoiceNumber)) Console.WriteLine("Ended invoice successfully"); else Console.WriteLine("***ERROR*** Could not end invoice"); // PrintReceipt - providing -1 for the split check # when there are no split checks if (api.PrintReceipt(context, inv2.InvoiceNumber, -1)) Console.WriteLine("Receipt was printed"); else Console.WriteLine("***ERROR*** Receive was NOT printed"); } catch (Exception ex) { Console.WriteLine(ex); } finally { Console.WriteLine("PRESS ENTER TO CONTINUE..."); Console.ReadLine(); } }
// more examples to work specificly with the sample database Burger Express that comes bundled with Resturant Pro Express // shows getting list of all inventory items, adding items two different ways, selecting a modifier for an item and splitting a check by guest static void TestBurgerExpress() { try { SalesAPI api = new SalesAPI(); DateTime startDateTime = DateTime.Parse("1/1/2010"); DateTime endDateTime = DateTime.Parse("12/31/2010"); SalesTotals totals = api.GetTotals(startDateTime, endDateTime); Console.WriteLine(String.Format("Sales totals between {0}-{1} -- NetSales:{2} TotalTax:{3} GrandTotal:{4}", startDateTime, endDateTime, totals.NetSales, totals.TotalTax, totals.GrandTotal)); List<ItemSale> sales = api.GetItemsSold(startDateTime, endDateTime); Console.WriteLine(String.Format("Between {0}-{1}, there are {2} records of items being sold", startDateTime, endDateTime, sales.Count)); pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context(); context.CashierID = "100101"; context.StoreID = "1001"; context.StationID = "01"; // StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal Invoice inv = api.StartNewInvoice(context, "Dan" + DateTime.Now.Second.ToString(), "XXOPEN TABS"); Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber)); // Unlock Invoice if (api.UnLockInvoice(context, inv.InvoiceNumber)) Console.WriteLine(String.Format("Unlocked invoice # {0}", inv.InvoiceNumber)); else Console.WriteLine(String.Format("Failed to unlock invoice # {0}", inv.InvoiceNumber)); // Lock Invoice if (api.LockInvoice(context, inv.InvoiceNumber)) Console.WriteLine(String.Format("Locked invoice # {0}", inv.InvoiceNumber)); else Console.WriteLine(String.Format("Failed to lock invoice # {0}", inv.InvoiceNumber)); // GetInvoiceHeader inv = api.GetInvoiceHeader(context, inv.InvoiceNumber); Console.WriteLine(String.Format("GetInvoiceHeader with #: {0}", inv.InvoiceNumber)); // GetInvoice inv = api.GetInvoice(context, inv.InvoiceNumber); Console.WriteLine(String.Format("GetInvoice with #: {0}", inv.InvoiceNumber)); InventoryAPI InvApi = new InventoryAPI(); pcAmerica.DesktopPOS.API.Client.InventoryService.Context InvContext = new pcAmerica.DesktopPOS.API.Client.InventoryService.Context(); InvContext.CashierID = "100101"; InvContext.StationID = "01"; InvContext.StoreID = "1001"; api.SetPartySizeForInvoice(context, inv.InvoiceNumber, 2); List<InventoryItem> items = InvApi.GetItemListExtended(InvContext); Console.WriteLine("*******************All Inventory Items************************"); foreach (InventoryItem singleItem in items) { Console.WriteLine(String.Format("Item#: {0} ItemName:{1}", singleItem.ItemNumber, singleItem.ItemName)); } Console.WriteLine("***************************************************************"); // ModifyItems inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" }); InventoryItem itemToAdd = InvApi.GetItem(InvContext, "SALAD3"); Guid itemToAddID = Guid.NewGuid(); LineItem LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" }; inv.LineItems.Add(LineItemToAdd); itemToAdd.ModifierGroups = InvApi.GetModiferGroupsForItem(InvContext, itemToAdd.ItemNumber); foreach (ModifierGroup ModGroup in itemToAdd.ModifierGroups) { Console.WriteLine("ModifierGroup:{0}", ModGroup.ItemName); Console.WriteLine("{0}", ModGroup.Prompt); int i = 1; if (ModGroup.Forced == false) { Console.WriteLine("{0} - NONE", i); i++; } //NOTE THIS HAS CHANGED Modifier Items for Groups now are retrieved by calling GetModiferItemsForModiferGroups ModGroup.ModifierItems = InvApi.GetModifierItemsForModifierGroup(InvContext, ModGroup.ItemNumber); foreach (ModifierItem ModItem in ModGroup.ModifierItems) { Console.WriteLine("{0} - {1} : {2}", i, ModItem.ItemNumber, ModItem.ItemName); i++; } string answer = Console.ReadLine(); if (answer.Length > 1) { Console.WriteLine("Invalid answer i Choose option 1 is chosen by default"); answer = "1"; } else if (char.IsDigit(answer[0]) == false) { Console.WriteLine("Invalid answer i Choose option 1 chosen by defualt"); answer = "1"; } InventoryItem dressing = InvApi.GetItem(InvContext, ModGroup.ModifierItems[Convert.ToInt32(answer) - 1].ItemNumber); decimal Price = 0; if (ModGroup.Charged == true) { Price = dressing.Price; } inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = dressing.ItemName, ItemNumber = dressing.ItemNumber, Price = dressing.Price, Quantity = 1, State = EntityState.Added, Guest = "2" }); } itemToAdd = InvApi.GetItem(InvContext, "DaveBurger"); itemToAddID = Guid.NewGuid(); LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" }; inv.LineItems.Add(LineItemToAdd); itemToAdd.ModifierItems = InvApi.GetIndividualModifiers(InvContext, itemToAdd.ItemNumber); if (itemToAdd.ModifierItems.Count > 0) inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = itemToAdd.ModifierItems[0].ItemName, ItemNumber = itemToAdd.ModifierItems[0].ItemNumber, Price = 0.00M, Quantity = 1, State = EntityState.Added, Guest = "1" }); // This is a sample Kit Item I made that i added some items to you just have to ring up the base item(test) and the kit items will add along with it automaticly itemToAdd = InvApi.GetItem(InvContext, "test"); itemToAddID = Guid.NewGuid(); LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" }; inv.LineItems.Add(LineItemToAdd); itemToAdd = InvApi.GetItem(InvContext, "test"); itemToAddID = Guid.NewGuid(); LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" }; inv.LineItems.Add(LineItemToAdd); itemToAdd = InvApi.GetItem(InvContext, "DRINKCHOICE"); int j = 1; Console.WriteLine(itemToAdd.ItemName2); InventoryItem Choice; foreach (String choiceItemNumber in itemToAdd.ChoiceItems) { Choice = InvApi.GetItem(InvContext, choiceItemNumber); Console.WriteLine(string.Format("{0}: ", Choice.ItemName)); j++; } int choiceItemSelection = Convert.ToInt32(Console.ReadLine()) - 1; itemToAdd = InvApi.GetItem(InvContext, itemToAdd.ChoiceItems[choiceItemSelection]); itemToAddID = Guid.NewGuid(); LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "1" }; inv.LineItems.Add(LineItemToAdd); inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems); Console.WriteLine(String.Format("ModifyItems new invoice value: {0}", inv.GrandTotal)); inv.LineItems[0].Quantity = 2; inv.LineItems[0].State = EntityState.Modified; inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems); Console.WriteLine(String.Format("ModifyItems CHANGED 1st item QUANTITY, new invoice value: {0}", inv.GrandTotal)); // SendToKitchen if (api.SendToKitchen(context, inv.InvoiceNumber)) Console.WriteLine("Invoice was printed in kitchen"); else Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen"); // Splitcheck inv = api.SplitInvoiceByGuest(context, inv.InvoiceNumber); if (inv.SplitInfo.NumberOfSplitChecks == 2) Console.WriteLine("Split invoice by guest"); else Console.WriteLine("***ERROR*** Invoice could be split"); // ApplyCashPayment - applying grand total minus 1 dollar (NOTE SPLITS Starts counting at 0 not 1) AppliedPaymentResponse payResponse = api.ApplyCashPayment(context, inv.InvoiceNumber, 0, inv.SplitInfo.GrandTotalForSplit[0] - 1); if (payResponse.Success) Console.WriteLine(String.Format("Applied cash payment to split 1, change due {0}", payResponse.ChangeAmount)); else Console.WriteLine("***ERROR*** Could not apply payment"); // ApplyCardPayment - applying remaining 1 dollar as a credit card payResponse = api.ApplyCardPayment(context, inv.InvoiceNumber, 0, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = 1, CardNumber = "4***********1", ReferenceNumber = "123456", Result = true, TipAmount = 1, TransactionNumber = 1234 }, -1); if (payResponse.Success) Console.WriteLine(String.Format("Applied card payment to split 1, change due {0}", payResponse.ChangeAmount)); else Console.WriteLine("***ERROR*** Could not apply card payment"); payResponse = api.ApplyCashPayment(context, inv.InvoiceNumber, 1, inv.SplitInfo.GrandTotalForSplit[1] + 13); if (payResponse.Success) Console.WriteLine(String.Format("Applied cash payment to split 2, change due {0}", payResponse.ChangeAmount)); else Console.WriteLine("***ERROR*** Could not apply payment"); // EndInvoice if (api.EndInvoice(context, inv.InvoiceNumber)) Console.WriteLine("Ended invoice successfully"); else Console.WriteLine("***ERROR*** Could not end invoice"); // looping and printing receipt for all splits for (int i = 0; i < inv.SplitInfo.NumberOfSplitChecks; i++) { if (api.PrintReceipt(context, inv.InvoiceNumber, i)) Console.WriteLine("Receipt was printed"); else Console.WriteLine("***ERROR*** Receive was NOT printed"); } } catch (Exception ex) { Console.WriteLine(ex); } finally { Console.WriteLine("PRESS ENTER TO CONTINUE..."); Console.ReadLine(); } }
static void TestPreAuthInvoice() { try { SalesAPI salesAPI = new SalesAPI(); pcAmerica.DesktopPOS.API.Client.SalesService.Context salesContext = new pcAmerica.DesktopPOS.API.Client.SalesService.Context(); salesContext.CashierID = "100101"; salesContext.StoreID = "1001"; salesContext.StationID = "01"; PaymentAPI paymentAPI = new PaymentAPI(); // first create the credit card object pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest creditCard1 = new pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest(); creditCard1.Amount = 5.00M; creditCard1.CardNumber = "5454545454545454"; creditCard1.ExpirationMonth = 05; creditCard1.ExpirationYear = 13; creditCard1.BarTab = true;// set this for a pre authed bar tab creditCard1.ProcessingType = pcAmerica.DesktopPOS.API.Client.PaymentService.ProcessingType.PreAuth; pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardPaymentProcessingResponse ProcessingResponse1 = paymentAPI.ProcessCreditCard(creditCard1); // create an invoice to apply your payment to Invoice inv = salesAPI.StartNewInvoice(salesContext, "Jane", "XXOPEN TABS"); // use paymentIndex of -1 since the card isn't attached to the invoice yet AppliedPaymentResponse paymentResponse1 = salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse1.Amount, ApprovalCode = ProcessingResponse1.ApprovalCode, CardNumber = ProcessingResponse1.CardNumber, ExpirationMonth = ProcessingResponse1.ExpirationMonth, ExpirationYear = ProcessingResponse1.ExpirationYear, ExtensionData = ProcessingResponse1.ExtensionData, IsPrePaidCard = ProcessingResponse1.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse1.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PreAuth, ReferenceNumber = ProcessingResponse1.ReferenceNumber, Result = ProcessingResponse1.Result, TipAmount = ProcessingResponse1.TipAmount, TransactionNumber = ProcessingResponse1.TransactionNumber }, -1); // some time passes and items are added to the invoice InventoryAPI invAPI = new InventoryAPI(); pcAmerica.DesktopPOS.API.Client.InventoryService.Context invContext = new pcAmerica.DesktopPOS.API.Client.InventoryService.Context(); invContext.CashierID = "100101"; invContext.StationID = "01"; invContext.StoreID = "1001"; salesAPI.LockInvoice(salesContext, inv.InvoiceNumber); inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" }); inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "2" }); inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "3" }); inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "4" }); inv = salesAPI.ModifyItems(salesContext, inv.InvoiceNumber, inv.LineItems); //to complete the earlier pre auth card you must call CompletePreAuth and pass it the PaymentIndex you got back from ApplyCardPayment earlier creditCard1.Amount = inv.GrandTotal - 7.98M; creditCard1.ProcessingType = pcAmerica.DesktopPOS.API.Client.PaymentService.ProcessingType.PostAuth; creditCard1.PostAuthReferenceNumber = ProcessingResponse1.PostAuthReferenceNumber; creditCard1.ReferenceNumber = ProcessingResponse1.ReferenceNumber; creditCard1.PaymentIndex = paymentResponse1.PaymentIndex; ProcessingResponse1 = paymentAPI.CompletePreAuth(creditCard1, inv.InvoiceNumber); paymentResponse1 = salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse1.Amount, ApprovalCode = ProcessingResponse1.ApprovalCode, CardNumber = ProcessingResponse1.CardNumber, ExpirationMonth = ProcessingResponse1.ExpirationMonth, ExpirationYear = ProcessingResponse1.ExpirationYear, ExtensionData = ProcessingResponse1.ExtensionData, IsPrePaidCard = ProcessingResponse1.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse1.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PostAuth, ReferenceNumber = ProcessingResponse1.ReferenceNumber, Result = ProcessingResponse1.Result, TipAmount = ProcessingResponse1.TipAmount, TransactionNumber = ProcessingResponse1.TransactionNumber }, paymentResponse1.PaymentIndex); // create a second credit card object pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest creditCard2 = new pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest(); creditCard2.Amount = 7.98M; creditCard2.CardNumber = "4545454545454545"; creditCard2.ExpirationMonth = 05; creditCard2.ExpirationYear = 13; creditCard2.BarTab = false;// this card is not a bar tab creditCard2.ProcessingType = pcAmerica.DesktopPOS.API.Client.PaymentService.ProcessingType.PreAuth; //process and apply the 2nd card pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardPaymentProcessingResponse ProcessingResponse2 = paymentAPI.ProcessCreditCard(creditCard2); AppliedPaymentResponse paymentResponse2 = salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse2.Amount, ApprovalCode = ProcessingResponse2.ApprovalCode, CardNumber = ProcessingResponse2.CardNumber, ExpirationMonth = ProcessingResponse2.ExpirationMonth, ExpirationYear = ProcessingResponse2.ExpirationYear, ExtensionData = ProcessingResponse2.ExtensionData, IsPrePaidCard = ProcessingResponse2.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse2.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PreAuth, ReferenceNumber = ProcessingResponse2.ReferenceNumber, Result = ProcessingResponse2.Result, TipAmount = ProcessingResponse2.TipAmount, TransactionNumber = ProcessingResponse2.TransactionNumber }, -1); //update the invoice object and end the transaction inv = salesAPI.GetInvoice(salesContext, inv.InvoiceNumber); salesAPI.EndInvoice(salesContext, inv.InvoiceNumber); //salesAPI.PrintReceipt(salesContext, inv.InvoiceNumber,-1); //add a tips to the invoice creditCard1.TipAmount = 1.5M; creditCard1.BarTab = false; ProcessingResponse1 = paymentAPI.CompletePreAuth(creditCard1, inv.InvoiceNumber); salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse1.Amount, ApprovalCode = ProcessingResponse1.ApprovalCode, CardNumber = ProcessingResponse1.CardNumber, ExpirationMonth = ProcessingResponse1.ExpirationMonth, ExpirationYear = ProcessingResponse1.ExpirationYear, ExtensionData = ProcessingResponse1.ExtensionData, IsPrePaidCard = ProcessingResponse1.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse1.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PostAuth, ReferenceNumber = ProcessingResponse1.ReferenceNumber, Result = ProcessingResponse1.Result, TipAmount = ProcessingResponse1.TipAmount, TransactionNumber = ProcessingResponse1.TransactionNumber }, paymentResponse1.PaymentIndex); //to complete the earlier pre auth card you must call CompletePreAuth and pass it the PaymentIndex you got back from ApplyCardPayment earlier creditCard2.Amount = 7.98M; creditCard2.TipAmount = 1.77M; creditCard2.ProcessingType = pcAmerica.DesktopPOS.API.Client.PaymentService.ProcessingType.PostAuth; creditCard2.PostAuthReferenceNumber = ProcessingResponse2.PostAuthReferenceNumber; creditCard2.ReferenceNumber = ProcessingResponse2.ReferenceNumber; creditCard2.PaymentIndex = paymentResponse2.PaymentIndex; ProcessingResponse2 = paymentAPI.CompletePreAuth(creditCard2, inv.InvoiceNumber); salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse2.Amount, ApprovalCode = ProcessingResponse2.ApprovalCode, CardNumber = ProcessingResponse2.CardNumber, ExpirationMonth = ProcessingResponse2.ExpirationMonth, ExpirationYear = ProcessingResponse2.ExpirationYear, ExtensionData = ProcessingResponse2.ExtensionData, IsPrePaidCard = ProcessingResponse2.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse2.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PostAuth, ReferenceNumber = ProcessingResponse2.ReferenceNumber, Result = ProcessingResponse2.Result, TipAmount = ProcessingResponse2.TipAmount, TransactionNumber = ProcessingResponse2.TransactionNumber }, paymentResponse2.PaymentIndex); salesAPI.PrintReceipt(salesContext, inv.InvoiceNumber, -1); } finally { Console.WriteLine("PRESS ENTER TO CONTINUE..."); Console.ReadLine(); } }
static void TestSaleWithCreditCardPayment() { try { var api = new SalesAPI(); var context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context { CashierID = "100101", StoreID = "1001", StationID = "01" }; // StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal var inv = api.StartNewInvoice(context, "ROB" + DateTime.Now.Second.ToString(), "XXOPEN TABS"); Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber)); inv.LineItems.Add(new LineItem() { ItemNumber = "Non_Inventory", ItemName = "Hot dog", Price = 1, Quantity = 1, State = EntityState.Added }); inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems); Console.WriteLine(String.Format("ModifyItems ADDED item # 1, new invoice value: {0}", inv.GrandTotal)); // SendToKitchen if (api.SendToKitchen(context, inv.InvoiceNumber)) Console.WriteLine("Invoice was printed in kitchen"); else Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen"); if (api.SendToKitchen(context, inv.InvoiceNumber)) Console.WriteLine( "Invoice was printed in kitchen, it should not have printed anything out the 2nd time"); else Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen"); // ApplyCardPayment - applying remaining 1 dollar as a credit card var payResponse = api.ApplyCardPayment(context, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = inv.GrandTotal, CardNumber = "4***********1", ReferenceNumber = "123456", Result = true, TipAmount = 1, TransactionNumber = 1234 }, -1); if (payResponse.Success) Console.WriteLine(String.Format("Applied card payment, change due {0}", payResponse.ChangeAmount)); else Console.WriteLine("***ERROR*** Could not apply card payment"); // EndInvoice if (api.EndInvoice(context, inv.InvoiceNumber)) Console.WriteLine("Ended invoice successfully"); else Console.WriteLine("***ERROR*** Could not end invoice"); // PrintReceipt - providing -1 for the split check # when there are no split checks if (api.PrintReceipt(context, inv.InvoiceNumber, -1)) Console.WriteLine("Receipt was printed"); else Console.WriteLine("***ERROR*** Receive was NOT printed"); } catch (Exception ex) { Console.WriteLine(ex); } finally { Console.WriteLine("PRESS ENTER TO CONTINUE..."); Console.ReadLine(); } }