private void ClientPeerOnReceive(object sender, ReceiveEventArgs e)
        {
            var clientPeer = sender as ClientPeer;

            Logger.Log("Client Peer Receiving>>> " + clientPeer.Name);

            Iso8583Message receivedMessage = e.Message as Iso8583Message;
            SinkNode       theSinkNode;

            try
            {
                var theSender = sender as ClientPeer;
                theSinkNode = new SinkNodeManager().GetById(Convert.ToInt32(theSender.Name));
            }
            catch (Exception)
            {
                Logger.Log(String.Format("Message from Unknown Sink Node: {0}", receivedMessage));
                receivedMessage.SetResponseMessageTypeIdentifier();
                receivedMessage.Fields.Add(39, "91");   //Issuer inoperative
                clientPeer.Send(receivedMessage);
                return;
            }

            bool isValidMti;

            if (receivedMessage == null)
            {
                return;
            }
            string mtiDescription = MessageDefinition.GetMtiDescription(receivedMessage.MessageTypeIdentifier, "FEP", out isValidMti);

            if (!isValidMti)
            {
                Logger.Log(String.Format("Invalid MTI response code {0}, {1}", receivedMessage, theSinkNode));  // work on this
                clientPeer.Send(receivedMessage);

                return;
            }

            string responseCode        = receivedMessage.Fields[39].ToString();
            string responseDescription = MessageDefinition.GetResponseDescription(responseCode);
            string stan = receivedMessage.Fields[11].ToString();

            clientPeer.Send(receivedMessage);
        }
Exemple #2
0
        public static void LogTransaction(Iso8583Message msg, SourceNode srcNode = null, bool needReversal = false)
        {
            var    transactionTypeCode = msg.Fields[MessageField.TRANSACTION_TYPE_FIELD].ToString().Substring(0, 2);
            var    channelCode         = msg.Fields[MessageField.CHANNEL_ID_FIELD].ToString().Substring(0, 1);
            var    cardPan             = msg.Fields[MessageField.CARD_PAN_FIELD].ToString();
            string responseCode        = string.Empty;      //the response to send back is not yet known
            var    transmissionDate    = DateTime.UtcNow;
            string originalDataElement = msg.Fields.Contains(MessageField.ORIGINAL_DATA_ELEMENT_FIELD) ? msg.Fields[MessageField.ORIGINAL_DATA_ELEMENT_FIELD].ToString() : string.Empty;

            //int originalDataElementLength = originalDataElement.Length;

            try
            {
                Transaction transactionToLog = new Transaction();
                transactionToLog.MTI                 = msg.MessageTypeIdentifier.ToString();
                transactionToLog.CardPan             = msg.Fields[MessageField.CARD_PAN_FIELD].ToString();
                transactionToLog.STAN                = msg.Fields[MessageField.STAN_FIELD].ToString();
                transactionToLog.Amount              = Convert.ToDecimal(msg.Fields[MessageField.AMOUNT_FIELD].ToString());
                transactionToLog.ChannelCode         = msg.Fields[MessageField.CHANNEL_ID_FIELD].ToString();
                transactionToLog.ChannelCode         = channelCode;
                transactionToLog.TransactionTypeCode = transactionTypeCode;
                transactionToLog.SourceNode          = srcNode;
                transactionToLog.Date                = transmissionDate;
                transactionToLog.OriginalDataElement = originalDataElement.TrimStart('0');      //removes all leading zeros


                if (msg.Fields.Contains(MessageField.TRANSACTION_FEE_FIELD))
                {
                    transactionToLog.TransactionFee = Convert.ToDecimal(msg.Fields[MessageField.TRANSACTION_FEE_FIELD].ToString());
                }
                if (msg.Fields.Contains(MessageField.PROCESSING_FEE_FIELD))
                {
                    transactionToLog.ProcessingFee = Convert.ToDecimal(msg.Fields[MessageField.PROCESSING_FEE_FIELD].ToString());
                }


                if (msg.Fields.Contains(MessageField.RESPONSE_FIELD))
                {
                    responseCode = msg.Fields[MessageField.RESPONSE_FIELD].Value.ToString();
                }

                transactionToLog.ResponseCode        = responseCode;
                transactionToLog.ResponseDescription = MessageDefinition.GetResponseDescription(responseCode);
                transactionToLog.Account1            = msg.Fields[MessageField.FROM_ACCOUNT_ID_FIELD].ToString();
                transactionToLog.Account2            = msg.Fields[MessageField.TO_ACCOUNT_ID_FIELD].ToString();
                transactionToLog.IsReversePending    = needReversal;

                if (msg.MessageTypeIdentifier == MTI.REVERSAL_ADVICE_RESPONSE && responseCode == "00")   //successful reversal
                {
                    transactionToLog.IsReversed = true;
                }
                try
                {
                    new TransactionDAO().Insert(transactionToLog);
                    MessageLogger.LogMessage("Transaction logged! -> ODE= " + transactionToLog.OriginalDataElement + " Amount: " + transactionToLog.Amount + " Date: " + transactionToLog.Date);
                }
                catch (Exception ex)
                {
                    MessageLogger.LogError("Transaction log failed! " + ex.Message + "   Inner Exception:  " + ex.InnerException);
                }
            }
            catch (Exception ex)
            {
                MessageLogger.LogError("Transaction log failed " + ex.Message + "   Inner Exception:  " + ex.InnerException);
            }
        }
Exemple #3
0
        public static void LogTransaction(Iso8583Message incomingMessage, SourceNode sourceNode = null, Scheme scheme = null, Fee fee = null, bool needReversal = false)
        {
            var      instCode            = incomingMessage.Fields[2].ToString().Substring(0, 6);
            string   transactionTypeCode = (incomingMessage.Fields[3].ToString().Substring(0, 2));
            string   channelCode         = incomingMessage.Fields[123].ToString().Substring(13, 2);
            string   cardPan             = incomingMessage.Fields[2].ToString();
            string   response            = string.Empty;
            string   responseCode        = string.Empty;
            DateTime transmissionDate    = DateTime.UtcNow;

            TransactionLog transactionLog = new TransactionLog();

            try
            {
                transactionLog.MTI     = incomingMessage.MessageTypeIdentifier.ToString();
                transactionLog.STAN    = incomingMessage.Fields[11].ToString();
                transactionLog.Amount  = Convert.ToDouble(incomingMessage.Fields[4].ToString());
                transactionLog.CardPAN = cardPan;
                var channel = new ChannelManager().GetByCode(channelCode);
                if (channel != null)
                {
                    transactionLog.Channel = channel.Name;
                }
                var trnx = new TransactionTypeManager().GetByCode(transactionTypeCode);
                if (trnx != null)
                {
                    transactionLog.TransactionType = trnx.Name;
                }
                transactionLog.SourceNode      = sourceNode.Name;
                transactionLog.TransactionDate = transmissionDate;
                transactionLog.DateCreated     = DateTime.Now;
                transactionLog.DateModified    = DateTime.Now;

                string orDataElt = incomingMessage.Fields[90].ToString();
                int    length    = orDataElt.Length;
                transactionLog.OriginalDataElement = orDataElt.Length > 19 ? orDataElt.Remove(0, (length - 19)) : orDataElt;

                try
                {
                    responseCode = incomingMessage.Fields[39].Value.ToString();
                }
                catch (Exception) { }


                if (scheme != null)
                {
                    transactionLog.Scheme = scheme.Name;
                    transactionLog.Route  = scheme.Route.Name;

                    transactionLog.SinkNode = scheme.Route.SinkNode.Name;
                }

                try
                {
                    string  value  = incomingMessage.Fields[28].Value.ToString();
                    decimal result = 0;
                    if (Decimal.TryParse(value, out result))
                    {
                        transactionLog.Charge = result;
                    }
                }
                catch (Exception) { }
                if (fee != null)
                {
                    transactionLog.Fee = fee.Name;
                }
                if (responseCode != null)
                {
                    transactionLog.ResponseCode = responseCode;
                }
                if (responseCode != null)
                {
                    transactionLog.ResponseDescription = MessageDefinition.GetResponseDescription(responseCode);
                }
                string acc1 = incomingMessage.Fields[102].Value.ToString();
                string acc2 = incomingMessage.Fields[103].Value.ToString();
                transactionLog.Account1         = acc1;
                transactionLog.Account2         = acc2;
                transactionLog.IsReversePending = needReversal;

                if (incomingMessage.MessageTypeIdentifier.ToString() == "430" && responseCode == "00")
                {
                    transactionLog.IsReversed = true;
                    // SetReversalStatus(incomingMsg, responseCode);  //here
                }

                if (new TransactionLogManager().AddTransactionLog(transactionLog))
                {
                    Log("Transaction log::: " + transactionLog.STAN + " " + transactionLog.TransactionDate);
                }
                else
                {
                    Log("Transaction log::: not successful");
                }
            }
            catch (Exception ex)
            {
                Log("Error occurred while logging transaction \n" + ex.Message);
                Console.ForegroundColor = ConsoleColor.Red;
            }
        }