private static async Task Run() { var connector = CloverConnectorFactory.CreateUsbConnector("RAID", "POS", "Register1", false); var listener = new Listener(connector); connector.AddCloverConnectorListener(listener); listener.DeviceReadyPromise = new TaskCompletionSource <MerchantInfo>(); connector.InitializeConnection(); await listener.DeviceReadyPromise.Task; listener.ResetDeviceResponsePromise = new TaskCompletionSource <ResetDeviceResponse>(); connector.ResetDevice(); await listener.ResetDeviceResponsePromise.Task; listener.SaleResponsePromise = new TaskCompletionSource <SaleResponse>(); connector.Sale(new SaleRequest { ExternalId = ExternalIDUtil.GenerateRandomString(32), Amount = 123 }); var sale = await listener.SaleResponsePromise.Task; await Task.Delay(100); connector.Dispose(); }
/// <summary> /// Connect to the specified Clover device /// </summary> public bool Connect(string connectionString) { CloverDeviceConfiguration config = null; Address = connectionString; if (connectionString.Trim().ToUpper() == "USB") { // USB connected Clover Devices are directly connected to the machine and so don't need any extra identification or Pairing information config = new USBCloverDeviceConfiguration(RemoteAppId, true); Address = "USB"; } else { // Network connections require a pairing information and send extra identification to the device config = new WebSocketCloverDeviceConfiguration(connectionString, RemoteAppId, true, 1, PosName, SerialNumber, LoadPairingAuthToken(connectionString, RemoteAppId, PosName), OnPairingCode, OnPairingSuccess, OnPairingState); } if (config != null) { cloverConnector = CloverConnectorFactory.createICloverConnector(config); listener = new SimpleCloverConnectorListener(cloverConnector); listener.DeviceConnected += Listener_DeviceConnected; listener.DeviceReady += Listener_DeviceReady; listener.DeviceDisconnected += Listener_DeviceDisconnected; listener.DeviceError += Listener_DeviceError; listener.SaleResponse += Listener_SaleResponse; cloverConnector.AddCloverConnectorListener(listener); cloverConnector.InitializeConnection(); } return(config != null); }
static void Main(string[] args) { cloverConnector = CloverConnectorFactory.createICloverConnector(SampleUtils.GetNetworkConfiguration()); var ccl = new ExampleCloverConnectionListener(cloverConnector); cloverConnector.AddCloverConnectorListener(ccl); cloverConnector.InitializeConnection(); while (!ccl.deviceReady) { Thread.Sleep(1000); } var pendingSale = new SaleRequest(); pendingSale.ExternalId = ExternalIDUtil.GenerateRandomString(13); pendingSale.Amount = 1000; pendingSale.AutoAcceptSignature = true; pendingSale.AutoAcceptPaymentConfirmations = true; pendingSale.DisableDuplicateChecking = true; cloverConnector.Sale(pendingSale); while (!ccl.saleDone) { Thread.Sleep(1000); } Console.ReadKey(); }
private void InitializeConnector(Dictionary <string, string> parameters) { string protocol; string port; bool testConfig = false; //string lanConfig = null; string testConfigString; if (!parameters.TryGetValue("/P", out port)) { port = "8889";// default } string certPath = null; if (!parameters.TryGetValue("/C", out certPath)) { protocol = "ws";// default } else { protocol = "wss"; } if (!parameters.TryGetValue("/T", out testConfigString)) { testConfig = false; } else { testConfig = true; // } //parameters.TryGetValue("/L", out lanConfig); server = new WebSocketServer(protocol + "://127.0.0.1:" + port); if (certPath != null) { server.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(certPath); } CloverDeviceConfiguration config = null; if (testConfig) { //config = new TestCloverDeviceConfiguration(); } else { config = new USBCloverDeviceConfiguration(null, getPOSNameAndVersion(), Debug, Timer); } cloverConnector = CloverConnectorFactory.createICloverConnector(config); cloverConnector.AddCloverConnectorListener(connectorListener); cloverConnector.InitializeConnection(); }
public PointOfSale() { var connector = CloverConnectorFactory.CreateUsbConnector("RAID", "Point of Sale", "Register101", false); connector.AddCloverConnectorListener(new Listener(this)); connector.InitializeConnection(); connector.RetrieveDeviceStatus(new RetrieveDeviceStatusRequest { sendLastMessage = true }); Connector = connector; }
public static void Main(string[] args) { cloverConnector = CloverConnectorFactory.createICloverConnector(SampleUtils.GetNetworkConfiguration()); var ccl = new ExampleCloverConnectionListener(cloverConnector); cloverConnector.AddCloverConnectorListener(ccl); cloverConnector.InitializeConnection(); while (!ccl.deviceConnected) { Thread.Sleep(1000); } Console.ReadKey(); }
/// <summary> /// When the user hits the connect button, create a Clover network connection: WebSocket transport to Secure Network Pay Display (SNPD) running on the device /// Note: needs the wss network address supplied in the DeviceAddressTextBox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ConnectButton_Click(object sender, EventArgs e) { ClearOutput(); Output("Initiating Connection..."); clover = new CloverEventConnector(CloverConnectorFactory.CreateWebSocketConnector(DeviceAddressTextBox.Text.Trim(), "__Your_Clover_RAID_Here__", "SNPD Connection Sample", "lane 1", CurrentPairingToken, PairingCodeHandler, PairingSuccessHandler, PairingStateHandler)); clover.Message += Clover_Message; clover.DeviceError += Clover_DeviceError; clover.DeviceConnected += Clover_DeviceConnected; clover.DeviceReady += Clover_DeviceReady; clover.DeviceDisconnected += Clover_DeviceDisconnected; clover.InitializeConnection(); }
protected override void OnStart(string[] args) { if (args.Length == 0) { // Retrieve the arguments from the service ImagePath args = Environment.GetCommandLineArgs(); } 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 { Timer = 1; EventLog.WriteEntry(SERVICE_NAME, "Error parsing the -timer command line argument. Setting timer to 1 second."); } } } } EventLog.WriteEntry(SERVICE_NAME, "Starting..."); Dictionary <string, string> argsMap = new Dictionary <string, string>(); for (int i = 1; i < args.Length; i++) { argsMap.Add(args[i - 1], args[i++]); } // only allow localhost string listenAddress = null; if (!argsMap.TryGetValue("/P", out listenAddress)) { listenAddress = "http://127.0.0.1:8181/"; listenAddress = "8181"; } ServiceEndpoints endpoints = new ServiceEndpoints(); string callbackEndpoint = null; if (!argsMap.TryGetValue("/C", out callbackEndpoint)) { callbackEndpoint = "http://localhost:8182/CloverCallback"; } server = new CloverRESTServer("localhost", listenAddress, "http");// "127.0.0.1", listenAddress, "http"); CloverRESTConnectorListener connectorListener = new CloverRESTConnectorListener(); Console.WriteLine("callback endpoint: " + callbackEndpoint); connectorListener.RestClient = new RestSharp.RestClient(callbackEndpoint); server.ForwardToClientListener = connectorListener; server.CloverConnector = (CloverConnector)CloverConnectorFactory.createICloverConnector(new USBCloverDeviceConfiguration(null, getPOSNameAndVersion(), Debug, Timer)); server.CloverConnector.AddCloverConnectorListener(connectorListener); server.CloverConnector.InitializeConnection(); StartRESTListener(); server.OnAfterStart += new ToggleServerHandler(this.OnServerStart); server.OnStop += new ToggleServerHandler(this.OnServerStop); }