public string BillPayment(TransactionBillDTO transaction) { if (transaction != null) { try { string descoRefId = "DESCO" + Guid.NewGuid().ToString().Substring(0, 6); Payment payment = new Payment { TransactionId = transaction.TransactionId, AccountNumber = transaction.SenderAccNo, PaymentAmount = (decimal)transaction.Amount, CreatedOn = DateTime.Now }; Customer customer = _businessLayer.GetAllCustomers().Where(x => x.AccountNumber == transaction.SenderAccNo).SingleOrDefault(); var user = _businessLayer.GetAllBankUsers().Where(x => x.AccountNumber == transaction.SenderAccNo).FirstOrDefault(); if (customer != null) { payment.CustomerId = customer.Id; customer.TotalPaidAmount += (decimal)transaction.Amount; customer.TotalDueAmount -= (decimal)transaction.Amount; customer.EntityState = EntityState.Modified; _businessLayer.UpdateCustomer(customer); } else { Customer newCustomer = new Customer { AccountNumber = transaction.SenderAccNo, Name = user.AccountName, ContactNumber = user.ContactNo, TotalDueAmount = 10000, TotalPaidAmount = 500, EntityState = EntityState.Added }; _businessLayer.AddCustomer(newCustomer); payment.CustomerId = newCustomer.Id; } payment.EntityState = EntityState.Added; _businessLayer.AddPayment(payment); return(descoRefId); } catch (WebException ex) { return("Error: " + ex.ToString()); } } else { return("Transaction Object Can not be Null"); } }
public string TransactionBill([FromBody] string xmlData) { // creating object of CultureInfo CultureInfo cultures = new CultureInfo("en-US"); try { XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlData); #region data fetched from xml string txnId, amount, senderBIC, receiverBIC, senderAccNo, receiverAccNo, sendingBankRoutingNo, receivingBankRoutingNo, purpose = string.Empty; txnId = doc.GetElementsByTagName("TxId").Item(0).InnerText; amount = doc.GetElementsByTagName("IntrBkSttlmAmt").Item(0).InnerText; senderBIC = doc.GetElementsByTagName("BICFI").Item(0).InnerText; receiverBIC = doc.GetElementsByTagName("BICFI").Item(3).InnerText; senderAccNo = doc.GetElementsByTagName("Id").Item(0).InnerText; receiverAccNo = doc.GetElementsByTagName("Id").Item(8).InnerText; sendingBankRoutingNo = doc.GetElementsByTagName("Id").Item(2).InnerText; receivingBankRoutingNo = doc.GetElementsByTagName("Id").Item(5).InnerText; purpose = doc.GetElementsByTagName("Ustrd").Item(0).InnerText; DateTime txnDt = DateTime.Now; DateTime stlmntDt = DateTime.Now; #endregion #region data fetched from db for further operation var sender = _businessLayer.GetAllBankUsers().SingleOrDefault(m => m.AccountNumber == senderAccNo); var senderBank = _businessLayer.GetAllBanks().SingleOrDefault(m => m.SwiftBic == senderBIC); #endregion //DBManager db = new DBManager(transactionRepository, sendingBankUserRepository, receivingBankUserRepository, bankNetDebitCapRepository, suspenseTransactionRepository, bankRepository); //update Sending Bank Net Debit Cap var senderInstitutionDebitCap = _businessLayer.GetParticipantDebitCapById(senderBank.Id); senderInstitutionDebitCap.CurrentNetDebitCap -= System.Convert.ToDecimal(amount, cultures); senderInstitutionDebitCap.EntityState = EntityState.Modified; _businessLayer.UpdateParticipantDebitCap(senderInstitutionDebitCap); //create suspense transaction var suspenseTransaction = new SuspenseTransaction { SuspenseTransactionId = Guid.NewGuid(), SenderAccountNo = senderAccNo, SendingBankId = senderBank.Id, SendingBankSuspanseAccount = senderBank.SuspenseAccount, Amount = Convert.ToDecimal(amount, cultures), TransactionInitiatedOn = txnDt, SuspenseClearingTime = DateTime.Now, TransactionId = txnId, SuspenseStatus = false, EntityState = EntityState.Added }; _businessLayer.AddSuspenseTransaction(suspenseTransaction); TransactionRequestLog transactionRequestLog = new TransactionRequestLog(); List <TransactionRequestLog> logs = new List <TransactionRequestLog>(); var responseResult = string.Empty; var responseResultFromBB = string.Empty; var responseDesco = string.Empty; using (var client = new HttpClient()) { transactionRequestLog.TransactionId = txnId; transactionRequestLog.RequestFrom = "IDTP"; transactionRequestLog.RequestTo = "Desco"; transactionRequestLog.RequestMessage = xmlData; transactionRequestLog.RequestTime = DateTime.Now; transactionRequestLog.CreatedBy = "IDTP"; transactionRequestLog.CreatedOn = DateTime.Now; transactionRequestLog.ModifiedBy = "IDTP"; transactionRequestLog.ModifiedOn = DateTime.Now; transactionRequestLog.EntityState = EntityState.Added; //_businessLayer.AddTransactionRequestLog(transactionRequestLog); logs.Add(transactionRequestLog); TransactionBillDTO tbd = new TransactionBillDTO { TransactionId = txnId, SenderAccNo = senderAccNo, SenderBankId = senderBank.Id, Amount = decimal.Parse(amount, cultures) }; //receiver bank call //responseResult = HttpClientHelper.Post("https://*****:*****@"\", "", StringComparison.CurrentCulture); TransactionRequestLog transactionRequestLogReceive = new TransactionRequestLog { TransactionId = txnId, RequestFrom = "Desco", RequestTo = "IDTP", RequestMessage = xmlReturn, RequestTime = DateTime.Now, CreatedBy = "IDTP", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, ModifiedBy = "IDTP", EntityState = EntityState.Added }; //_businessLayer.AddTransactionRequestLog(transactionRequestLogReceive); logs.Add(transactionRequestLogReceive); _businessLayer.AddTransactionRequestLog(logs.ToArray()); return(xmlReturn); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <IActionResult> Create([FromForm] TransactionBillDTO tbd) { // creating object of CultureInfo try { CultureInfo cultures = new CultureInfo("en-US"); if (tbd != null) { #region fetch data db var sender = _businessLayer.GetAllBankUsers().Where(u => u.AccountNumber == tbd.SenderAccNo).FirstOrDefault(); if (sender == null) { TempData["error"] = "User Not Found"; return(RedirectToAction(nameof(Index))); } var SenderBank = _businessLayer.GetAllBanks().Where(b => b.Id == tbd.SenderBankId).FirstOrDefault(); var senderBranch = _businessLayer.GetAllBranchs().Where(br => br.Id == tbd.SenderBranchId).FirstOrDefault(); #endregion var senderBankRoutingNo = senderBranch.RoutingNumber; //var receiverBankRoutingNo = receiverBranch.RoutingNumber; var transactionId = SenderBank.SwiftBic.Substring(0, 4) + DateTime.Now.ToString("yyyyMMddHHmmss", cultures); #region create pacs008 xml //ISOComposer composer = new ISOComposer(); var pacs008xml = ISOComposer.GetPacs008Data(SenderBank.SwiftBic, "", sender.AccountName, tbd.ReceiverName, transactionId, tbd.SenderAccNo, senderBankRoutingNo, SenderBank.CbaccountNo, "", "", "", tbd.Amount.ToString(), "Bill Payment"); #endregion #region fetch data db sender.Balance -= tbd.Amount; sender.EntityState = EntityState.Modified; _businessLayer.UpdateBankUser(sender); #endregion #region get token for session //login as user LoginDTO loginDTO = new LoginDTO { UserName = Helper.Constants.UserName, MasterToken = Helper.Constants.UserSecret }; //get token string token = await HttpClientAuthorization.GetAuthorizationToken(loginDTO); HttpContext.Session.SetString("token", token); #endregion TransactionRequestLog transactionRequestLog = new TransactionRequestLog(); TransactionRequestLog transactionRequestLogReceive = new TransactionRequestLog(); List <TransactionRequestLog> logs = new List <TransactionRequestLog>(); var responseResult = string.Empty; //Uri uri = new Uri("https://localhost:44321/TransactionBill"); //var uri = "https://idtp-fundtransfer.azurewebsites.net/TransactionBill"; var uri = new Uri(Helper.Constants.IDTPApiGatewayUrl + "ft/TransactionBill"); using (var client = new HttpClient()) { transactionRequestLog.TransactionId = transactionId; transactionRequestLog.RequestFrom = SenderBank.FinancialInstitution.InstitutionName; transactionRequestLog.RequestTo = "IDTP"; transactionRequestLog.RequestMessage = pacs008xml.InnerXml; transactionRequestLog.RequestTime = DateTime.Now; transactionRequestLog.CreatedBy = SenderBank.FinancialInstitution.InstitutionName; transactionRequestLog.CreatedOn = DateTime.Now; transactionRequestLog.ModifiedBy = SenderBank.FinancialInstitution.InstitutionName; transactionRequestLog.ModifiedOn = DateTime.Now; transactionRequestLog.EntityState = EntityState.Added; logs.Add(transactionRequestLog); //_businessLayer.AddTransactionRequestLog(transactionRequestLog); //calling to IDTP API responseResult = HttpClientHelper.Post(uri, pacs008xml.InnerXml, token); } responseResult = responseResult.Replace("\\", "", StringComparison.CurrentCulture); responseResult = responseResult.Substring(1, responseResult.Length - 2); transactionRequestLogReceive.TransactionId = transactionId; transactionRequestLogReceive.RequestFrom = "IDTP"; transactionRequestLogReceive.RequestTo = SenderBank.FinancialInstitution.InstitutionName; transactionRequestLogReceive.RequestMessage = responseResult; transactionRequestLogReceive.RequestTime = DateTime.Now; transactionRequestLogReceive.CreatedBy = "IDTP"; transactionRequestLogReceive.CreatedOn = DateTime.Now; transactionRequestLogReceive.ModifiedBy = "IDTP"; transactionRequestLogReceive.ModifiedOn = DateTime.Now; transactionRequestLogReceive.EntityState = EntityState.Added; logs.Add(transactionRequestLogReceive); _businessLayer.AddTransactionRequestLog(logs.ToArray()); //responseResult = "<" + responseResult + ">"; XmlDocument doc = new XmlDocument(); doc.LoadXml(responseResult); TempData["txnId"] = doc.GetElementsByTagName("OrgnlTxId").Item(0).InnerText; } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { TempData["error"] = ex.Message; return(RedirectToAction(nameof(Index))); } }