Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public Result Init(RuntimeConfiguration configuration)
        {
            Log.Info("Init method started...");

            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 ComConcertApi())
                {
                    var connectResult = api.Connect(configuration.Port);
                    if (connectResult != COMConcertLibrary.ConcertErrMsg.None)
                    {
                        Log.Debug($"Connect result: {connectResult}");
                        return(ResultCode.GenericError);
                    }

                    var disconnectResult = api.Disconnect();
                    if (disconnectResult != COMConcertLibrary.ConcertErrMsg.None)
                    {
                        Log.Debug($"Disconnect result: {disconnectResult}");
                        return(ResultCode.GenericError);
                    }

                    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.");
            }
        }
Example #2
0
        private void Beat(object state)
        {
            var configuration = RuntimeConfiguration.Instance;

            if (configuration == null)
            {
                return;
            }

            try
            {
                using (var api = new ComConcertApi())
                {
                    var connectResult = api.Connect(configuration.Port);
                    if (connectResult != COMConcertLibrary.ConcertErrMsg.None)
                    {
                        Alive = false;
                        Log.Debug($"Connect result: {connectResult}");
                        return;
                    }

                    var disconnectResult = api.Disconnect();
                    if (disconnectResult != COMConcertLibrary.ConcertErrMsg.None)
                    {
                        Alive = false;
                        Log.Debug($"Disconnect result: {disconnectResult}");
                        return;
                    }

                    Alive = true;
                }
            }
            finally
            {
                Log.Debug($"Heartbeat status: {Alive}");
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="amount"></param>
        /// <returns></returns>
        public Result <PaymentData> Pay(int amount)
        {
            Log.Info("Pay method started...");

            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 ComConcertApi())
                {
                    var connectResult = api.Connect(config.Port);
                    Log.Info($"Connect Result: {connectResult}");
                    if (connectResult != COMConcertLibrary.ConcertErrMsg.None)
                    {
                        return(new Result <PaymentData>((ResultCode)connectResult));
                    }

                    var payResult = api.Pay(amount, 120000, config.ForceOnline, out var payResponse);
                    Log.Info($"Pay Result: {payResult}");
                    Log.Info($"Pay Response Data: {payResponse.responseData}");
                    if (payResult != COMConcertLibrary.ConcertErrMsg.None)
                    {
                        return(new Result <PaymentData>((ResultCode)payResult));
                    }

                    data.Result     = (PaymentResult)payResponse.getTransactionStatus();
                    data.PaidAmount = amount;

                    XNode ticketDocument = null;
                    var   ticketResult   = api.Ticket(120000, out var ticketResponse);
                    Log.Info($"Ticket Result: {ticketResult}");
                    if (ticketResult == COMConcertLibrary.ConcertErrMsg.None)
                    {
                        if (ticketResponse.getTransactionStatus() != COMConcertLibrary.ConcertTxnStatus.TxnCancelled)
                        {
                            ticketDocument = XDocument.Parse(ticketResponse.nonConcertData);

                            var transactionInfo = RetrieveInfo(ticketDocument);

                            if (transactionInfo.IsSignatureVerified)
                            {
                                Log.Info("This transaction requires signature. We will reverse it");
                                var revResult = api.Reverse(transactionInfo.Number, 120000, out var revResponse);
                                return(new Result <PaymentData>(ResultCode.TransactionCancelled, data: data));
                            }

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

                    PersistTransaction(payResponse, ticketDocument);

                    var disconnectResult = api.Disconnect();
                    Log.Info($"Disconnect Result: {disconnectResult}");
                }

                Log.Info("Payment succeeded.");

                return(new Result <PaymentData>(ResultCode.Success, data: data));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(ResultCode.GenericError);
            }
            finally
            {
                Log.Info("Pay method finished.");
            }
        }