public SourceNodeManager() { _db = new SourceNodeDAO(); }
public static Iso8583Message ProcessIncommingMessage(int sourceId, Iso8583Message originalMessage) { SourceNode sourceNode = new SourceNodeDAO().GetById(sourceId); //Configure Original Data Element DateTime transmissionDate = DateTime.UtcNow; //Configuring the original data element (intended for transaction matching (e.g. to identify a transaction for correction or reversal) //consists of 5 data elements: MTI (1-4), STAN (5-10), Date&Time (11-20), AcquirerInsttutionCode (21-31), ForwardingInstCode(32-42) string transactionDate = string.Format("{0}{1}", string.Format("{0:00}{1:00}", transmissionDate.Month, transmissionDate.Day), string.Format("{0:00}{1:00}{2:00}", transmissionDate.Hour, transmissionDate.Minute, transmissionDate.Second)); //string originalDataElement = $"{originalMessage.MessageTypeIdentifier}{originalMessage.Fields[11]}{transactionDate}"; string originalDataElement = originalMessage.MessageTypeIdentifier.ToString() + originalMessage.Fields[11] + transactionDate; //if the originalDataElement is empty (for non-reversal), add it if (!(originalMessage.Fields.Contains(MessageField.ORIGINAL_DATA_ELEMENT_FIELD))) { originalMessage.Fields.Add(MessageField.ORIGINAL_DATA_ELEMENT_FIELD, originalDataElement); } MessageLogger.LogMessage("Validating message..."); //check if it's a reversal message if (originalMessage.MessageTypeIdentifier == MTI.REVERSAL_ADVICE || originalMessage.MessageTypeIdentifier == MTI.REPEAT_REVERSAL_ADVICE) { MessageLogger.LogMessage("\nReversal message!"); //confirm that this transaction actually needs to be reversed bool isReversal; Iso8583Message reversalMessage = GetReversalMessage(originalMessage, out isReversal); if (!isReversal) { MessageLogger.LogMessage("Invalid Reversal transaction"); return(reversalMessage); } //continue if it's a reversal message originalMessage = reversalMessage; } string cardPan = originalMessage.Fields[MessageField.CARD_PAN_FIELD].ToString(); decimal amount = Convert.ToDecimal(originalMessage[MessageField.AMOUNT_FIELD].Value); //The amount is in kobo string channelCode = originalMessage.Fields[MessageField.CHANNEL_ID_FIELD].Value.ToString().Substring(0, 2); string tTypeCode = originalMessage.Fields[MessageField.TRANSACTION_TYPE_FIELD].Value.ToString().Substring(0, 2); //first two positions for the transaction type string expiryDate = originalMessage.Fields[MessageField.EXPIRY_DATE_FIELD].Value.ToString(); DateTime expiryDateOfCard = ConvertToDateTime(expiryDate); Iso8583Message responseMessage; //rsponse message to return after performing some checks if (expiryDateOfCard <= DateTime.Now) //card expired { responseMessage = SetReponseMessage(originalMessage, ResponseCode.EXPIRED_CARD.ToString()); MessageLogger.LogMessage("Expired card"); return(responseMessage); } //check the amount, only for balance enq should the amount be zero if (amount <= 0 && tTypeCode != TransactionTypeCode.BALANCE_ENQUIRY.ToString()) { responseMessage = SetReponseMessage(originalMessage, ResponseCode.INVALID_AMOUNT.ToString()); //Invalid amount MessageLogger.LogMessage("Invalid Amount"); return(responseMessage); } Combo theCombo = null; Scheme theScheme = null; var sourceNodeSchemes = sourceNode.Schemes; string pan = originalMessage.Fields[MessageField.CARD_PAN_FIELD].Value.ToString(); var route = new RouteDAO().GetByCardBIN(pan.Substring(0, 6)); if (route == null) { MessageLogger.LogMessage("Route is null."); responseMessage = SetReponseMessage(originalMessage, ResponseCode.ROUTING_ERROR.ToString()); return(responseMessage); } //get the sourcenode by the route theScheme = sourceNodeSchemes.Where(s => s.Route.ID == route.ID).FirstOrDefault(); if (theScheme == null) { MessageLogger.LogMessage("No such secheme"); responseMessage = SetReponseMessage(originalMessage, ResponseCode.TRANSACTION_NOT_PERMITTED_ON_TERMINAL.ToString()); return(responseMessage); } theCombo = theScheme.Combos.Where(c => c.TransactionType.Code.Equals(tTypeCode) && c.Channel.Code.Equals(channelCode)).FirstOrDefault(); if (theCombo == null) //of course, scheme also = null { MessageLogger.LogMessage("Invalid transaction type-channel-fee combo"); responseMessage = SetReponseMessage(originalMessage, ResponseCode.TRANSACTION_NOT_PERMITTED_ON_TERMINAL.ToString()); // Transaction not allowed on terminal return(responseMessage); } var sinkNnode = route.SinkNode; if (sinkNnode == null) { MessageLogger.LogMessage("Sink node is null."); responseMessage = SetReponseMessage(originalMessage, ResponseCode.ISSUER_OR_SWITCH_INOPERATIVE.ToString()); return(responseMessage); } //At this point, everything is assumed to be okay Fee fee = theCombo.Fee; if (fee == null) { MessageLogger.LogMessage("Unacceptable transaction fee"); responseMessage = SetReponseMessage(originalMessage, ResponseCode.UNACCEPTABLE_TRANSACTION_FEE.ToString()); // Transaction type not allowed in this scheme return(responseMessage); } //calculate the transaction fee and embed in the message originalMessage = SetTransactionFee(originalMessage, ComputeFee(fee, amount)); var clientPeer = Program.ClientPeers.Where(p => p.Name.Equals(theScheme.Route.SinkNode.ID.ToString())).FirstOrDefault(); if (clientPeer == null) { MessageLogger.LogMessage("Clientpeer is null"); originalMessage = SetReponseMessage(originalMessage, ResponseCode.ISSUER_OR_SWITCH_INOPERATIVE.ToString()); return(originalMessage); } //////// Iso8583Message replyFromFEP = SendMessageToFEP(clientPeer, originalMessage); //sends message to the client return(replyFromFEP); }
public IndexUI() { SourceNodeDAO sourceNodeDAO = new SourceNodeDAO(); AddSection() .StretchFields(50) .WithTitle("Search Source Nodes") .IsCollapsible() .IsFramed() .WithColumns(new List <Column>() { new Column(new List <IField>() { Map(x => x.Name).AsSectionField <TextBox>().TextFormatIs("^[ a-zA-Z]+$") }), new Column(new List <IField>() { Map(x => x.IpAddress).AsSectionField <TextBox>().TextFormatIs(@"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$") }), new Column(new List <IField>() { Map(x => x.Port).AsSectionField <TextBox>().TextFormatIs(@"^(6553[0-5]|655[0-2][0-9]|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})$") }), new Column(new List <IField>() { //Map(x=> x.Status).AsSectionField<DropDownList>() // .Of(Enum.GetValues(typeof(NodeStatus)).Cast<NodeStatus>().ToList()) // .ListOf(x => x.ToString(), x => x) // .LabelTextIs("Status"), AddSectionButton() .ApplyMod <IconMod>(x => x.WithIcon(Ext.Net.Icon.Magnifier)) .WithText("Search") .UpdateWith(x => { return(x); }) }) }); HasMany(x => x.AllSourceNodes) .As <Grid>() .ApplyMod <IconMod>(x => x.WithIcon(Ext.Net.Icon.Link)) .ApplyMod <ViewDetailsMod>(y => y.Popup <DetailsUI>("Source Node Details") .PrePopulate <SourceNode, SourceNode>(x => x)) .Of <SourceNode>() .WithColumn(x => x.Name) .WithColumn(x => x.HostName) .WithColumn(x => x.IpAddress) .WithColumn(x => x.Port) .WithColumn(x => x.Status) .WithColumn(x => x.NodeType) .WithRowNumbers() .IsPaged <ViewSourceNodeUIModel>(10, (x, e) => { int totalCount = 0; try { var results = String.IsNullOrEmpty(x.Name) && String.IsNullOrEmpty(x.Port.ToString()) && String.IsNullOrEmpty(x.IpAddress) ? new SourceNodeDAO().Get() : new SourceNodeDAO().Search(x, e.Start, e.Limit, out totalCount, a => a.Name.ToLower().Contains(x.Name.ToLower()) || a.IpAddress.Contains(x.IpAddress) || a.Port == x.Port); //var results = String.IsNullOrEmpty(x.Name) ? new SourceNodeDAO().Get() : new SourceNodeDAO().Search(x, e.Start, e.Limit, out totalCount, a => a.Name.ToLower().Contains(x.Name.ToLower())); x.AllSourceNodes = results.ToList(); } catch (Exception ex) { string msg = "Message= " + ex.Message + " Inner Exception= " + ex.InnerException; MessageLogger.LogError(msg); } e.TotalCount = totalCount; return(x); }) .LabelTextIs("Source Nodes"); }
public SourceNodeManager(SourceNodeDAO db) { _db = db; }
public AddUI() { string errorMsg = ""; WithTitle("Add new Source Node"); AddSection() .WithFields(new List <IField>() { Map(x => x.Name).AsSectionField <TextBox>() .WithLength(20) .LabelTextIs("Node Name") .Required() .TextFormatIs("^[ a-zA-Z]+$"), Map(x => x.HostName).AsSectionField <TextBox>() .WithLength(30) .LabelTextIs("Host Name") .Required() .TextFormatIs(@"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"), Map(x => x.IpAddress).AsSectionField <TextBox>() .WithLength(12) .LabelTextIs("IP Address") .Required() .TextFormatIs(@"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"), Map(x => x.Port).AsSectionField <TextBox>() .Required() .TextFormatIs(@"^(6553[0-5]|655[0-2][0-9]|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})$"), // \d = [0-9] HasMany(x => x.Schemes).AsSectionField <MultiSelect>() .Of <Scheme>(() => { return(new SchemeDAO().Get().ToList()); }) .WithColumn(x => x.Name) .WithColumn(x => x.Route.Name, "Route") .WithColumn(x => x.Description) .ListOf(x => x.Name, x => x.ID).WithEditableText() .LabelTextIs("Schemes").Required(), AddSectionButton() .ApplyMod <IconMod>(x => x.WithIcon(Ext.Net.Icon.Disk)) .WithText("Add") .SubmitTo(x => { bool flag = false; try { //check for uniqueness SourceNodeDAO sourceNodeDao = new SourceNodeDAO(); if (!sourceNodeDao.isUniqueName(x.Name)) { errorMsg += "Name must be unique"; flag = false; } else if (!sourceNodeDao.isUniqueHostName(x.HostName)) { errorMsg += "Host name must be unique"; flag = false; } else if (!sourceNodeDao.isUniqueIpAddress(x.IpAddress)) { errorMsg += "IP address must be unique"; flag = false; } else if (!sourceNodeDao.isUniquePort(x.Port)) { errorMsg += "Port must be unique"; flag = false; } else { SourceNode sourceNode = new SourceNode { DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = x.Name, HostName = x.HostName, Port = x.Port, IpAddress = x.IpAddress, NodeType = NodeType.Server, Status = NodeStatus.Active, Schemes = x.Schemes }; new SourceNodeDAO().Insert(sourceNode); flag = true; } } catch (Exception ex) { errorMsg += "An error occured"; string logMsg = "Message= " + ex.Message + " Inner Exception= " + ex.InnerException; MessageLogger.LogError(logMsg); } return(flag); //Success }) .OnSuccessDisplay(x => { return(x.Name + "Node added successfully."); }) .OnFailureDisplay(x => { return("Unable to add Node\n" + errorMsg); }) .OnSuccessRedirectTo("/sourcenodemanagement/add") }); }
public EditUI() { string msg = ""; string errorMsg = String.Empty; AddSection() .IsFramed() .WithTitle("Edit Source Node") .WithColumns(new List <Column> { new Column( new List <IField> { Map(x => x.Name).AsSectionField <TextBox>().Required().TextFormatIs(TextFormat.name).WithLength(30), Map(x => x.HostName).AsSectionField <TextBox>().Required().TextFormatIs(@"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"), Map(x => x.IpAddress).AsSectionField <TextBox>().Required().TextFormatIs(@"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"), Map(x => x.Port).AsSectionField <TextBox>().Required().TextFormatIs(@"^(6553[0-5]|655[0-2][0-9]|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})$"), Map(x => x.ID).AsSectionField <TextLabel>().ApplyMod <VisibilityMod>(m => m.Hide <SourceNode>(h => { return(true); })), Map(x => x.Status).AsSectionField <DropDownList>() .Of(Enum.GetValues(typeof(NodeStatus)).Cast <NodeStatus>().ToList()) .ListOf(x => x.ToString(), x => x) .Required() .LabelTextIs("Status"), Map(x => x.Schemes).AsSectionField <MultiSelect>() .Of <Scheme>(() => { return(new SchemeDAO().Get().ToList()); }) .WithColumn(x => x.Name, "Scheme") .WithColumn(x => x.Route.Name, "Route") //.WithColumn(x => x.Combos.Count(), "No. of combos") .ListOf(x => x.Name, x => x.ID) .LabelTextIs("Schemes"), }), }) .WithFields(new List <IField> { AddSectionButton() .SubmitTo(x => { try { SourceNodeDAO sourceNodeDAO = new SourceNodeDAO(); SourceNode sourceNode = sourceNodeDAO.GetById(x.ID); //check for uniqueness if (!sourceNodeDAO.isUniqueName(sourceNode.Name, x.Name)) { //errorMsg = "Sink node's name must be unique"; errorMsg = String.Format("Source Node Name {0} is Unique. Use Another", x.Name); msg += "Source node's name must be unique"; return(false); } if (!sourceNodeDAO.isUniqueHostName(sourceNode.HostName, x.HostName)) { msg += "Host name must be unique"; return(false); } if (!sourceNodeDAO.isUniquePort(sourceNode.Port, x.Port)) { msg += "Sink node's Port must be unique"; return(false); } if (!sourceNodeDAO.isUniqueIpAddress(sourceNode.IpAddress, x.IpAddress)) { msg += "IP Address must be unique"; return(false); } sourceNode.Name = x.Name; sourceNode.HostName = x.HostName; sourceNode.IpAddress = x.IpAddress; sourceNode.Port = x.Port; sourceNode.Status = x.Status; sourceNode.NodeType = x.NodeType; sourceNode.Schemes = x.Schemes; sourceNode.DateModified = DateTime.Now; sourceNodeDAO.Update(sourceNode); return(true); } catch (Exception ex) { msg += "An error occured"; string logMsg = "Message= " + ex.Message + " Inner Exception= " + ex.InnerException; MessageLogger.LogError(logMsg); return(false); } }) .ConfirmWith(s => String.Format("Update Source Node {0} ", s.Name)).WithText("Update") .OnSuccessDisplay(s => String.Format("Source Node \"{0}\" has been successfuly editted ", s.Name)) .OnFailureDisplay(s => String.Format("Error editting!\n {0} ", msg)) }); }