diff --git a/Business/App.config b/Business/App.config index 4c6fbcf..b6404a1 100644 --- a/Business/App.config +++ b/Business/App.config @@ -45,9 +45,7 @@ - + \ No newline at end of file diff --git a/Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs b/Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs index 199bcca..c1ac201 100644 --- a/Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs +++ b/Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs @@ -2,6 +2,7 @@ using Common.Utility; using GMENepal.GMENepalAPIService; using log4net; +using TPApiServices.SendMNRemit.Services; using TPService.GCC.Services; using Unity; @@ -26,7 +27,11 @@ namespace Business.BusinessLogic.TPApiServices.Factory log.Debug("Choose Provider as GCC "); apiFactory = _container.Resolve(); } - + else if (providerNo == GetStatic.ReadWebConfig("sendMN", "")) + { + log.Debug("Choose Provider as SENDMN "); + apiFactory = _container.Resolve(); + } return apiFactory; } } diff --git a/Common/Models/StaticData.cs b/Common/Models/StaticData.cs index 4983cba..5e61110 100644 --- a/Common/Models/StaticData.cs +++ b/Common/Models/StaticData.cs @@ -8,6 +8,7 @@ namespace Common.Models public string CountryIsoCode { get; set; } public string Type { get; set; } public string MethodName { get; set; } + public string ControlNo { get; set; } } public class PurposeOfRemitance diff --git a/TPServices/App.config b/TPServices/App.config index 2e3fcb4..2ca70db 100644 --- a/TPServices/App.config +++ b/TPServices/App.config @@ -1,7 +1,7 @@ - + - + @@ -12,28 +12,26 @@ - + - - + + - - + + - - + + - - + + diff --git a/TPServices/SendMNRemit/Model/SendMNModel.cs b/TPServices/SendMNRemit/Model/SendMNModel.cs new file mode 100644 index 0000000..f73efbe --- /dev/null +++ b/TPServices/SendMNRemit/Model/SendMNModel.cs @@ -0,0 +1,183 @@ +using Common.Models.RequestResponse; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TPApiServices.SendMNRemit.Model +{ + public class SendMNModel + { + public string AgentCode { get; set; } + public string AuthKey { get; set; } + public string UserName { get; set; } + } + + public class SendMNAuthResponsetModel + { + public string Code { get; set; } + public string Message { get; set; } + public string ProcessIdentifier { get; set; } + + public Detail Detail { get; set; } + // public string Detail { get; set; } + } + public class Detail + { + public string ProcessIdentifier { get; set; } + public string Token { get; set; } + public string Note { get; set; } + public string ForexSSessionId { get; set; } + public string PartnerTranNo { get; set; } + public string PaymentMethod { get; set; } + public string SendingAmount { get; set; } + public string SendingCurrency { get; set; } + public string SendingCountry { get; set; } + public string ReceivingAmount { get; set; } + public string ReceivingCurrency { get; set; } + public string ReceivingCountry { get; set; } + public string ExRate { get; set; } + public string ControlNo { get; set; } + public string PaidDate { get; set; } + public string Status { get; set; } + public DateTime ExpiryTime { get; set; } + public string Rate { get; set; } + public string ForexSession { get; set; } + } + + + + + public class SendMNStatusRequestModel + { + public string ProcessIdentifier { get; set; } + public string Token { get; set; } + public string Note { get; set; } + public Body Body{ get; set; } + public string Signature { get; set; } + } + + public class SendExRateRequestModel + { + + public string ProcessIdentifier { get; set; } + + public string Signature { get; set; } + public string SendingCountry { get; set; } + public string ReceivingCurrency { get; set; } + public string ReceivingCountry { get; set; } + public string RequestBy { get; set; } + public Body Body { get; set; } + } + + + + + public class Body + { + public string ControlNo { get; set; } + + public Sender Sender { get; set; } + public Receiver Receiver { get; set; } + + public Detail Detail { get; set; } + public string SendingCountry { get; set; } + public string ReceivingCountry { get; set; } + public string ReceivingCurrency { get; set; } + } + + public class SendMNSendTransactionRequestModel + { + public string ProcessIdentifier { get; set; } + public string Signature { get; set; } + public Body Body { get; set; } + + } + //public class SendMNExRateRequestModel + //{ + // public string ProcessIdentifier { get; set; } + // public string Signature { get; set; } + // public Body Body { get; set; } + + //} + public class SendMNSendTransactionResponseModel + { + public Detail Detail { get; set; } + //public Data Data { get; set; } + public string Code { get; set; } + public object Msg { get; set; } + public object Message { get; set; } + } + public class SendMNExRateResponseModel + { + public Detail Detail { get; set; } + + + //public Data Data { get; set; } + public string Code { get; set; } + public string Msg { get; set; } + public string Message { get; set; } + } + + + + public class Sender + { + public string TransferReason { get; set; } + public string FundSource { get; set; } + public string FirstName { get; set; } + public string MiddleName { get; set; } + public string LastName { get; set; } + public string NativeCountry { get; set; } + public string City { get; set; } + public string Address { get; set; } + public string IdType { get; set; } + public string idNumber { get; set; } + public string Mobile { get; set; } + public string Email { get; set; } + + } + + public class Receiver + { + public string Bank { get; set; } + public string AccountNo { get; set; } + public string Relation { get; set; } + public string FirstName { get; set; } + public string MiddleName { get; set; } + public string LastName { get; set; } + public string NativeCountry { get; set; } + public string City { get; set; } + public string Address { get; set; } + public string Mobile { get; set; } + + + } + + public class SendMNGetAccountNameModel + { + public string ProcessIdentifier { get; set; } + public string Signature { get; set; } + public string AccountNo { get; set; } + public string BankCode { get; set; } + } + public class SendMNGResponseNameModel + { + public string ResponseCode { get; set; } + public string Data { get; set; } + public string Msg { get; set; } + } + + public class SendMNStatusResponseModel + { + public string ResponseCode { get; set; } + public string Data { get; set; } + public string Msg { get; set; } + public string Code { get; set; } + public string Message { get; set; } + public Detail Detail { get; set; } + } + + +} diff --git a/TPServices/SendMNRemit/Services/SendMNAPI.cs b/TPServices/SendMNRemit/Services/SendMNAPI.cs new file mode 100644 index 0000000..17d9abb --- /dev/null +++ b/TPServices/SendMNRemit/Services/SendMNAPI.cs @@ -0,0 +1,677 @@ +using Common.Models; +using Common.Models.Bank_Account; +using Common.Models.ExchangeRate; +using Common.Models.RequestResponse; +using Common.Models.Status; +using Common.Models.TxnModel; +using Common.TPService; +using Common.Utility; +using log4net; +using Newtonsoft.Json; +using RestSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using TPApiServices.SendMNRemit.Model; + +namespace TPApiServices.SendMNRemit.Services +{ + public class SendMNAPI : ITPApiServices + { + + private readonly ILog _log = LogManager.GetLogger(typeof(SendMNAPI)); + protected string baseUrl { get; set; } + protected string userName { get; set; } + protected string authKey { get; set; } + protected string agentCode { get; set; } + + public SendMNAPI() + { + baseUrl = GetStatic.ReadWebConfig("sendmn_base_url", ""); + userName = GetStatic.ReadWebConfig("sendmn_user_name", ""); + authKey = GetStatic.ReadWebConfig("sendmn_auth_key", ""); + agentCode = GetStatic.ReadWebConfig("sendmn_agent_code", ""); + } + + public TPResponse GetTPResponse(T model, string MethodName) where T : class + { + switch (MethodName) + { + //case "exRate": + // return GetExRate(model as SendExRateRequestModel); + case "send": + return SendTransaction(model as SendTransaction); + + case "verify": + return AccountVerifySendMN(model as AccountValidate); + + case "status": + return GetStatusSendMN(model as GetStatus); + + case "staticData": + return GetStaticData(model as StaticData); + + default: + throw new NotImplementedException(); + } + } + private SendMNAuthResponsetModel GetToken(string user) + { + SendMNAuthResponsetModel tokenResponse = new SendMNAuthResponsetModel(); + try + { + var requestBody = new SendMNModel + { + AgentCode = agentCode, + AuthKey = authKey, + UserName = userName + }; + var client = new RestClient(baseUrl); + var request = new RestRequest("/Authentication", Method.POST); + + request.AddHeader("Content-Type", "application/json"); + request.AddHeader("UserName", userName); + request.AddHeader("AgentCode", agentCode); + request.AddHeader("AuthKey", authKey); + + request.RequestFormat = DataFormat.Json; + request.AddJsonBody(requestBody); + + _log.Info($"SENDMNAPI|GETTOKEN|REQUEST URL: {client.BaseUrl}{request.Resource}"); + _log.Info($"SENDMNAPI|GETTOKEN|REQUEST HEADERS: {JsonConvert.SerializeObject(request.Parameters.Where(p => p.Type == ParameterType.HttpHeader).Select(p => new { p.Name, p.Value }))}"); + _log.Info($"SENDMNAPI|GETTOKEN|REQUEST BODY: {JsonConvert.SerializeObject(requestBody)}"); + + + var response = client.Execute(request); + + tokenResponse = response.Data; + //tokenResponse = response.ProcessIdentifier; + + + + if (tokenResponse != null && tokenResponse.Code == "0") + { + + tokenResponse.Detail.ExpiryTime = DateTime.UtcNow.AddMinutes(90); + _log.Info($"SENDMNAPI|GETTOKEN|RESPONSE : {JsonConvert.SerializeObject(tokenResponse)}"); + } + else + { + _log.Error($"SENDMNAPI|GETTOKEN|ERROR RESPONSE : {JsonConvert.SerializeObject(tokenResponse)}"); + } + } + catch (Exception ex) + { + tokenResponse = new SendMNAuthResponsetModel + { + Code = "999", + Detail = new Detail { Note = ex.ToString() } + }; + _log.Error($"SENDMNAPI|GETTOKEN|EXCEPTION OCCURRED : {JsonConvert.SerializeObject(tokenResponse)}"); + } + + return tokenResponse; + } + + + private TPResponse GetExRate(SendExRateRequestModel model) + { + var exResponse = new TPResponse(); + + try + { + // Get token + SendMNAuthResponsetModel tokenResponse = GetToken(model.RequestBy); + + if (tokenResponse.Code != "0") + { + exResponse.ResponseCode = "1"; + exResponse.Msg = tokenResponse.Detail.Note; + _log.Error($"SENDMNAPI|EXRATE.GETTOKEN()|RESPONSE : {JsonConvert.SerializeObject(exResponse)}"); + return exResponse; + } + + + var body = new SendExRateRequestModel + { + Body = new Body + { + + SendingCountry = "UK", + ReceivingCountry = "MN", + ReceivingCurrency = "MNT" + + }, + Signature = "", // Placeholder for the generated signature + ProcessIdentifier = tokenResponse.Detail.ProcessIdentifier + }; + + // Generate signature using the constructed body and token response + string signature = GenerateSignatureExRate(body, tokenResponse); + + // Assign the generated signature to the body + body.Signature = signature; + + _log.Info($"SENDMNAPI|EXRATE|REQUEST BODY : {JsonConvert.SerializeObject(body)}"); + + // Send request + var client = new RestClient(baseUrl); + var request = new RestRequest("/CalculateExRate", Method.POST) + { + RequestFormat = DataFormat.Json + }; + + request.AddHeader("Content-Type", "application/json"); + request.AddHeader("Authorization", "Bearer " + tokenResponse.Detail.Token); + request.AddHeader("UserName", userName); + request.AddHeader("AgentCode", agentCode); + request.AddJsonBody(body); + + var response = client.Execute(request); + + //_log.Info($"SENDMNAPI|EXRATE|RESPONSE : {response.Content}"); + + // _log.Info($"SENDMNAPI|EXRATE|RESPONSE : {response.Content} | ResponseCode: {exResponse.ResponseCode}, Id: {exResponse.Id}, Extra: {exResponse.Extra}"); + // Process response + //_log.Info($"SENDMNAPI|EXRATE|RESPONSE : {response.Content} | ResponseCode: {exRateResponse.Code}, Id: {exRateResponse.Detail.ForexSession}, Extra: {exRateResponse.Detail.Rate}"); + var exRateResponse = response.Data; + _log.Info($"SENDMNAPI|EXRATE|RESPONSE : {response.Content} | ResponseCode: {exRateResponse.Code}, Id: {exRateResponse.Detail.ForexSession}, Extra: {exRateResponse.Detail.Rate}"); + + if (exRateResponse.Code == "0") + { + exResponse.ResponseCode = "0"; + exResponse.Id = exRateResponse.Detail.ForexSession; + exResponse.Extra = exRateResponse.Detail.Rate; + } + else + { + exResponse.ResponseCode = "1"; + exResponse.Extra = exRateResponse.Code; + } + + exResponse.Msg = exRateResponse.Msg ?? exRateResponse.Message; + exResponse.Data = exRateResponse; + } + catch (Exception ex) + { + exResponse.ResponseCode = "999"; + exResponse.Msg = ex.ToString(); + _log.Error($"SENDMNAPI|SENDTRANSACTION|EXCEPTION OCCURRED|RESPONSE : {JsonConvert.SerializeObject(exResponse)}"); + } + + return exResponse; + } + + + + public TPResponse SendTransaction(SendTransaction model) + { + TPResponse txnResponse = new TPResponse(); + txnResponse.ResponseCode = "1"; + txnResponse.Msg = "Error sending transaction to partner!"; + + try + { + var exRateResponse = GetExRate(new SendExRateRequestModel + { + RequestBy = model.RequestBy, + }); + + if (exRateResponse.ResponseCode != "0") + { + txnResponse.ResponseCode = "1"; + txnResponse.Msg = exRateResponse.Msg; + + _log.Error($"SENDMNAPI|SENDTRANSACTION.GETEXRATE()|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}"); + return txnResponse; + } + + // If exchange rate retrieval was successful, proceed with sending the transaction + var tokenResponse = GetToken(model.RequestBy); + + if (tokenResponse == null || tokenResponse.Code != "0") + { + txnResponse.ResponseCode = "1"; + txnResponse.Msg = tokenResponse?.Detail?.Note ?? "Token response is null"; + + _log.Error($"SENDMNAPI|SENDTRANSACTION.GETTOKEN()|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}"); + return txnResponse; + } + + // Update the model with exchange rate details + model.Transaction.FOREX_SESSION_ID = exRateResponse.Id; + model.Transaction.ExRate = decimal.Parse(exRateResponse.Extra); + + var requestBody = MapSendTxnDetails(model); + if (requestBody == null) + { + txnResponse.ResponseCode = "1"; + txnResponse.Msg = "Request body mapping failed"; + + _log.Error($"SENDMNAPI|SENDTRANSACTION.MAPSENDTXNDETAILS()|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}"); + return txnResponse; + } + + requestBody.ProcessIdentifier = tokenResponse.Detail.ProcessIdentifier; + requestBody.Signature = GenerateSignature(requestBody, tokenResponse); + + _log.Info($"SENDMNAPI|SENDTRANSACTION|REQUEST BODY : {JsonConvert.SerializeObject(requestBody)}"); + + var client = new RestClient(baseUrl); + var request = new RestRequest("/sendTxn", Method.POST); + + request.AddHeader("Content-Type", "application/json"); + request.AddHeader("Authorization", "Bearer " + tokenResponse.Detail.Token); + request.AddHeader("UserName", userName); + request.AddHeader("AgentCode", agentCode); + + request.RequestFormat = DataFormat.Json; + request.AddJsonBody(requestBody); + + var TxnResponse = client.Execute(request); + + if (TxnResponse == null || TxnResponse.Data == null) + { + txnResponse.ResponseCode = "1"; + txnResponse.Msg = "Transaction response is null"; + + _log.Error($"SENDMNAPI|SENDTRANSACTION.EXECUTE()|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}"); + return txnResponse; + } + + var sendTxnResponse = TxnResponse.Data; + _log.Info($"SENDMNAPI|SENDTRANSACTION|RESPONSE : {TxnResponse.Content}"); + + if (sendTxnResponse.Code == "0") + { + txnResponse.ResponseCode = "0";//success + txnResponse.Id = sendTxnResponse.Detail.ControlNo; + txnResponse.Extra = exRateResponse.Extra; + } + else + { + txnResponse.ResponseCode = "1";//failed + txnResponse.Extra = sendTxnResponse.Code; + } + + txnResponse.Msg = sendTxnResponse.Msg as string ?? sendTxnResponse.Message as string; + txnResponse.Data = sendTxnResponse; + } + catch (Exception ex) + { + txnResponse.ResponseCode = "999"; + txnResponse.Msg = ex.ToString(); + + _log.Error($"SENDMNAPI|SENDTRANSACTION|EXCEPTION OCCURED|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}"); + } + + return txnResponse; + } + + + + private TPResponse GetStaticData(StaticData model) + { + TPResponse statusResponse = new TPResponse(); + statusResponse.ResponseCode = "1"; + statusResponse.Msg = "Error fetching transaction status!"; + try + { + var tokenResponse = GetToken(model.RequestBy); + + if (tokenResponse.Code != "0") + { + statusResponse.ResponseCode = "1"; + statusResponse.Msg = tokenResponse.Detail.Note; + + _log.Error($"SENDMNAPI|GETSTATUSSENDMN.GETTOKEN()|RESPONSE : {JsonConvert.SerializeObject(statusResponse)}"); + return statusResponse; + } + + var requestBody = new SendMNStatusRequestModel { Body = new Body { ControlNo = model.ControlNo } }; + requestBody.ProcessIdentifier = tokenResponse.Detail.ProcessIdentifier; + requestBody.Signature = GenerateSignatureStatus(requestBody, tokenResponse); + + _log.Info($"SENDMNAPI|GETSTATUSSENDMN|REQUEST BODY : {JsonConvert.SerializeObject(requestBody)}"); + + var client = new RestClient(baseUrl); + var request = new RestRequest("/CheckStatusTxn", Method.POST); + + request.AddHeader("Content-Type", "application/json"); + request.AddHeader("Authorization", "Bearer " + tokenResponse.Detail.Token); + request.AddHeader("UserName", userName); + request.AddHeader("AgentCode", agentCode); + + request.RequestFormat = DataFormat.Json; + request.AddJsonBody(requestBody); + + var getStatusResponse = client.Execute(request).Data; + + _log.Info($"SENDMNAPI|GETSTATUSSENDMN|RESPONSE : {JsonConvert.SerializeObject(getStatusResponse)}"); + + statusResponse.ResponseCode = getStatusResponse.Code; + statusResponse.Msg = getStatusResponse.Message; + + if (getStatusResponse.Code == "0") + { + statusResponse.Id = getStatusResponse.Detail.ControlNo; + statusResponse.Extra = getStatusResponse.Detail.PartnerTranNo; + statusResponse.Extra2 = getStatusResponse.Detail.Status; + + statusResponse.Extra3 = string.IsNullOrEmpty(getStatusResponse.Detail.PaidDate) ? "" : getStatusResponse.Detail.PaidDate; + } + statusResponse.Data = getStatusResponse; + } + catch (Exception ex) + { + statusResponse.ResponseCode = "999"; + statusResponse.Msg = ex.ToString(); + + _log.Error($"SENDMNAPI|GETSTATUSSENDMN|EXCEPTION OCCURED|RESPONSE : {JsonConvert.SerializeObject(statusResponse)}"); + } + return statusResponse; + } + private TPResponse GetStatusSendMN(GetStatus model) + { + TPResponse statusResponse = new TPResponse(); + statusResponse.ResponseCode = "1"; + statusResponse.Msg = "Error fetching transaction status!"; + try + { + var tokenResponse = GetToken(model.RequestBy); + + if (tokenResponse.Code != "0") + { + statusResponse.ResponseCode = "1"; + statusResponse.Msg = tokenResponse.Detail.Note; + + _log.Error($"SENDMNAPI|GETSTATUSSENDMN.GETTOKEN()|RESPONSE : {JsonConvert.SerializeObject(statusResponse)}"); + return statusResponse; + } + + var requestBody = new SendMNStatusRequestModel { Body = new Body { ControlNo = model.ControlNo } }; + requestBody.ProcessIdentifier = tokenResponse.Detail.ProcessIdentifier; + requestBody.Signature = GenerateSignatureStatus(requestBody, tokenResponse); + + _log.Info($"SENDMNAPI|GETSTATUSSENDMN|REQUEST BODY : {JsonConvert.SerializeObject(requestBody)}"); + + var client = new RestClient(baseUrl); + var request = new RestRequest("/CheckStatusTxn", Method.POST); + + request.AddHeader("Content-Type", "application/json"); + request.AddHeader("Authorization", "Bearer " + tokenResponse.Detail.Token); + request.AddHeader("UserName", userName); + request.AddHeader("AgentCode", agentCode); + + request.RequestFormat = DataFormat.Json; + request.AddJsonBody(requestBody); + + var getStatusResponse = client.Execute(request).Data; + + _log.Info($"SENDMNAPI|GETSTATUSSENDMN|RESPONSE : {JsonConvert.SerializeObject(getStatusResponse)}"); + + statusResponse.ResponseCode = getStatusResponse.Code; + statusResponse.Msg = getStatusResponse.Message; + + if (getStatusResponse.Code == "0") + { + statusResponse.Id = getStatusResponse.Detail.ControlNo; + statusResponse.Extra = getStatusResponse.Detail.Status; + statusResponse.Extra2 = getStatusResponse.Detail.PartnerTranNo; + + statusResponse.Extra3 = string.IsNullOrEmpty(getStatusResponse.Detail.PaidDate) ? "" : getStatusResponse.Detail.PaidDate; + } + statusResponse.Data = getStatusResponse; + } + catch (Exception ex) + { + statusResponse.ResponseCode = "999"; + statusResponse.Msg = ex.ToString(); + + _log.Error($"SENDMNAPI|GETSTATUSSENDMN|EXCEPTION OCCURED|RESPONSE : {JsonConvert.SerializeObject(statusResponse)}"); + } + return statusResponse; + + } + + private TPResponse AccountVerifySendMN(AccountValidate model) + { + TPResponse accountResponse = new TPResponse(); + accountResponse.ResponseCode = "1"; + accountResponse.Msg = "Error fetching account details!"; + try + { + var tokenResponse = GetToken(model.RequestBy); + + if (tokenResponse.Code != "0") + { + accountResponse.ResponseCode = "1"; + accountResponse.Msg = tokenResponse.Detail.Note; + + _log.Error($"SENDMNAPI|ACCOUNTVERIFYSENDMN.GETTOKEN()|RESPONSE : {JsonConvert.SerializeObject(accountResponse)}"); + return accountResponse; + } + + var requestBody = new SendMNGetAccountNameModel { AccountNo = model.AccountNumber, BankCode = model.BankCode }; + requestBody.ProcessIdentifier = tokenResponse.Detail.ProcessIdentifier; + requestBody.Signature = GenerateSignatureAccName(requestBody, tokenResponse); + + _log.Info($"SENDMNAPI|ACCOUNTVERIFYSENDMN|REQUEST BODY : {JsonConvert.SerializeObject(requestBody)}"); + + var client = new RestClient(baseUrl); + var request = new RestRequest("/Common/getAccountName", Method.POST); + + request.AddHeader("Content-Type", "application/json"); + request.AddHeader("Authorization", "Bearer " + tokenResponse.Detail.Token); + request.AddHeader("UserName", userName); + request.AddHeader("AgentCode", agentCode); + + request.RequestFormat = DataFormat.Json; + request.AddJsonBody(requestBody); + + var accountDetailsResponse = client.Execute(request); + var getAccountDetailsResponse = accountDetailsResponse.Data; + + _log.Info($"SENDMNAPI|ACCOUNTVERIFYSENDMN|RESPONSE : {accountDetailsResponse.Content}"); + + accountResponse.ResponseCode = getAccountDetailsResponse.ResponseCode; + accountResponse.Msg = "Success"; + + if (getAccountDetailsResponse.ResponseCode == "SUCCESS") + { + accountResponse.ResponseCode = "0"; + accountResponse.Extra = getAccountDetailsResponse.Data; + accountResponse.Extra2 = model.AccountNumber; + } + else + { + accountResponse.ResponseCode = "1"; + accountResponse.Msg = $"{getAccountDetailsResponse.ResponseCode} - {getAccountDetailsResponse.Msg}"; + } + accountResponse.Data = getAccountDetailsResponse; + } + catch (Exception ex) + { + accountResponse.ResponseCode = "999"; + accountResponse.Msg = ex.ToString(); + + _log.Error($"SENDMNAPI|ACCOUNTVERIFYSENDMN|EXCEPTION OCCURED|RESPONSE : {JsonConvert.SerializeObject(accountResponse)}"); + } + return accountResponse; + } + + public SendMNSendTransactionRequestModel MapSendTxnDetails(SendTransaction model) + { + return new SendMNSendTransactionRequestModel + { + Body = new Body + { + Sender = new Sender + { + TransferReason = model.Transaction.PurposeOfRemittanceName, + FundSource = model.Sender.SourceOfFund, + FirstName = model.Sender.SFirstName, + MiddleName = model.Sender.SMiddleName, + LastName = model.Sender.SLastName1, + NativeCountry = model.Sender.SNativeCountry, + City = model.Sender.SCityId, + Address = model.Sender.SCityId, + IdType = model.Sender.SIdType, + idNumber = model.Sender.SIdNo, + Mobile = model.Sender.SMobile, + Email = model.Sender.SEmail + }, + Receiver = new Receiver + { + Bank = model.Agent.PBankId,//"MGO394687", + AccountNo = model.Receiver.UnitaryBankAccountNo,//"5431109819", + Relation = model.Receiver.RelWithSenderName, + FirstName = model.Receiver.RFirstName, + MiddleName = model.Receiver.RMiddleName, + LastName = model.Receiver.RLastName, + NativeCountry = model.Receiver.RNativeCountry, + City = model.Receiver.RCity, + Address = model.Receiver.RAdd1, + Mobile = model.Receiver.RMobile + }, + Detail = new Detail + { + ForexSSessionId = model.Transaction.FOREX_SESSION_ID, + PartnerTranNo = model.Transaction.JMEControlNo, + PaymentMethod = model.Transaction.PaymentType, + SendingAmount = Convert.ToString(model.Transaction.TAmt), + SendingCurrency = model.Transaction.CollCurr, + SendingCountry = "UK",//model.Sender.SCountryName, + ReceivingAmount = Convert.ToString(model.Transaction.PAmt), + ReceivingCurrency = "MNT",//model.Transaction.PCurr, + ReceivingCountry = "MN",//model.Receiver.RCountry, + ExRate = Convert.ToString(model.Transaction.ExRate) + } + } + }; + } + + + + private string GenerateSignature(SendMNSendTransactionRequestModel body, SendMNAuthResponsetModel token) + { + string hashValue = ""; + string textToEncrypt = userName + agentCode + body.Body.Sender.TransferReason + body.Body.Sender.FundSource + body.Body.Sender.FirstName + body.Body.Sender.MiddleName + + body.Body.Sender.LastName + body.Body.Sender.NativeCountry + body.Body.Sender.City + body.Body.Sender.Address + body.Body.Sender.IdType + body.Body.Sender.idNumber + + body.Body.Sender.Mobile + body.Body.Sender.Email + body.Body.Receiver.Bank + body.Body.Receiver.AccountNo + body.Body.Receiver.Relation + body.Body.Receiver.FirstName + + body.Body.Receiver.MiddleName + body.Body.Receiver.LastName + body.Body.Receiver.NativeCountry + body.Body.Receiver.City + body.Body.Receiver.Address + + body.Body.Receiver.Mobile + body.Body.Detail.ForexSSessionId + body.Body.Detail.PartnerTranNo + body.Body.Detail.PaymentMethod + body.Body.Detail.SendingAmount + + body.Body.Detail.SendingCurrency + body.Body.Detail.SendingCountry + body.Body.Detail.ReceivingAmount + body.Body.Detail.ReceivingCurrency + body.Body.Detail.ReceivingCountry + + body.Body.Detail.ExRate + token.Detail.ProcessIdentifier; + + using (MD5 md5 = MD5.Create()) + { + byte[] inputBytes = Encoding.UTF8.GetBytes(textToEncrypt); + byte[] hashBytes = md5.ComputeHash(inputBytes); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < hashBytes.Length; i++) + { + sb.Append(hashBytes[i].ToString("x2")); + } + + hashValue = sb.ToString(); + } + + return hashValue; + } + private string GenerateSignatureExRate(SendExRateRequestModel requestBody, SendMNAuthResponsetModel tokenResponse) + { + string hashValue = ""; + string textToEncrypt = userName + agentCode + requestBody.Body.ReceivingCountry + requestBody.Body.SendingCountry + requestBody.Body.ReceivingCurrency + tokenResponse.Detail.ProcessIdentifier; + + using (MD5 md5 = MD5.Create()) + { + byte[] inputBytes = Encoding.UTF8.GetBytes(textToEncrypt); + byte[] hashBytes = md5.ComputeHash(inputBytes); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < hashBytes.Length; i++) + { + sb.Append(hashBytes[i].ToString("x2")); + } + + hashValue = sb.ToString(); + } + + return hashValue; + } + + private string GenerateSignatureStatic(StaticData requestBody, SendMNAuthResponsetModel tokenResponse) + { + string hashValue = ""; + string textToEncrypt = userName + agentCode + requestBody.Type + tokenResponse.Detail.ProcessIdentifier; + + using (MD5 md5 = MD5.Create()) + { + byte[] inputBytes = Encoding.UTF8.GetBytes(textToEncrypt); + byte[] hashBytes = md5.ComputeHash(inputBytes); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < hashBytes.Length; i++) + { + sb.Append(hashBytes[i].ToString("x2")); + } + + hashValue = sb.ToString(); + } + + return hashValue; + } + private string GenerateSignatureStatus(SendMNStatusRequestModel requestBody, SendMNAuthResponsetModel tokenResponse) + { + string hashValue = ""; + string textToEncrypt = userName + agentCode + requestBody.Body.ControlNo + tokenResponse.Detail.ProcessIdentifier; + + using (MD5 md5 = MD5.Create()) + { + byte[] inputBytes = Encoding.UTF8.GetBytes(textToEncrypt); + byte[] hashBytes = md5.ComputeHash(inputBytes); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < hashBytes.Length; i++) + { + sb.Append(hashBytes[i].ToString("x2")); + } + + hashValue = sb.ToString(); + } + + return hashValue; + } + + private string GenerateSignatureAccName(SendMNGetAccountNameModel requestBody, SendMNAuthResponsetModel tokenResponse) + { + string hashValue = ""; + string textToEncrypt = userName + agentCode; + + using (MD5 md5 = MD5.Create()) + { + byte[] inputBytes = Encoding.UTF8.GetBytes(textToEncrypt); + byte[] hashBytes = md5.ComputeHash(inputBytes); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < hashBytes.Length; i++) + { + sb.Append(hashBytes[i].ToString("x2")); + } + + hashValue = sb.ToString(); + } + + return hashValue; + } + } + +} + + + diff --git a/TPServices/TPServices.csproj b/TPServices/TPServices.csproj index f794c5a..8d299f8 100644 --- a/TPServices/TPServices.csproj +++ b/TPServices/TPServices.csproj @@ -43,10 +43,14 @@ ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\RestSharp.106.11.7\lib\net452\RestSharp.dll + + @@ -64,6 +68,8 @@ + + diff --git a/TPServices/packages.config b/TPServices/packages.config index 3dae89b..f245211 100644 --- a/TPServices/packages.config +++ b/TPServices/packages.config @@ -2,4 +2,5 @@ + \ No newline at end of file diff --git a/ThirdPartyAPIs/ApiControllers/ThirdPartyAPIController.cs b/ThirdPartyAPIs/ApiControllers/ThirdPartyAPIController.cs index b439215..2f913c2 100644 --- a/ThirdPartyAPIs/ApiControllers/ThirdPartyAPIController.cs +++ b/ThirdPartyAPIs/ApiControllers/ThirdPartyAPIController.cs @@ -15,11 +15,11 @@ using Common.Models.Status; using Common.Models.TxnAmendModel; using Common.Models.TxnModel; using log4net; -using Newtonsoft.Json; using System; using System.Web.Http; using Common.Utility; using Common.Models.DigitalSignature; +using Newtonsoft.Json; namespace ThirdPartyAPIs.ApiControllers { diff --git a/ThirdPartyAPIs/App_Data/Templates/BANK_TRANSFER_TXN_PENDING.html b/ThirdPartyAPIs/App_Data/Templates/BANK_TRANSFER_TXN_PENDING.html index 50e57c8..ca9c097 100644 --- a/ThirdPartyAPIs/App_Data/Templates/BANK_TRANSFER_TXN_PENDING.html +++ b/ThirdPartyAPIs/App_Data/Templates/BANK_TRANSFER_TXN_PENDING.html @@ -2,10 +2,12 @@ -
- +
+
+ imelondon + imelondon +
+

@@ -13,22 +15,21 @@
Dear {CustomerName}, -

- Thank you for your transaction. Please kindly deposit the total amount of £{CollectAmt} in the following bank account. Your transaction - will be released once the amount is credited in our account with the reference number given below. If we do not get the deposit in two working days, - your transaction will be cancelled. Please note that the transfer amount should exactly match with your transaction amount.
- You can now start sending money to your loved ones. -

+

+ Thank you for your transaction. Please kindly deposit the total amount of £{CollectAmt} in the following bank account. Your transaction + will be released once the amount is credited in our account with the reference number given below. If we do not get the deposit in the end of the day, + your transaction will be cancelled. Please note that the transfer amount should exactly match with your transaction amount.
+

Our Bank Information

  1. Bank Name: CLEAR BANK
  2. Account Name: IME LONDON
  3. -
  4. Sort Code: 04-08-42
  5. -
  6. Accoutn Number: 00000042
  7. +
  8. Sort Code: 04-06-93
  9. +
  10. Account Number: 00000151
  11. Reference: {CustomerName}
  12. -
  13. Subhida UK Ltd is the registered name of IME London.
  14. +

@@ -37,7 +38,12 @@ For further details please visit our website www.imelondon.co.uk

- +

+ + Note: If you face any problems while transferring money into IME London account due to account validation, please disregard + the notice and proceed with the transaction, as some of the banks may not provide account validation for business accounts.
+
+

diff --git a/ThirdPartyAPIs/Web.config b/ThirdPartyAPIs/Web.config index 038faf8..e0954bb 100644 --- a/ThirdPartyAPIs/Web.config +++ b/ThirdPartyAPIs/Web.config @@ -56,13 +56,14 @@ - + - + + + + + + + + + + @@ -98,7 +107,7 @@ - + @@ -106,7 +115,7 @@ - + @@ -374,9 +383,7 @@ - +