Example #1
0
        public string Post([FromBody] string xmlData)
        {
            // creating object of CultureInfo
            CultureInfo cultures = new CultureInfo("en-US");

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlData);

            #region data fetched from xml
            string txnId, amount, senderBIC, receiverBIC, receiverAccNo, senderName, receiverName = 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;
            receiverAccNo = doc.GetElementsByTagName("Id").Item(8).InnerText;
            senderName    = doc.GetElementsByTagName("Nm").Item(0).InnerText;
            receiverName  = doc.GetElementsByTagName("Nm").Item(1).InnerText;
            #endregion


            var receiver = _businessLayer.GetAllBankUsers().Where(m => m.AccountNumber == receiverAccNo).FirstOrDefault();
            receiver.Balance    += Convert.ToDecimal(amount, cultures);
            receiver.EntityState = IDTPDomainModel.EntityState.Modified;
            _businessLayer.UpdateBankUser(receiver);

            //ISOComposer composer = new ISOComposer();
            //var pacs002xml = composer.GetDataForPacs002Single(senderBIC, receiverBIC, senderName,receiverName, txnId, amount);
            var       pacs002xml = ISOComposer.GetDataForPacs002Single(senderBIC, txnId, amount, "pacs.008.001.04");
            XDocument doc02      = new XDocument(pacs002xml);

            //return  doc02.Root.ToString();
            //return Regex.Unescape(pacs002xml.InnerXml);
            return(pacs002xml.OuterXml.Replace(@"\", "", StringComparison.CurrentCulture));
        }
        public string Post([FromBody] string xml)
        {
            // creating object of CultureInfo
            CultureInfo cultures = new CultureInfo("en-US");

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);

                #region data fetched from xml
                string amount, senderBIC, receiverBIC, receiverAccNo = 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(1).InnerText;
                //senderAccNo = doc.GetElementsByTagName("Id").Item(0).InnerText;
                //receiverAccNo = doc.GetElementsByTagName("Id").Item(2).InnerText;
                #endregion

                #region get data from DB
                //var transaction = businessLayer.GetAllTransactions().Where(x => x.TransactionId == txnId).FirstOrDefault();
                //var sender = businessLayer.GetAllBankUsers().Where(x => x.Id == transaction.SenderId).FirstOrDefault();
                //var recevier = businessLayer.GetAllBankUsers().Where(x => x.Id == transaction.ReceiverId).FirstOrDefault();
                //var senderName = businessLayer.GetAllTransactions().SingleOrDefault(m => m.TransactionId == txnId).Sender.AccountName;
                //var receiverName = businessLayer.GetAllTransactions().SingleOrDefault(m => m.TransactionId == txnId).Receiver.AccountName;
                //var senderName = sender.AccountName;
                //var receiverName = recevier.AccountName;

                #endregion

                var bank       = _businessLayer.GetBankBySwiftBic(senderBIC);
                var senderName = bank.FinancialInstitution.InstitutionName;
                //var receiverName = "";
                string txnId = "";
                Double.TryParse(amount, NumberStyles.Any, cultures, out double balance);
                BBSettlement settlement = new BBSettlement
                {
                    Id          = bank.Id,
                    Balance     = balance,
                    ModifiedOn  = DateTime.Now,
                    EntityState = EntityState.Modified
                };
                _businessLayer.UpdateBBSettlement(settlement);

                var transactionID = Guid.NewGuid().ToString();
                //ISOComposer composer = new ISOComposer();
                //var pacs002xml = composer.GetDataForPacs002Single(senderBIC, receiverBIC, senderName, receiverName, txnId, amount);
                var pacs002xml = ISOComposer.GetDataForPacs002Single(senderBIC, txnId, amount, "pacs.009.001.04");

                return(pacs002xml.InnerXml);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
                //return ex.Message;
            }
        }
        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 string PayGovtDues([FromBody] string xmlData)
        {
            var responseResult = string.Empty;
            // 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, amountStr, senderBIC, receiverBIC, senderAccNo, receiverAccNo, sendingBankRoutingNo, receivingBankRoutingNo,
                       otherInfo;
                txnId                  = doc.GetElementsByTagName("TxId").Item(0).InnerText;
                amountStr              = 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;
                otherInfo              = 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.GetAllIDTPUserEntities().SingleOrDefault(m => m.AccountNo == senderAccNo);
                var receiver = _businessLayer.GetAllIDTPUserEntities().SingleOrDefault(m => m.AccountNo == receiverAccNo);
                //var senderBank = _businessLayer.GetAllBanks().SingleOrDefault(m => m.SwiftBic == senderBIC);
                //var receiverBank = _businessLayer.GetAllBanks().SingleOrDefault(m => m.SwiftBic == receiverBIC);
                #endregion

                /* //update Sending Bank Net Debit Cap
                 * var senderInstitutionDebitCap = _businessLayer.GetParticipantDebitCapById(senderBank.Id);
                 * senderInstitutionDebitCap.NetDebitCap -= System.Convert.ToDecimal(amount);
                 * senderInstitutionDebitCap.EntityState = EntityState.Modified;
                 * _businessLayer.UpdateParticipantDebitCap(senderInstitutionDebitCap);*/
                //int deviceLocationInfoId = ParseDeviceLocationInfo.SaveInfo(doc);

                double.TryParse(amountStr, NumberStyles.Any, cultures, out double amount);

                string[] otherInfos = otherInfo.Split(',');
                string[] billInfos  = otherInfos[0].Split(':');

                GovtBillPayment govtBillPayment = new GovtBillPayment
                {
                    SenderId        = sender.Id,
                    ReceiverId      = receiver.Id,
                    Amount          = amount,
                    ReferenceNumber = txnId,
                    BillInfo        = billInfos[1],
                    OtherInfo       = otherInfo,
                    EntityState     = EntityState.Added
                };
                _businessLayer.AddGovtBillPayment(govtBillPayment);

                /*//update receiver bank net debit cap
                 * if (isSameBank)
                 * {
                 *  senderInstitutionDebitCap.NetDebitCap += System.Convert.ToDecimal(amount);
                 *  senderInstitutionDebitCap.EntityState = EntityState.Modified;
                 *  _businessLayer.UpdateParticipantDebitCap(senderInstitutionDebitCap);
                 * }
                 * else
                 * {
                 *  var receiverInstitutionDebitCap = _businessLayer.GetParticipantDebitCapById(receiverBank.Id);
                 *  receiverInstitutionDebitCap.NetDebitCap += System.Convert.ToDecimal(amount);
                 *  receiverInstitutionDebitCap.EntityState = EntityState.Modified;
                 *  _businessLayer.UpdateParticipantDebitCap(receiverInstitutionDebitCap);
                 *
                 * }*/

                //ISOComposer composer = new ISOComposer();
                var pacs002xml = ISOComposer.GetDataForPacs002Single(senderBIC, txnId, amountStr, "pacs.008.001.04");
                responseResult = pacs002xml.InnerXml.ToString();

                return(responseResult);
            }
            catch (Exception)
            {
                responseResult = IDTPXmlParser.PrepareFailResponse("PayGovtDues");
                return(responseResult);
            }
        }