public bool EditFee(Fee model) { bool result = false; try { var fee = _db.Get<Fee>().FirstOrDefault(x => x.Id==model.Id); if (fee != null) { fee.Name = model.Name; fee.FlatAmount = model.FlatAmount; fee.PercentageOfTransaction = model.PercentageOfTransaction; fee.Maximum = model.Maximum; fee.Minimum = model.Minimum; result = _db.Update(fee); _db.Commit(); } else { throw new Exception("This Fee Does Not Exist"); } return result; } catch (Exception ex) { _db.Rollback(); throw; } }
public bool CreateFee(Fee model) { bool result =false; try { var fee = _db.Get<Fee>().FirstOrDefault(x => x.Name == model.Name); if(fee==null) { fee = new Fee { Name=model.Name, FlatAmount=model.FlatAmount, PercentageOfTransaction= model.PercentageOfTransaction, Maximum= model.Maximum, Minimum= model.Minimum }; result = _db.Add(fee); } else { throw new Exception("Fee With this Name Already Exist"); } return result; } catch (Exception) { _db.Rollback(); throw; } }
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; } }
private double CalculateFee(Fee fee, double amount) { double feeCharged = 0.0; if (fee.FlatAmount > 0) { feeCharged = Convert.ToDouble(fee.FlatAmount); } else { double perOfTransaction = (Convert.ToDouble(fee.PercentageOfTransaction) * 0.01); feeCharged = amount * perOfTransaction; if (feeCharged > fee.Maximum) { feeCharged = fee.Maximum; } if (feeCharged < fee.Minimum) { feeCharged = fee.Minimum; } } Console.WriteLine("feeCharged is: " + feeCharged + "\n"); return feeCharged; }