From 7248adbd7d5f7bebf300ed96a099060cc455e02b Mon Sep 17 00:00:00 2001 From: Dinesh Date: Thu, 1 Aug 2024 14:20:13 +0545 Subject: [PATCH 1/6] #30995 gauvaPay api --- .../Factory/ApiFactoryServices.cs | 6 + .../GuavaPayRemit/Model/GuavaPayModel.cs | 96 +++++++++ .../GuavaPayRemit/Services/GuavaPayAPI.cs | 203 ++++++++++++++++++ TPServices/TPServices.csproj | 2 + ThirdPartyAPIs/Web.config | 34 +-- 5 files changed, 329 insertions(+), 12 deletions(-) create mode 100644 TPServices/GuavaPayRemit/Model/GuavaPayModel.cs create mode 100644 TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs diff --git a/Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs b/Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs index c1ac201..374e2a7 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.GuavaPayRemit.Services; using TPApiServices.SendMNRemit.Services; using TPService.GCC.Services; using Unity; @@ -32,6 +33,11 @@ namespace Business.BusinessLogic.TPApiServices.Factory log.Debug("Choose Provider as SENDMN "); apiFactory = _container.Resolve(); } + else if (providerNo == GetStatic.ReadWebConfig("guavaPay", "")) + { + log.Debug("Choose Provider as guavaPay"); + apiFactory = _container.Resolve(); + } return apiFactory; } } diff --git a/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs b/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs new file mode 100644 index 0000000..ba07592 --- /dev/null +++ b/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TPApiServices.GuavaPayRemit.Model +{ + public class GuavaPayModel + { + public string clientId { get; set; } + public string secretKey { get; set; } + + } + + public class AuthResponseModel + { + public string accessToken { get; set; } + public string refreshToken { get; set; } + public string Message { get; set; } + public string Code { get; set; } + public DateTime ExpiryTime { get; set; } + } + public class GuavaSendTransaction + { + public string Country { get; set; } + public string AgentName { get; set; } + public string Amount { get; set; } + public string Currency { get; set; } + public string AgentTransactionId { get; set; } + public string CallBackUrl { get; set; } + public Sender senderClient { get; set; } + public Receiver receiverClient { get; set; } + } + public class Sender + { + public string FirstName { get; set; } + public string MiddleName { get; set; } + public string LastName { get; set; } + public string Phone { get; set; } + public string Address { get; set; } + public string BirthDate { get; set; } + public string zipCode { get; set; } + public DocumentInfo documentInfo { get; set; } + + } + public class DocumentInfo + { + public string DocumentType { get; set; } + public string DocumentNumber { get; set; } + public string RDocumentNumber { get; set; } + public string DocumentIssuedCountry { get; set; } + public string DocumentIssuedDate { get; set; } + public string DocumentEndDate { get; set; } + } + + public class Receiver + { + public string FirstName { get; set; } + public string MiddleName { get; set; } + public string LastName { get; set; } + public string Phone { get; set; } + public DocumentInfo documentInfo { get; set; } + public AccountInfo accountInfo { get; set; } + + } + public class AccountInfo + { + public string AccountNumber { get; set; } + public string BankName { get; set; } + } + + public class SendTransactionResponse + { + public string Status { get; set; } + public string StatusDescription { get; set; } + public string RRN { get; set; } + public string Fee { get; set; } + public string Rate { get; set; } + public string StatusCode { get; set; } + public string Msg { get; set; } + public string Message { get; set; } + public List Errors { get; internal set; } + } + + public class StatusResponseModel + { + public string statusDescription; + + public string referenceCode { get; set; } + + public string Status { get; set; } + //public Detail Detail { get; set; } + + } +} diff --git a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs new file mode 100644 index 0000000..b7fa702 --- /dev/null +++ b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs @@ -0,0 +1,203 @@ +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.Net; +using System.Text; +using System.Threading.Tasks; +using TPApiServices.GuavaPayRemit.Model; + +namespace TPApiServices.GuavaPayRemit.Services +{ + public class GuavaPayAPI : ITPApiServices + { + private readonly ILog _log = LogManager.GetLogger(typeof(GuavaPayAPI)); + protected string baseUrl { get; set; } + protected string clientId { get; set; } + protected string secretKey { get; set; } + protected string agentCode { get; set; } + + public GuavaPayAPI() + { + baseUrl = GetStatic.ReadWebConfig("guavaPay_base_url", ""); + clientId = GetStatic.ReadWebConfig("guavaPay_clint_Id", ""); + secretKey = GetStatic.ReadWebConfig("guavaPay_secret_key", ""); + //agentCode = GetStatic.ReadWebConfig("guavaPay_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 GetStatus(model as GetStatus); + + //case "staticData": + // return GetStaticData(model as StaticData); + + default: + throw new NotImplementedException(); + } + } + private AuthResponseModel GetToken(string user) + { + AuthResponseModel tokenResponse = new AuthResponseModel(); + try + { + var requestBody = new GuavaPayModel + { + clientId = clientId, + secretKey = secretKey//"7cf3288cc67d4a2b965a5d41a4005fc1123fa64081" + }; + var client = new RestClient(baseUrl); + var request = new RestRequest("/v2/auth", Method.POST); + request.AddHeader("Content-Type", "application/json"); + request.AddJsonBody(requestBody); + _log.Info($"GUAVAPAYAPI|GETTOKEN|REQUEST URL: {client.BaseUrl}{request.Resource}"); + _log.Info($"GUAVAPAYAPI|GETTOKEN|REQUEST BODY: {JsonConvert.SerializeObject(requestBody)}"); + var response = client.Execute(request); + if (response.StatusCode == HttpStatusCode.OK) + { + tokenResponse = JsonConvert.DeserializeObject(response.Content); + tokenResponse.ExpiryTime = DateTime.UtcNow.AddMinutes(90); + _log.Info($"GUAVAPAYAPI|GETTOKEN|RESPONSE : {JsonConvert.SerializeObject(tokenResponse)}"); + } + else + { + _log.Error($"GUAVAPAYAPI|GETTOKEN|ERROR RESPONSE : {response.Content}"); + } + } + catch (Exception ex) + { + tokenResponse = new AuthResponseModel + { + Code = "999" + }; + _log.Error($"GUAVAPAYAPI|GETTOKEN|EXCEPTION OCCURRED : {ex}"); + } + + return tokenResponse; + } + private TPResponse GetStatus(GetStatus model) + { + TPResponse statusResponse = new TPResponse(); + var tokenResponse = GetToken(model.RequestBy); + var client = new RestClient(baseUrl); + var request = new RestRequest($"/v2/transactions/{model.PartnerPinNo}/status", Method.GET); + request.AddHeader("Content-Type", "application/json"); + request.AddHeader("Authorization", "Bearer " + tokenResponse.accessToken); + request.RequestFormat = DataFormat.Json; + // request.AddJsonBody(requestBody); + var getStatusResponse = client.Execute(request).Data; + //var statusres = getStatusResponse.Data; + _log.Info($"GUAVAPAYAPI|GETSTATUSSENDMN|RESPONSE : {JsonConvert.SerializeObject(getStatusResponse)}"); + statusResponse.ResponseCode = "0"; + statusResponse.Id = getStatusResponse.referenceCode; + statusResponse.Extra2 = getStatusResponse.Status; + statusResponse.Extra4 = getStatusResponse.statusDescription; + statusResponse.Data = getStatusResponse; + return statusResponse; + } + public TPResponse SendTransaction(SendTransaction model) + { + TPResponse txnResponse = new TPResponse(); + try + { + var tokenResponse = GetToken(model.RequestBy); // Method to get the token + var requestBody = MapSendTxnDetails(model); // Method to map transaction details + _log.Info($"GUAVAPAYAPI|SENDTRANSACTION|REQUEST BODY : {JsonConvert.SerializeObject(requestBody)}"); + var client = new RestClient(baseUrl); + if (model?.Transaction == null || string.IsNullOrEmpty(model.Transaction.PaymentType)) + { + throw new ArgumentNullException("Transaction or PaymentType is null or empty."); + } + _log.Info($"GUAVAPAYAPI|SENDTRANSACTION|PAYMENT TYPE : {model.Transaction.PaymentType}"); + string endpoint = model.Transaction.PaymentType == "CASH" ? "/v2/payments/cash" : "/v2/payments/account"; + var request = new RestRequest(endpoint, Method.POST); + // request = new RestRequest(endpoint, Method.POST); + request.AddHeader("Content-Type", "application/json"); + request.AddHeader("Authorization", "Bearer " + tokenResponse.accessToken); + request.AddJsonBody(requestBody); + request.RequestFormat = DataFormat.Json; + var txnResponseData = client.Execute(request); + var sendTxnResponse = txnResponseData.Data; + _log.Info($"GUAVAPAYAPI|SENDTRANSACTION|RESPONSE : {txnResponseData.Content}"); + txnResponse.ResponseCode = "0"; + txnResponse.Id = sendTxnResponse.RRN; + txnResponse.Extra = sendTxnResponse.Rate; + txnResponse.Extra2 = sendTxnResponse.Status; + txnResponse.Extra3 = sendTxnResponse.Fee; + txnResponse.Extra4 = sendTxnResponse.StatusDescription; + txnResponse.Data = sendTxnResponse; + } + catch (Exception ex) + { + txnResponse.ResponseCode = "999"; + txnResponse.Msg = ex.ToString(); + _log.Error($"GUAVAPAYAPI|SENDTRANSACTION|EXCEPTION OCCURRED|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}"); + } + return txnResponse; + } + public GuavaSendTransaction MapSendTxnDetails(SendTransaction model) + { + return new GuavaSendTransaction + { + senderClient = new Sender + { + FirstName = model.Sender.SFirstName, + MiddleName = model.Sender.SMiddleName, + LastName = model.Sender.SLastName1, + Address = model.Sender.SCityId, + BirthDate = model.Sender.SBirthDate, + Phone = model.Sender.SMobile, + zipCode = model.Sender.SZipCode, + documentInfo = new DocumentInfo + { + DocumentType = model.Sender.SIdType, + DocumentNumber = model.Sender.SIdNo, + DocumentIssuedCountry = model.Sender.SCountryName, + DocumentIssuedDate = model.Sender.SIdIssueDate, + DocumentEndDate = model.Sender.SIdExpiryDate, + } + }, + receiverClient = new Receiver + { + FirstName = model.Receiver.RFirstName, + MiddleName = model.Receiver.RMiddleName, + LastName = model.Receiver.RLastName, + Phone = model.Receiver.RMobile, + documentInfo = new DocumentInfo + { + RDocumentNumber = model.Receiver.RIdNo + }, + accountInfo = new AccountInfo + { + AccountNumber = model.Receiver.UnitaryBankAccountNo,// "1312431424141414", + BankName = model.Agent.PBankName //"MeezanBank" + } + }, + Country = model.Receiver.RNativeCountry, + AgentName = model.Agent.PBankId, //"MeezanBank", + Amount = Convert.ToString(model.Transaction.PAmt), + AgentTransactionId = model.Transaction.JMEControlNo, + Currency = model.Transaction.PCurr, + CallBackUrl = "" + + }; + } + } +} diff --git a/TPServices/TPServices.csproj b/TPServices/TPServices.csproj index 8d299f8..e604dcd 100644 --- a/TPServices/TPServices.csproj +++ b/TPServices/TPServices.csproj @@ -66,6 +66,8 @@ + + diff --git a/ThirdPartyAPIs/Web.config b/ThirdPartyAPIs/Web.config index e0954bb..f176dd0 100644 --- a/ThirdPartyAPIs/Web.config +++ b/ThirdPartyAPIs/Web.config @@ -62,29 +62,39 @@ - + + + + - - + - --> + - - + + + + + + - - - - + + + + + + + From 57bd6fbe64dfff8f91103d3d5d9d08db2ae7cf4c Mon Sep 17 00:00:00 2001 From: Dinesh Date: Wed, 7 Aug 2024 16:18:42 +0545 Subject: [PATCH 2/6] #32695 gauvaPay --- .../GuavaPayRemit/Services/GuavaPayAPI.cs | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs index b7fa702..7d1fbb0 100644 --- a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs +++ b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs @@ -136,13 +136,41 @@ namespace TPApiServices.GuavaPayRemit.Services var txnResponseData = client.Execute(request); var sendTxnResponse = txnResponseData.Data; _log.Info($"GUAVAPAYAPI|SENDTRANSACTION|RESPONSE : {txnResponseData.Content}"); - txnResponse.ResponseCode = "0"; - txnResponse.Id = sendTxnResponse.RRN; - txnResponse.Extra = sendTxnResponse.Rate; - txnResponse.Extra2 = sendTxnResponse.Status; - txnResponse.Extra3 = sendTxnResponse.Fee; - txnResponse.Extra4 = sendTxnResponse.StatusDescription; - txnResponse.Data = sendTxnResponse; + + if (sendTxnResponse != null) + { + _log.Info($"GUAVAPAYAPI|SENDTRANSACTION|RESPONSE DATA : {JsonConvert.SerializeObject(sendTxnResponse)}"); + + if (string.IsNullOrEmpty(sendTxnResponse.RRN) || string.IsNullOrEmpty(sendTxnResponse.Rate) || + string.IsNullOrEmpty(sendTxnResponse.Status) || string.IsNullOrEmpty(sendTxnResponse.Fee) || + string.IsNullOrEmpty(sendTxnResponse.StatusDescription)) + { + txnResponse.ResponseCode = "1"; + txnResponse.Msg = "One or more critical response fields are null."; + _log.Warn($"GUAVAPAYAPI|SENDTRANSACTION|MISSING FIELDS: " + + $"RRN: {sendTxnResponse.RRN}, " + + $"Rate: {sendTxnResponse.Rate}, " + + $"Status: {sendTxnResponse.Status}, " + + $"Fee: {sendTxnResponse.Fee}, " + + $"StatusDescription: {sendTxnResponse.StatusDescription}"); + } + else + { + txnResponse.ResponseCode = "0"; + txnResponse.Id = sendTxnResponse.RRN; + txnResponse.Extra = sendTxnResponse.Rate; + txnResponse.Extra2 = sendTxnResponse.Status; + txnResponse.Extra3 = sendTxnResponse.Fee; + txnResponse.Extra4 = sendTxnResponse.StatusDescription; + txnResponse.Data = sendTxnResponse; + } + } + else + { + txnResponse.ResponseCode = "1"; + txnResponse.Msg = "Response data is null"; + _log.Warn($"GUAVAPAYAPI|SENDTRANSACTION|RESPONSE DATA IS NULL"); + } } catch (Exception ex) { From a1f38852269c168a87c29b0b303871e9aca5e08b Mon Sep 17 00:00:00 2001 From: Dinesh Date: Wed, 14 Aug 2024 14:16:46 +0545 Subject: [PATCH 3/6] #32695 gauvapay receiver id --- TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs | 2 +- ThirdPartyAPIs/Web.config | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs index 7d1fbb0..7da5035 100644 --- a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs +++ b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs @@ -210,7 +210,7 @@ namespace TPApiServices.GuavaPayRemit.Services Phone = model.Receiver.RMobile, documentInfo = new DocumentInfo { - RDocumentNumber = model.Receiver.RIdNo + DocumentNumber = model.Receiver.RIdNo }, accountInfo = new AccountInfo { diff --git a/ThirdPartyAPIs/Web.config b/ThirdPartyAPIs/Web.config index f176dd0..3d2e66e 100644 --- a/ThirdPartyAPIs/Web.config +++ b/ThirdPartyAPIs/Web.config @@ -17,8 +17,8 @@ - - + + From 97fbf3c5a0fc69b48fe99866927e81ad3c93a422 Mon Sep 17 00:00:00 2001 From: Dinesh Date: Thu, 15 Aug 2024 10:59:20 +0545 Subject: [PATCH 4/6] #32695 guavapay --- TPServices/GuavaPayRemit/Model/GuavaPayModel.cs | 1 + TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs b/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs index ba07592..adfcbf5 100644 --- a/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs +++ b/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs @@ -68,6 +68,7 @@ namespace TPApiServices.GuavaPayRemit.Model { public string AccountNumber { get; set; } public string BankName { get; set; } + public string BankBranchCode { get; set; } } public class SendTransactionResponse diff --git a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs index 7da5035..0082333 100644 --- a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs +++ b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs @@ -215,7 +215,8 @@ namespace TPApiServices.GuavaPayRemit.Services accountInfo = new AccountInfo { AccountNumber = model.Receiver.UnitaryBankAccountNo,// "1312431424141414", - BankName = model.Agent.PBankName //"MeezanBank" + BankName = model.Agent.PBankName, //"MeezanBank" + BankBranchCode = model.Agent.PAgentName, } }, Country = model.Receiver.RNativeCountry, From a5772f9d1a7012a5bc2464e9f59f48fe8effe605 Mon Sep 17 00:00:00 2001 From: Dinesh Date: Thu, 15 Aug 2024 21:17:57 +0545 Subject: [PATCH 5/6] #32695 grl --- TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs index 0082333..4c454fa 100644 --- a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs +++ b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs @@ -135,6 +135,7 @@ namespace TPApiServices.GuavaPayRemit.Services request.RequestFormat = DataFormat.Json; var txnResponseData = client.Execute(request); var sendTxnResponse = txnResponseData.Data; + _log.Info($"GUAVAPAYAPI|SENDTRANSACTION|REQUEST URL: {client.BaseUrl}{request.Resource}"); _log.Info($"GUAVAPAYAPI|SENDTRANSACTION|RESPONSE : {txnResponseData.Content}"); if (sendTxnResponse != null) From 07562724e1c713bec5baf6f1aedc822d9b3436cb Mon Sep 17 00:00:00 2001 From: Dinesh Date: Wed, 21 Aug 2024 13:40:10 +0545 Subject: [PATCH 6/6] #32695 guavapay (add Bank code) --- TPServices/GuavaPayRemit/Model/GuavaPayModel.cs | 1 + TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs b/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs index adfcbf5..c5a9aa7 100644 --- a/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs +++ b/TPServices/GuavaPayRemit/Model/GuavaPayModel.cs @@ -69,6 +69,7 @@ namespace TPApiServices.GuavaPayRemit.Model public string AccountNumber { get; set; } public string BankName { get; set; } public string BankBranchCode { get; set; } + public string BankCode { get; set; } } public class SendTransactionResponse diff --git a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs index 4c454fa..7f14d2a 100644 --- a/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs +++ b/TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs @@ -218,6 +218,7 @@ namespace TPApiServices.GuavaPayRemit.Services AccountNumber = model.Receiver.UnitaryBankAccountNo,// "1312431424141414", BankName = model.Agent.PBankName, //"MeezanBank" BankBranchCode = model.Agent.PAgentName, + BankCode = model.Agent.PBranchId } }, Country = model.Receiver.RNativeCountry,