From df721cc945ab2e3b1d3d663bc3f67c1dfc68c7bf Mon Sep 17 00:00:00 2001 From: Dinesh Date: Thu, 13 Jun 2024 14:24:01 +0545 Subject: [PATCH] #30995 sendmn cost rate --- TPServices/SendMNRemit/Services/SendMNAPI.cs | 168 ++++++++++--------- 1 file changed, 93 insertions(+), 75 deletions(-) diff --git a/TPServices/SendMNRemit/Services/SendMNAPI.cs b/TPServices/SendMNRemit/Services/SendMNAPI.cs index 7a6f7cb..18404cc 100644 --- a/TPServices/SendMNRemit/Services/SendMNAPI.cs +++ b/TPServices/SendMNRemit/Services/SendMNAPI.cs @@ -58,74 +58,6 @@ namespace TPApiServices.SendMNRemit.Services throw new NotImplementedException(); } } - - - - - - //private SendMNAuthResponsetModel GetToken(string user) - //{ - // SendMNAuthResponsetModel tokenResponse = new SendMNAuthResponsetModel(); - // ThirdPartyRepo thirdPartyRepo = new ThirdPartyRepo(); - // try - // { - // TokenDataNew token = new TokenDataNew - // { - // PartnerCode = "SENDMN", - - // }; - - // //check token in DB - // var tokenDB = thirdPartyRepo.GetTokenNew(user, token); - // if (tokenDB.ResponseCode == "2" || tokenDB.ResponseCode == "3") - // { - // var requestBody = new SendMNModel - // { - // AgentCode = agentCode, - // AuthKey = authKey, - // UserName = userName - // }; - // var client = new RestClient(baseUrl); - // var request = new RestRequest("/api/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); - - // tokenResponse = client.Execute(request).Data; - - // _log.Info($"SENDMNAPI|GETTOKEN|RESPONSE : {JsonConvert.SerializeObject(tokenResponse)}"); - - // //save token in DB - // token.ExpiryTime = 10 * 60; - // token.Token = tokenResponse.Detail.Token; - // token.RefreshToken = tokenResponse.Detail.ProcessIdentifier; - // token.TokenType = "Bearer"; - - // tokenDB = thirdPartyRepo.GetTokenNew(user, token); - // } - // else - // { - // tokenResponse.Code = "0"; - // tokenResponse.Detail = new Detail { Token = tokenDB.Id, ProcessIdentifier = tokenDB.Extra }; - // } - // } - // catch (Exception ex) - // { - // tokenResponse.Code = "999"; - - // tokenResponse.Detail.Note = ex.ToString(); - - // _log.Error($"SENDMNAPI|GETTOKEN|EXCEPTION OCCURED : {JsonConvert.SerializeObject(tokenResponse)}"); - // } - - // return tokenResponse; - //} - private SendMNAuthResponsetModel GetToken(string user) { SendMNAuthResponsetModel tokenResponse = new SendMNAuthResponsetModel(); @@ -187,6 +119,92 @@ namespace TPApiServices.SendMNRemit.Services + //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; + //} + private TPResponse GetExRate(SendExRateRequestModel model) { var exResponse = new TPResponse(); @@ -204,14 +222,16 @@ namespace TPApiServices.SendMNRemit.Services return exResponse; } - + var body = new SendExRateRequestModel { Body = new Body { - SendingCountry = "UK", - ReceivingCountry = "MN", - ReceivingCurrency = "MNT" + + SendingCountry = "UK", + ReceivingCountry = "MN", + ReceivingCurrency = "MNT" + }, Signature = "", // Placeholder for the generated signature ProcessIdentifier = tokenResponse.Detail.ProcessIdentifier @@ -275,8 +295,6 @@ namespace TPApiServices.SendMNRemit.Services - - public TPResponse SendTransaction(SendTransaction model) { TPResponse txnResponse = new TPResponse(); @@ -359,7 +377,7 @@ namespace TPApiServices.SendMNRemit.Services { txnResponse.ResponseCode = "0";//success txnResponse.Id = sendTxnResponse.Detail.ControlNo; - txnResponse.Extra = sendTxnResponse.Detail.ControlNo; + txnResponse.Extra = exRateResponse.Extra; } else {