//////////////// Void methods ///////////// private void VoidButton_Click(object sender, EventArgs e) { VoidPaymentRequest request = new VoidPaymentRequest(); if (OrderPaymentsView.SelectedItems.Count == 1) { POSPayment payment = ((POSPayment)OrderPaymentsView.SelectedItems[0].Tag); request.PaymentId = payment.PaymentID; request.EmployeeId = payment.EmployeeID; request.OrderId = payment.OrderID; request.VoidReason = "USER_CANCEL"; cloverConnector.VoidPayment(request); } }
public static void testPaymentAndVoid(CloverConnector cloverConnector, TestConnectorListener connListener) { //BEGIN: Test Void SaleRequest paymentRequest = new SaleRequest(); paymentRequest.ExternalId = ExternalIDUtil.GenerateRandomString(13); paymentRequest.Amount = 1324; paymentRequest.TipAmount = 123; System.Console.WriteLine("Preparing To Test Sale: $" + paymentRequest.Amount * 100.00); System.Console.WriteLine("Press Any Key to Continue..."); System.Console.ReadKey(); //cloverConnector.Sales += paymentListener; cloverConnector.Sale(paymentRequest); while (!connListener.hasResponse) { System.Console.WriteLine("Waiting for paymentResponse"); System.Threading.Thread.Sleep(1000); } SaleResponse response = connListener.saleResponse; string paymentId = response.Payment.id; string orderId = response.Payment.order.id; string employeeId = response.Payment.employee.id; VoidPaymentRequest voidRequest = new VoidPaymentRequest(); voidRequest.OrderId = orderId; voidRequest.PaymentId = paymentId; voidRequest.EmployeeId = employeeId; voidRequest.VoidReason = VoidReason.USER_CANCEL.ToString(); cloverConnector.VoidPayment(voidRequest); while (!connListener.hasResponse) { System.Console.WriteLine("Waiting for voidResponse"); System.Threading.Thread.Sleep(1000); } VoidPaymentResponse voidResponse = connListener.voidPaymentResponse; System.Console.WriteLine(voidResponse.Result); //END: Test Void }
public static void testPaymentAndVoid(CloverConnector cloverConnector, TestConnectorListener connListener) { //BEGIN: Test Void SaleRequest paymentRequest = new SaleRequest(); paymentRequest.ExternalId = ExternalIDUtil.GenerateRandomString(13); paymentRequest.Amount = 1324; paymentRequest.TipAmount = 123; System.Console.WriteLine("Preparing To Test Sale: $" + paymentRequest.Amount * 100.00); System.Console.WriteLine("Press Any Key to Continue..."); System.Console.ReadKey(); //cloverConnector.Sales += paymentListener; cloverConnector.Sale(paymentRequest); while (!connListener.hasResponse) { System.Console.WriteLine("Waiting for paymentResponse"); System.Threading.Thread.Sleep(1000); } SaleResponse response = connListener.saleResponse; string paymentId = response.Payment.id; string orderId = response.Payment.order.id; string employeeId = response.Payment.employee.id; VoidPaymentRequest voidRequest = new VoidPaymentRequest(); voidRequest.OrderId = orderId; voidRequest.PaymentId = paymentId; voidRequest.EmployeeId = employeeId; voidRequest.VoidReason = VoidReason.USER_CANCEL.ToString(); cloverConnector.VoidPayment(voidRequest); while (!connListener.hasResponse) { System.Console.WriteLine("Waiting for voidResponse"); System.Threading.Thread.Sleep(1000); } VoidPaymentResponse voidResponse = connListener.voidPaymentResponse; System.Console.WriteLine(voidResponse.Result); //END: Test Void }
protected override void OnStart(string[] args) { base.OnStart(args); string logSource = "_TransportEventLog"; if (!EventLog.SourceExists(logSource)) { EventLog.CreateEventSource(logSource, logSource); } EventLogTraceListener myTraceListener = new EventLogTraceListener(logSource); // Add the event log trace listener to the collection. Trace.Listeners.Add(myTraceListener); if (args.Length > 0) { if (((ICollection <string>)args).Contains("-debug")) { Debug = true; } if (((ICollection <string>)args).Any(a => a.Contains("-timer"))) { IEnumerable <string> timerStrings = ((ICollection <string>)args).Where(a => a.Contains("-timer")); if (timerStrings.Count() == 1) { try { string timerString = timerStrings.First(); int index = timerString.IndexOf('='); string timerSeconds = timerString.Substring(index + 1); Timer = Convert.ToInt32(timerSeconds); } catch (Exception e) { Timer = 1; EventLog.WriteEntry(SERVICE_NAME, "Error parsing the -timer command line argument. Setting timer to 1 second."); } } } } //load args in to dictionary Dictionary <string, string> parameters = new Dictionary <string, string>(); if (args != null) { for (int i = 0; i < args.Length; i++) { if ("/T".Equals(args[i])) { parameters.Add("/T", "true"); } else if (i + 1 < args.Length) { parameters.Add(args[i], args[++i]); } } } IWebSocketConnection sendSocket = null; Action <IWebSocketConnection> serverSocket = socket => { socket.OnOpen = () => { Console.WriteLine("Open! " + clientConnections.Count); if (clientConnections.Count > 0) { if (clientConnections[0].IsAvailable) { socket.Close(); connectorListener.OnDeviceError(new CloverDeviceErrorEvent(CloverDeviceErrorEvent.CloverDeviceErrorType.EXCEPTION, 0, "Another client is already connected")); return; } } sendSocket = socket; clientConnections.Add(socket); connectorListener.WebSocket = sendSocket; connectorListener.SendConnectionStatus(); }; socket.OnClose = () => { clientConnections.Remove(socket); Console.WriteLine("Close!"); connectorListener.WebSocket = null; }; socket.OnMessage = message => { try { JObject jsonObj = (JObject)JsonConvert.DeserializeObject(message); JToken method = jsonObj.GetValue(ServicePayloadConstants.PROP_METHOD); JObject payload = (JObject)jsonObj.GetValue(ServicePayloadConstants.PROP_PAYLOAD); WebSocketMethod wsm = (WebSocketMethod)Enum.Parse(typeof(WebSocketMethod), method.ToString()); switch (wsm) { case WebSocketMethod.Status: { connectorListener.SendConnectionStatus(); break; } case WebSocketMethod.OpenCashDrawer: { string reason = ((JObject)payload).GetValue("Reason").Value <string>(); cloverConnector.OpenCashDrawer(reason); break; } case WebSocketMethod.ShowMessage: { string msg = ((JObject)payload).GetValue("Message").Value <string>(); cloverConnector.ShowMessage(msg); break; } case WebSocketMethod.ShowThankYouScreen: { cloverConnector.ShowThankYouScreen(); break; } case WebSocketMethod.ShowWelcomeScreen: { cloverConnector.ShowWelcomeScreen(); break; } case WebSocketMethod.Cancel: { cloverConnector.Cancel(); break; } case WebSocketMethod.Break: { cloverConnector.ResetDevice(); break; } case WebSocketMethod.PrintText: { JArray messages = (JArray)payload.GetValue("Messages"); List <string> messageList = new List <string>(); foreach (string msg in messages) { messageList.Add(msg); } cloverConnector.PrintText(messageList); break; } case WebSocketMethod.PrintImage: { string base64Img = ((JObject)payload).GetValue("Bitmap").Value <string>(); byte[] imgBytes = Convert.FromBase64String(base64Img); MemoryStream ms = new MemoryStream(); ms.Write(imgBytes, 0, imgBytes.Length); Bitmap bp = new Bitmap(ms); ms.Close(); cloverConnector.PrintImage(bp); break; } case WebSocketMethod.PrintImageFromURL: { string url = ((JObject)payload).GetValue("Url").Value <string>(); cloverConnector.PrintImageFromURL(url); break; } case WebSocketMethod.Auth: { AuthRequest authRequest = JsonUtils.deserialize <AuthRequest>(payload.ToString()); cloverConnector.Auth(authRequest); break; } case WebSocketMethod.PreAuth: { PreAuthRequest preAuthRequest = JsonUtils.deserialize <PreAuthRequest>(payload.ToString()); cloverConnector.PreAuth(preAuthRequest); break; } case WebSocketMethod.TipAdjustAuth: { TipAdjustAuthRequest tipAdjustRequest = JsonUtils.deserialize <TipAdjustAuthRequest>(payload.ToString()); cloverConnector.TipAdjustAuth(tipAdjustRequest); break; } case WebSocketMethod.CapturePreAuth: { CapturePreAuthRequest capturePreAuthRequest = JsonUtils.deserialize <CapturePreAuthRequest>(payload.ToString()); cloverConnector.CapturePreAuth(capturePreAuthRequest); break; } case WebSocketMethod.Sale: { SaleRequest saleRequest = JsonUtils.deserialize <SaleRequest>(payload.ToString()); cloverConnector.Sale(saleRequest); break; } case WebSocketMethod.InvokeInputOption: { InputOption io = JsonUtils.deserialize <InputOption>(payload.ToString()); cloverConnector.InvokeInputOption(io); break; } case WebSocketMethod.VoidPayment: { VoidPaymentRequest request = JsonUtils.deserialize <VoidPaymentRequest>(payload.ToString()); cloverConnector.VoidPayment(request); break; } case WebSocketMethod.ManualRefund: { ManualRefundRequest mrr = JsonUtils.deserialize <ManualRefundRequest>(payload.ToString()); cloverConnector.ManualRefund(mrr); break; } case WebSocketMethod.RefundPayment: { RefundPaymentRequest request = JsonUtils.deserialize <RefundPaymentRequest>(payload.ToString()); cloverConnector.RefundPayment(request); break; } case WebSocketMethod.DisplayPaymentReceiptOptions: { DisplayPaymentReceiptOptionsRequest request = JsonUtils.deserialize <DisplayPaymentReceiptOptionsRequest>(payload.ToString()); cloverConnector.DisplayPaymentReceiptOptions(request.OrderID, request.PaymentID); break; } case WebSocketMethod.ShowDisplayOrder: { com.clover.remote.order.DisplayOrder displayOrder = JsonUtils.deserialize <com.clover.remote.order.DisplayOrder>(payload.ToString()); cloverConnector.ShowDisplayOrder(displayOrder); break; } case WebSocketMethod.AcceptSignature: { WSVerifySignatureRequest svr = JsonUtils.deserialize <WSVerifySignatureRequest>(payload.ToString()); cloverConnector.AcceptSignature(svr); break; } case WebSocketMethod.RejectSignature: { WSVerifySignatureRequest svr = JsonUtils.deserialize <WSVerifySignatureRequest>(payload.ToString()); cloverConnector.RejectSignature(svr); break; } case WebSocketMethod.ConfirmPayment: { AcceptPayment acceptPayment = JsonUtils.deserialize <AcceptPayment>(payload.ToString()); cloverConnector.AcceptPayment(acceptPayment.Payment); break; } case WebSocketMethod.RejectPayment: { RejectPayment rp = JsonUtils.deserialize <RejectPayment>(payload.ToString()); cloverConnector.RejectPayment(rp.Payment, rp.Challenge); break; } case WebSocketMethod.VaultCard: { VaultCardMessage vcm = JsonUtils.deserialize <VaultCardMessage>(payload.ToString()); cloverConnector.VaultCard(vcm.cardEntryMethods); break; } case WebSocketMethod.ReadCardData: { ReadCardDataRequest request = JsonUtils.deserialize <ReadCardDataRequest>(payload.ToString()); cloverConnector.ReadCardData(request); break; } case WebSocketMethod.Closeout: { CloseoutRequest cr = new CloseoutRequest(); cloverConnector.Closeout(cr); break; } case WebSocketMethod.RetrievePendingPayments: { cloverConnector.RetrievePendingPayments(); break; } default: { Console.WriteLine("received unknown websocket method: " + method.ToString() + " in CloverWebSocketService."); break; } } } catch (InvalidOperationException ioe) { Console.WriteLine(ioe.Message); socket.Send("Error Deserializing"); } catch (Exception e) { Console.WriteLine(e.Message); socket.Send("Error Parsing: " + message); } }; }; InitializeConnector(parameters); server.Start(serverSocket); }