Exemplo n.º 1
0
        public Iso8583Message PerformReversal(Iso8583Message message, out bool doReversal)
        {
            Console.WriteLine("Performing Reversal ... ");
            doReversal = true;
            bool needReversal = false;

            string cardBIN = message.Fields[2].Value.ToString().Substring(0, 6);


            Route route = new RouteLogic().GetRouteByBIN(cardBIN);

            if (route != null)
            {
                if (route.SinkNode != null)
                {
                    Console.WriteLine("Routing to Sink - " + route.SinkNode.IPAddress + ":" + route.SinkNode.Port);
                    RouteToDestination(message, route.SinkNode, out needReversal);
                }
            }

            return(message);
        }
Exemplo n.º 2
0
        public Iso8583Message ProcessMessage(Iso8583Message message, SourceNode sourceNode)
        {
            var    field41    = message.Fields[41].Value.ToString();
            var    terminalID = field41.Substring(1, field41.Length - 1);
            string cardBIN    = message.Fields[2].Value.ToString().Substring(0, 6);

            Console.WriteLine("Processing ...");
            if (!terminalID.Equals(IsoMessageFieldDefinitions.TERMINAL_ID.ToString()))
            {
                Console.WriteLine("THIS IS A NOT-ON-US TRANSACTION");
            }
            else
            {
                if (cardBIN.Equals(IsoMessageFieldDefinitions.INSTITUTION_BIN.ToString()))
                {
                    Console.WriteLine("THIS IS AN ON-US TRANSACTION");
                }
                else
                {
                    Console.WriteLine("THIS IS A REMOTE-ON-US TRANSACTION");
                }
            }
            if (message.MessageTypeIdentifier != 420)
            {
                message = AddOriginalDataElement(message);
            }
            //            SourceNode sourceNode = new EntityLogic<SourceNode>().GetByID(sourceID);
            bool returnMsg;

            message = CheckMessageType(message, sourceNode, out returnMsg);

            if (returnMsg == true)
            {
                return(message);
            }

            Iso8583Message responseMessage;
            string         expiryDate = message.Fields[14].Value.ToString();
            DateTime       cardExpiry = ParseDate(expiryDate);

            if (cardExpiry < DateTime.Now)
            {
                //expired card
                responseMessage = SetResponseMessage(message, "54");
                new TransactionLogProcessing().LogTransaction(responseMessage);
                return(responseMessage);
            }

            Console.WriteLine("Getting TrxCode ...");
            string transactionTypeCode = message.Fields[3].Value.ToString().Substring(0, 2);

            Console.WriteLine("Getting Amount ...");
            double amount = ConvertIsoAmountToDouble(message.Fields[4].Value.ToString());

            if (transactionTypeCode != "31" && amount <= 0)
            {
                responseMessage = SetResponseMessage(message, "13");
                new TransactionLogProcessing().LogTransaction(responseMessage);
                return(responseMessage);
            }

            // GETTING ROUTE

            Console.WriteLine("Getting BIN ...");
//            string cardBIN = message.Fields[2].Value.ToString().Substring(0, 6);

            Console.WriteLine("Getting Route ...");
            Route route = new RouteLogic().GetRouteByBIN(cardBIN);

            if (route == null)
            {
                responseMessage = SetResponseMessage(message, "15");
                new TransactionLogProcessing().LogTransaction(responseMessage);
                return(responseMessage);
            }

            if (route.SinkNode == null || route.SinkNode.Status == "In-active")
            {
                Console.WriteLine("Sink Node is null");
                responseMessage = SetResponseMessage(message, "91");
                new TransactionLogProcessing().LogTransaction(responseMessage);
                return(responseMessage);
            }

            //GETTING SCHEME

            Scheme scheme;

            try

            {
                Console.WriteLine("Getting Scheme ...");
                scheme = SwitchData.GetSchemeByRoute(route, transactionTypeCode);
            }
            catch (Exception e)
            {
                responseMessage = SetResponseMessage(message, "06");
                new TransactionLogProcessing().LogTransaction(responseMessage);
                return(responseMessage);
            }

            if (scheme == null)
            {
                responseMessage = SetResponseMessage(message, "58");
                new TransactionLogProcessing().LogTransaction(responseMessage);
                //new TransactionLogLogic().LogMessage(responseMessage);
                return(responseMessage);
            }

            Console.WriteLine("Getting TrxType ...");
            TransactionType transactionType = new TransactionTypeLogic().GetTransactionTypebyCode(transactionTypeCode);

            Console.WriteLine("Getting Channel ...");
            string channelCode = message.Fields[41].Value.ToString().Substring(0, 1);

            Channel channel = new ChannelLogic().GetChannelByCode(channelCode);

            Fee fee = GetFee(transactionType, channel, scheme);

            if (fee == null)
            {
                responseMessage = SetResponseMessage(message, "58");
                new TransactionLogProcessing().LogTransaction(responseMessage);
                return(responseMessage);
            }

            double?fees = CalculateFee(fee, amount);

            message = SetFee(message, fees);

            //BY NOW ALL CHECKS HAVE BEEN DONE , TIME TO SEND TO SINK NODE

            bool needReversal = false;

            Console.WriteLine("Routing To Destination ...");
            responseMessage = RouteToDestination(message, route.SinkNode, out needReversal);


            return(responseMessage);
        }