public Loader(ILogger logger) { _logger = logger; driverLocation = $@"C:\Acrelec\Core\Peripherals\Payments\Drivers\{Constants.PAYMENT_NAME}\{DriverVersion}\Driver\{Constants.DRIVER_FOLDER_NAME}"; var assembly = System.Reflection.Assembly.GetExecutingAssembly(); _logger.Info(Constants.LOG_FILE, $"{assembly.GetTitle()} {assembly.GetFileVersion()} [build timestamp: {assembly.GetBuildTimestamp():yyyy/MM/dd HH:mm:ss}]"); _logger.Info(Constants.LOG_FILE, "Loader method started..."); LastStatus = PeripheralStatus.PeripheralNotConfigured(); //Init the settings _currentPaymentInitConfig = new Payment { Id = Constants.ID, PaymentName = Constants.PAYMENT_NAME, DriverFolderName = Constants.DRIVER_FOLDER_NAME, Type = Constants.PAYMENT_TYPE.ToString(), ConfigurationSettings = new List <AdminPeripheralSetting>() { new AdminPeripheralSetting() { ControlType = SettingDataType.Int, ControlName = "POS Number", RealName = "PosNumber", CurrentValue = "1", ControlDescription = "POS Number" } } }; }
public bool Test() { try { //_logger.Info(Constants.LOG_FILE, "Test method started..."); var proxy = _channelFactory.CreateChannel(); using (proxy as IDisposable) { var result = proxy.Test(); LastStatus = result == ResultCode.Success ? PeripheralStatus.PeripheralOK() : PeripheralStatus.PeripheralGenericError(); if (result != ResultCode.Success) { _logger.Error(Constants.LOG_FILE, "Payment driver test returned an error."); } } return(LastStatus.Status == 0); } catch (Exception ex) { _logger.Error(Constants.LOG_FILE, "Failed to test payment driver."); _logger.Error(Constants.LOG_FILE, ex.ToString()); return(false); } finally { _logger.Debug(Constants.LOG_FILE, "Test method finished."); } }
/// <summary> /// /// </summary> /// <param name="payRequest"></param> /// <param name="payDetails"></param> /// <param name="specificStatusDetails"></param> /// <param name="wasUncertainPaymentDetected"></param> /// <returns></returns> public bool Pay(PayRequest payRequest, ref PayDetails payDetails, ref SpecificStatusDetails specificStatusDetails, ref bool wasUncertainPaymentDetected) { try { _logger.Info(Constants.LOG_FILE, "Pay method started..."); _logger.Debug(Constants.LOG_FILE, $"PayRequest: {JsonConvert.SerializeObject(payRequest)}"); Result <PaymentData> result; var proxy = _channelFactory.CreateChannel(); using (proxy as IDisposable) { result = proxy.Pay(payRequest.Amount, payRequest.TransactionReference); } payDetails = new PayDetails { PaidAmount = result.Data?.PaidAmount ?? 0, HasClientReceipt = result.Data?.HasClientReceipt ?? false, HasMerchantReceipt = result.Data?.HasMerchantReceipt ?? false }; specificStatusDetails = new SpecificStatusDetails() { StatusCode = (int)result.ResultCode, Description = result.Message }; //Check the status property of the parameters object to see if the Pay was successful if ((result.ResultCode == ResultCode.Success && result.Data?.Result == PaymentResult.Successful)) { _logger.Info(Constants.LOG_FILE, "Payment has succeeded."); LastStatus = PeripheralStatus.PeripheralOK(); return(true); } else { _logger.Info(Constants.LOG_FILE, "Payment has failed."); return(false); } } catch (Exception ex) { _logger.Error(Constants.LOG_FILE, "Payment exception thrown."); _logger.Error(Constants.LOG_FILE, ex.ToString()); return(false); } }
/// <summary> /// /// </summary> /// <param name="payRequest"></param> /// <param name="payDetails"></param> /// <param name="specificStatusDetails"></param> /// <param name="wasUncertainPaymentDetected"></param> /// <returns></returns> public bool Pay(PayRequest payRequest, ref PayDetails payDetails, ref SpecificStatusDetails specificStatusDetails, ref bool wasUncertainPaymentDetected) { try { _logger.Info(Constants.LOG_FILE, "Pay method started..."); _logger.Debug(Constants.LOG_FILE, $"PayRequest: {JsonConvert.SerializeObject(payRequest)}"); //Init the paid amount and Tender Media payDetails = new PayDetails(); Result <PaymentData> result; var proxy = _channelFactory.CreateChannel(); using (proxy as IDisposable) { result = proxy.Pay(payRequest.Amount); } //Check the status property of the parameters object to see if the Pay was successful if (result.ResultCode == ResultCode.Success && result.Data.Result == PaymentResult.Successful) { _logger.Info(Constants.LOG_FILE, "Payment has been succeeded."); LastStatus = PeripheralStatus.PeripheralOK(); //Update the payment details with the ones received from the payment terminal //payDetails.TenderMediaId = result.Data.TenderMediaId; payDetails.PaidAmount = result.Data.PaidAmount; payDetails.HasClientReceipt = result.Data.HasClientReceipt; } else { _logger.Info(Constants.LOG_FILE, "Payment has been failed."); } specificStatusDetails = new SpecificStatusDetails() { StatusCode = (int)result.ResultCode, Description = result.Message }; return(result.ResultCode == ResultCode.Success && result.Data.Result == PaymentResult.Successful); } catch (Exception ex) { _logger.Error(Constants.LOG_FILE, "Payment exception has been thrown."); _logger.Error(Constants.LOG_FILE, ex.ToString()); return(false); } }
public Loader(ILogger logger) { _logger = logger; var assembly = System.Reflection.Assembly.GetExecutingAssembly(); _logger.Info(Constants.LOG_FILE, $"{assembly.GetTitle()} {assembly.GetFileVersion()} [build timestamp: {assembly.GetBuildTimestamp():yyyy/MM/dd HH:mm:ss}]"); _logger.Info(Constants.LOG_FILE, "Loader method started..."); LastStatus = PeripheralStatus.PeripheralNotConfigured(); //Init the settings _currentPaymentInitConfig = new Payment { Id = Constants.ID, PaymentName = Constants.NAME, DriverFolderName = Path.GetDirectoryName(Constants.DRIVER_PATH).Split(Path.DirectorySeparatorChar).Last(), ConfigurationSettings = new List <AdminPeripheralSetting>() { new AdminPeripheralSetting() { ControlType = SettingDataType.SerialPortSelection, ControlName = "COM Port number", RealName = "Port", CurrentValue = "", ControlDescription = "Serial communication port for the EFT terminal (IPP350)" }, new AdminPeripheralSetting() { ControlType = SettingDataType.Bool, ControlName = "Force online transaction", RealName = "ForceOnline", CurrentValue = "False", ControlDescription = "Force online transaction" }, new AdminPeripheralSetting() { ControlType = SettingDataType.Int, ControlName = "POS Number", RealName = "PosNumber", CurrentValue = "1", ControlDescription = "POS Number" } } }; }
public static void CheckBarcodeReaderStatus(IPort port) { // Create IPeripheralConnectParser object. IPeripheralConnectParser parser = StarIoExt.CreateBcrConnectParser(BcrModel.POP1); // Usage of parser sample is "Communication.ParseDoNotCheckCondition(IPeripheralCommandParser parser, IPort port)". CommunicationResult result = Communication.ParseDoNotCheckCondition(parser, port); // Check peripheral status. barcodeReaderStatus = PeripheralStatus.Invalid; if (result.Result == Result.Success) { // Check parser property value. if (parser.IsConnected) // connect { barcodeReaderStatus = PeripheralStatus.Connect; } else // disconnect { barcodeReaderStatus = PeripheralStatus.Disconnect; } } else // communication error { barcodeReaderStatus = PeripheralStatus.Impossible; } //switch (barcodeReaderStatus) //{ // default: // case PeripheralStatus.Impossible: // OnBarcodeReaderImpossible(); // break; // case PeripheralStatus.Connect: // OnBarcodeReaderConnect(); // break; // case PeripheralStatus.Disconnect: // OnBarcodeReaderDisconnect(); // break; //} }
public static string GetPeripheralStatusResultMessage(PeripheralStatus status) { string message; switch (status) { default: case PeripheralStatus.Impossible: message = "Impossible"; break; case PeripheralStatus.Connect: message = "Connect"; break; case PeripheralStatus.Disconnect: message = "Disconnect"; break; } return(message); }
public bool Pay(PayRequest payRequest, ref PayDetails payDetails, ref SpecificStatusDetails specificStatusDetails, ref bool wasUncertainPaymentDetected) { try { logger.Info(PAYMENT_LOG, "Pay: Started payment."); //Init the payment details this.payDetails = new PayDetails(); //Check if the c3_rmp_net is started or if multiple instances of it are started. if (!c3NetManager.IsC3NetStarted() || c3NetManager.AreMultipleC3NetInstancesStarted()) { logger.Info(PAYMENT_LOG, " c3_rpm_net.exe is closed or has multiple instances opened."); if (!StartC3Net()) { logger.Info(PAYMENT_LOG, " c3_rpm_net.exe restart failed."); paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; return(false); } } //Set the flag to false until a response is received from the payment application IsPayFinished = false; WasPaySuccessful = false; //Init the object that will be updated with the specific error code and description. this.specificStatusDetails = new SpecificStatusDetails(); specificStatusDetails.StatusCode = PeripheralStatus.PeripheralGenericError().Status; specificStatusDetails.Description = PeripheralStatus.PeripheralGenericError().Description; //If the message is not received by the payment application the method will fail if (!communicator.SendMessage(CommunicatorMethods.Pay, (object)payRequest)) { paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; return(false); } //Wait until the payment application responds to the test message while (!IsPayFinished) { Thread.Sleep(0); Thread.Sleep(50); } logger.Info(PAYMENT_LOG, "Pay: Pay finished."); //Update the payment details reference payDetails = this.payDetails; if (WasPaySuccessful) { paymentStatus.CurrentStatus = PeripheralStatus.PeripheralOK().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralOK().Description; } specificStatusDetails = this.specificStatusDetails; return(WasPaySuccessful); } catch (Exception ex) { logger.Error(PAYMENT_LOG, string.Format("Pay: Failed payment.\r\n{0}", ex.ToString())); } paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; return(false); }
public bool Test() { try { logger.Info(PAYMENT_LOG, "Test: Started testing payment."); //Set the flag to false until a response is received from the payment application IsTestFinished = false; WasTestSuccessful = false; //Check if the c3_rmp_net is started or if multiple instances of it are started. if (!c3NetManager.IsC3NetStarted() || c3NetManager.AreMultipleC3NetInstancesStarted()) { if (StartC3Net()) { paymentStatus.CurrentStatus = PeripheralStatus.PeripheralOK().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralOK().Description; return(true); } else { paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; return(false); } } //If the message is not received by the payment application the method will fail if (!communicator.SendMessage(CommunicatorMethods.Test, new object())) { paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; return(false); } //Wait until the payment application responds to the test message while (!IsTestFinished) { Thread.Sleep(0); Thread.Sleep(50); } logger.Info(PAYMENT_LOG, "Test: Finished testing payment."); if (WasTestSuccessful) { paymentStatus.CurrentStatus = PeripheralStatus.PeripheralOK().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralOK().Description; } else { paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; } return(WasTestSuccessful); } catch (Exception ex) { logger.Error(PAYMENT_LOG, string.Format("Test: Failed to test payment.\r\n{0}", ex.ToString())); } paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; return(false); }
public bool Init() { try { _logger.Info(Constants.LOG_FILE, "Initializing payment..."); //Start the driver Payment application (if it's already open try to close it before starting it) LaunchDriver(); Thread.Sleep(2000); var binding = new NetNamedPipeBinding() { CloseTimeout = TimeSpan.FromDays(1), OpenTimeout = TimeSpan.FromDays(1), ReceiveTimeout = TimeSpan.FromDays(1), SendTimeout = TimeSpan.FromDays(1) }; // Create communication channel _logger.Info(Constants.LOG_FILE, "Creating channel factory..."); _channelFactory = new ChannelFactory <IPaymentService>(binding, new EndpointAddress($"net.pipe://localhost/{Constants.PAYMENT_NAME}")); var parameters = _currentPaymentInitConfig.ConfigurationSettings.ToDictionary(_ => _.RealName, _ => _.CurrentValue); var serializedConfiguration = JsonConvert.SerializeObject(parameters); _logger.Info(Constants.LOG_FILE, $"Serialized Configuration: {serializedConfiguration}"); var configuration = JsonConvert.DeserializeObject <RuntimeConfiguration>(serializedConfiguration); var proxy = _channelFactory.CreateChannel(); using (proxy as IDisposable) { var result = proxy.Init(configuration); if (result == ResultCode.Success) { LastStatus = PeripheralStatus.PeripheralOK(); _logger.Info(Constants.LOG_FILE, "Driver successfully initialized."); } else { LastStatus = PeripheralStatus.PeripheralGenericError(); _logger.Info(Constants.LOG_FILE, "Driver failed to initialize."); } return(result == ResultCode.Success); } } catch (Exception ex) { _logger.Error(Constants.LOG_FILE, "Error Message in Init():\n" + ex.Message); _logger.Error(Constants.LOG_FILE, "Source Error in Init():\n" + ex.Source); _logger.Error(Constants.LOG_FILE, "StackTrace Error in Init():\n" + ex.StackTrace); LastStatus = PeripheralStatus.PeripheralGenericError(); _logger.Error(Constants.LOG_FILE, "Failed to initialize payment driver."); _logger.Error(Constants.LOG_FILE, ex.ToString()); return(false); } finally { _logger.Info(Constants.LOG_FILE, "Init method finished."); } }
public static void ShowPeripheralStatusResultMessage(string peripheralName, PeripheralStatus status) { string resultMessage = GetPeripheralStatusResultMessage(status); MessageBox.Show(peripheralName + " " + resultMessage, "Check Status"); }
public static void ShowPeripheralStatusResultMessage(string peripheralName, PeripheralStatus status) { string resultMessage = GetPeripheralStatusResultMessage(status); Util.ShowMessage("Check Status", peripheralName + " " + resultMessage); }