Ejemplo n.º 1
0
        private bool SetPaymentConfigSettings(AdminPeripheralSetting setting, ref string exceptionMessage)
        {
            try
            {
                logger.Info(PAYMENT_LOG, string.Format("Updating c3config setting : {0}", setting.ControlName));

                switch (setting.ControlType)
                {
                case SettingDataType.String:

                    if (setting.RealName.Equals("AXIS_COM") || setting.RealName.Equals("AXIS_COM2"))
                    {
                        return(IniFilesSimple.WriteValue(setting.RealName, string.Format("socket {0}", ((string)setting.CurrentValue).Trim()), Path.Combine(DriverLocation, C3NET_CONFIG), ref exceptionMessage));
                    }
                    //This is a treatment for the previous case where the COM was a string type not a SerialPortSelection type setting
                    else if (setting.RealName.Equals("L10_COM"))
                    {
                        //The user is only able to modify the com port, not the speed, parity and other properties of the COM
                        return(IniFilesSimple.WriteValue(setting.RealName, string.Format("{0} 115200/8/1/0", ((string)setting.CurrentValue).Trim()), Path.Combine(DriverLocation, C3NET_CONFIG), ref exceptionMessage));
                    }
                    //For any other setting
                    else
                    {
                        return(IniFilesSimple.WriteValue(setting.RealName, (string)setting.CurrentValue, Path.Combine(DriverLocation, C3NET_CONFIG), ref exceptionMessage));
                    }

                case SettingDataType.SerialPortSelection:

                    //The user is only able to modify the com port, not the speed, parity and other properties of the COM
                    return(IniFilesSimple.WriteValue(setting.RealName, string.Format("{0} 115200/8/1/0", ((string)setting.CurrentValue).Trim()), Path.Combine(DriverLocation, C3NET_CONFIG), ref exceptionMessage));

                case SettingDataType.Int:
                    return(IniFilesSimple.WriteValue(setting.RealName, setting.CurrentValue.ToString(), Path.Combine(DriverLocation, C3NET_CONFIG), ref exceptionMessage));

                case SettingDataType.Bool:
                    return(IniFilesSimple.WriteValue(setting.RealName, setting.CurrentValue.ToString(), Path.Combine(DriverLocation, C3NET_CONFIG), ref exceptionMessage));

                default:
                    return(false);
                }
            }
            catch (Exception ex)
            {
                logger.Error(PAYMENT_LOG, string.Format("SetPaymentConfigSettings : Failed to write payment setting.\r\n{0}", ex.ToString()));
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update the settings in all the configuration files with the ones stored in the Account
        /// This method will be called when the a device is Set from Admin or when a device is loaded at Core startup
        /// </summary>
        /// <param name="configJson"></param>
        /// <param name="overwrite"></param>
        /// <returns></returns>
        public bool UpdateSettings(string configJson, bool overwrite = false)
        {
            string exceptionMessage = "";

            try
            {
                //Deserialize the config object to get access to the driver settings
                Payment payment = JsonConvert.DeserializeObject <Payment>(configJson);

                //Check if the config object is empty
                if (currentPaymentInitConfig != payment)
                {
                    //Save the settings
                    foreach (AdminPeripheralSetting paymentSetting in payment.ConfigurationSettings)
                    {
                        switch (paymentSetting.RealName)
                        {
                        case "Currency":
                            currency = paymentSetting;
                            break;

                        case "L10_COM":
                            //Update the c3config filed
                            if (!SetPaymentConfigSettings(paymentSetting, ref exceptionMessage))
                            {
                                logger.Info(PAYMENT_LOG, $"Failed to update c3config setting : {paymentSetting.ControlName}. {exceptionMessage}");
                                return(false);
                            }
                            comPort = paymentSetting;
                            break;

                        case "QTPV":
                            //Update the c3config filed
                            if (!SetPaymentConfigSettings(paymentSetting, ref exceptionMessage))
                            {
                                logger.Info(PAYMENT_LOG, $"Failed to update c3config setting : {paymentSetting.ControlName}. {exceptionMessage}");
                                return(false);
                            }
                            terminalID = paymentSetting;
                            break;

                        case "AXIS_COM":
                            //Update the c3config filed
                            if (!SetPaymentConfigSettings(paymentSetting, ref exceptionMessage))
                            {
                                logger.Info(PAYMENT_LOG, $"Failed to update c3config setting : {paymentSetting.ControlName}. {exceptionMessage}");
                                return(false);
                            }
                            first_server = paymentSetting;
                            break;

                        case "AXIS_COM2":
                            //Update the c3config filed
                            if (!SetPaymentConfigSettings(paymentSetting, ref exceptionMessage))
                            {
                                logger.Info(PAYMENT_LOG, $"Failed to update c3config setting : {paymentSetting.ControlName}. {exceptionMessage}");
                                return(false);
                            }
                            second_server = paymentSetting;
                            break;

                        case "REPOS_1":
                            //Update the c3config filed
                            if (!SetPaymentConfigSettings(paymentSetting, ref exceptionMessage))
                            {
                                logger.Info(PAYMENT_LOG, $"Failed to update c3config setting : {paymentSetting.ControlName}. {exceptionMessage}");
                                return(false);
                            }
                            messageLineOne = paymentSetting;
                            break;

                        case "REPOS_2":
                            //Update the c3config filed
                            if (!SetPaymentConfigSettings(paymentSetting, ref exceptionMessage))
                            {
                                logger.Info(PAYMENT_LOG, $"Failed to update c3config setting : {paymentSetting.ControlName}. {exceptionMessage}");
                                return(false);
                            }
                            messageLineTwo = paymentSetting;
                            break;

                        case "CARTES":
                            //Update the c3config filed
                            if (!SetPaymentConfigSettings(paymentSetting, ref exceptionMessage))
                            {
                                logger.Info(PAYMENT_LOG, $"Failed to update c3config setting : {paymentSetting.ControlName}. {exceptionMessage}");
                                return(false);
                            }
                            cardApplications = paymentSetting;
                            break;
                        }
                    }

                    //Update the c3config "VISA_RRP_DATA" filed with this new Value.
                    //This update it will not allow contact-less payments to be processed off-line(which we now can't do because of UK Law)
                    logger.Info(PAYMENT_LOG, "Updating c3config setting : VISA_RRP_DATA");

                    if (!IniFilesSimple.WriteValue("VISA_RRP_DATA", VISA_RRP_DATA_VALUE, Path.Combine(DriverLocation, C3NET_CONFIG), ref exceptionMessage))
                    {
                        logger.Info(PAYMENT_LOG, $"Failed to update c3config setting : VISA_RRP_DATA. \r\n {exceptionMessage}");
                        return(false);
                    }
                }
                //Return with failure if the payment config is empty
                else
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(PAYMENT_LOG, string.Format("Failed to initialize payment settings.\r\n{0}", ex.ToString()));
            }
            return(false);
        }