/// <summary>
        /// Get the configuratiion data
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public Result Init(RuntimeConfiguration configuration)
        {
            Log.Info("Init method started...");

            //initalise confguration file instance
            var configFile = AppConfiguration.Instance;

            try
            {
                if (configuration == null)
                {
                    Log.Info("Can not set configuration to null.");
                    return(ResultCode.GenericError);
                }

                if (configuration.PosNumber <= 0)
                {
                    Log.Info($"Invalid PosNumber {configuration.PosNumber}.");
                    return(ResultCode.GenericError);
                }

                //if (configuration.Port == string.Empty)
                //{
                //    Log.Info($"Invalid Port {configuration.Port}.");
                //    return ResultCode.GenericError;
                //}


                using (var api = new GuardianApi())
                {
                    RuntimeConfiguration.Instance = configuration;
                    Heartbeat.Instance.Start();
                    Log.Info("Init success!");

                    return(ResultCode.Success);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(ResultCode.GenericError);
            }
            finally
            {
                Log.Info("Init method finished.");
            }
        }
        private void Beat(object state)
        {
            var configuration = RuntimeConfiguration.Instance;

            if (configuration == null)
            {
                return;
            }

            try
            {
                using (var api = new GuardianApi())
                {
                    Alive = true;
                }
            }
            finally
            {
                Log.Debug($"Heartbeat status: {Alive}");
            }
        }
        /// <summary>
        /// Payment method
        /// </summary>
        /// <param name="amount"></param>
        /// <returns></returns>
        public Result <PaymentData> Pay(int amount)
        {
            Log.Info("Pay method started...");
            Log.Info($"Amount = {amount/100.0}.");
            Result <PaymentData> transactionResult = null;
            string reciept = string.Empty;

            try
            {
                if (File.Exists(ticketPath))
                {
                    File.Delete(ticketPath);
                }

                if (amount <= 0)
                {
                    Log.Info("Invalid pay amount...");
                    return(ResultCode.GenericError);
                }

                var config = RuntimeConfiguration.Instance;
                var data   = new PaymentData();

                Log.Info("Calling payment driver...");

                using (var api = new GuardianApi())
                {
                    var payResult = api.Pay(amount, out TransactionInfo payResponse);
                    Log.Info($"Pay Result: {payResult}");


                    // interogate the result check if payResponse not equal to null

                    if (payResponse == null)
                    {
                        Log.Error("Transaction response error...");
                        data.Result = PaymentResult.Failed;
                        PrintErrorTicket(data, string.Empty);
                        return(new Result <PaymentData>((ResultCode)payResult, data: data));
                    }
                    else

                    if (payResult != DiagnosticErrMsg.OK && payResponse != null)
                    {
                        Log.Error($"Pay Result = {payResult} Payment Failed...");
                        data.Result = PaymentResult.Failed;

                        PrintErrorTicket(data, payResponse.CustomerReceipt);

                        return(new Result <PaymentData>((ResultCode)payResult, data: data));
                    }
                    else
                    {
                        data.Result = PaymentResult.Successful;

                        data.PaidAmount = amount;

                        Log.Info($"paid Amount: {data.PaidAmount}");
                        transactionResult = new Result <PaymentData>(ResultCode.Success, data: data);
                        Log.Info($"Payment succeeded transaction result: {transactionResult}");

                        CreateCustomerTicket(payResponse);
                        data.HasClientReceipt = true;
                    }

                    //persist the transaction
                    //PersistTransaction(payResponse);
                }


                return(transactionResult);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(ResultCode.GenericError);
            }
            finally
            {
                Log.Info("Pay method finished...");
            }
        }