private void Beat(object state)
        {
            var configuration = RuntimeConfiguration.Instance;

            if (configuration == null)
            {
                return;
            }

            try
            {
                using (var api = new BarclayCardSmartpayApi())
                {
                    Alive = true;
                }
            }
            finally
            {
                Log.Debug($"Heartbeat status: {Alive}");
            }
        }
Пример #2
0
        /// <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);
                }

                using (var api = new BarclayCardSmartpayApi())
                {
                    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.");
            }
        }
Пример #3
0
        /// <summary>
        /// Payment method
        /// </summary>
        /// <param name="amount"></param>
        /// <returns></returns>
        public Result <PaymentData> Pay(int amount, string transactionRef)
        {
            Log.Info("Payment method started...");
            Log.Info($"Amount = {amount / 100.0}.");
            Log.Info($"Transaction Reference  = {transactionRef}.");
            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);
                }

                if (transactionRef == string.Empty)
                {
                    Log.Info("Transaction reference is empty");
                    return(ResultCode.GenericError);
                }

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


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

                using (var api = new BarclayCardSmartpayApi())
                {
                    var payResult = api.Pay(amount, transactionRef, out TransactionReceipts payReceipts);
                    Log.Info($"Pay Result: {payResult}");


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

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

                    //}

                    if (payResult != DiagnosticErrMsg.OK)
                    {
                        Log.Error($"Pay Result = {payResult} Payment Failed...See Stored Ticket and Logs ");
                        data.Result = PaymentResult.Failed;

                        PrintErrorTicket(data);

                        return(new Result <PaymentData>((ResultCode)payResult, data: data));
                    }
                    else

                    if (payResult == DiagnosticErrMsg.OK)
                    {
                        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}");


                        //persist the Merchant transaction
                        PersistTransaction(payReceipts.MerchantReturnedReceipt, "MERCHANT");

                        CreateTicket(payReceipts.CustomerReturnedReceipt, "CUSTOMER");

                        data.HasClientReceipt   = true;
                        data.HasMerchantReceipt = true;
                    }
                }


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