Browse Source

#32695 guavaPay api

gcc
Dinesh 3 months ago
parent
commit
203393c885
  1. 7
      Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs
  2. 110
      TPServices/GuavaPay/Model/GuavaPayModel.cs
  3. 322
      TPServices/GuavaPay/Services/GuavaPayAPI.cs
  4. 6
      ThirdPartyAPIs/Web.config

7
Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs

@ -3,6 +3,7 @@ using Common.Utility;
using Donga.DongaAPIService;
using GMENepal.GMENepalAPIService;
using log4net;
using TPApiServices.GuavaPay.Services;
using TPApiServices.SendMNRemit.Services;
using TPService.GCC.Services;
using Transfast.ApiServices;
@ -64,7 +65,11 @@ namespace Business.BusinessLogic.TPApiServices.Factory
log.Debug("Choose Provider as SENDMN ");
apiFactory = _container.Resolve<SendMNAPI>();
}
else if (providerNo == GetStatic.ReadWebConfig("guavaPay", ""))
{
log.Debug("Choose Provider as guavaPay ");
apiFactory = _container.Resolve<GuavaPayAPI>();
}
return apiFactory;
}
}

110
TPServices/GuavaPay/Model/GuavaPayModel.cs

@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TPApiServices.GuavaPay.Model
{
public class GuavaPayModel
{
public string ClintId { get; set; }
public string SecretKey { get; set; }
}
public class AuthResponseModel
{
public string Token { 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 Sender { get; set; }
public Receiver Receiver { get; set; }
}
public class Sender
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public string BirthDate { get; set; }
public DocumentInfo Document { get; set; }
}
public class DocumentInfo
{
public string DocumentType { get; set; }
public string DocumentNumber { get; set; }
public string RDocumentNumber { get; set; }
public string DocumentIssueCountry { get; set; }
public string DocumentIssueDate { get; set; }
public string DocumentEndDate { get; set; }
}
public class Receiver
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
public DocumentInfo Document { get; set; }
public AccountInfo AcountInfo { 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 Code { get; set; }
public string Msg { get; set; }
public string Message { get; set; }
}
public class GetExchangeRate
{
public string SourceCurrency { get; set; }
public string TragetCourrency { get; set; }
public string Rate { get; set; }
public string RemitanceType { get; set; }
public string agent { get; set; }
}
public class StatusResponseModel
{
public string statusDescription;
public string referenceCode { get; set; }
public string Data { get; set; }
public string Msg { get; set; }
public string Code { get; set; }
public string Message { get; set; }
public string Status { get; set; }
//public Detail Detail { get; set; }
}
public class StatusRequestModel
{
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; }
}
}

322
TPServices/GuavaPay/Services/GuavaPayAPI.cs

@ -0,0 +1,322 @@
using Common.Models;
using Common.Models.Bank_Account;
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.Text;
using System.Threading.Tasks;
using TPApiServices.GuavaPay.Model;
namespace TPApiServices.GuavaPay.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 authKey { get; set; }
protected string agentCode { get; set; }
public GuavaPayAPI()
{
baseUrl = GetStatic.ReadWebConfig("guavaPay_base_url", "");
clientId = GetStatic.ReadWebConfig("guavaPay_clint_Id", "");
authKey = GetStatic.ReadWebConfig("guavaPay_secret_key", "");
//agentCode = GetStatic.ReadWebConfig("guavaPay_agent_code", "");
}
public TPResponse GetTPResponse<T>(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
{
ClintId = agentCode,
SecretKey = authKey,
//UserName = userName
};
var client = new RestClient(baseUrl);
var request = new RestRequest("/v2/auth", Method.POST);
request.AddHeader("Content-Type", "application/json");
//request.AddHeader("UserName", userName);
request.AddHeader("ClintId", clientId);
request.AddHeader("SecretKey", authKey);
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(requestBody);
_log.Info($"GUAVAPAYAPI|GETTOKEN|REQUEST URL: {client.BaseUrl}{request.Resource}");
_log.Info($"GUAVAPAYAPI|GETTOKEN|REQUEST HEADERS: {JsonConvert.SerializeObject(request.Parameters.Where(p => p.Type == ParameterType.HttpHeader).Select(p => new { p.Name, p.Value }))}");
_log.Info($"GUAVAPAYAPI|GETTOKEN|REQUEST BODY: {JsonConvert.SerializeObject(requestBody)}");
var response = client.Execute<AuthResponseModel>(request);
tokenResponse = response.Data;
//tokenResponse = response.ProcessIdentifier;
if (tokenResponse != null && tokenResponse.Code == "0")
{
tokenResponse.ExpiryTime = DateTime.UtcNow.AddMinutes(90);
_log.Info($"GUAVAPAYAPI|GETTOKEN|RESPONSE : {JsonConvert.SerializeObject(tokenResponse)}");
}
else
{
_log.Error($"GUAVAPAYAPI|GETTOKEN|ERROR RESPONSE : {JsonConvert.SerializeObject(tokenResponse)}");
}
}
catch (Exception ex)
{
tokenResponse = new AuthResponseModel
{
Code = "999",
//Detail = new Detail { Note = ex.ToString() }
};
_log.Error($"GUAVAPAYAPI|GETTOKEN|EXCEPTION OCCURRED : {JsonConvert.SerializeObject(tokenResponse)}");
}
return tokenResponse;
}
private TPResponse GetStatus(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.Message;
_log.Error($"GUAVAPAYAPI|GETSTATUSSENDMN.GETTOKEN()|RESPONSE : {JsonConvert.SerializeObject(statusResponse)}");
return statusResponse;
}
var requestBody = new StatusResponseModel { referenceCode = model.PartnerPinNo };
_log.Info($"GUAVAPAYAPI|GETSTATUSSENDMN|REQUEST BODY : {JsonConvert.SerializeObject(requestBody)}");
var client = new RestClient(baseUrl);
var request = new RestRequest($"/v2/transactions/{model.PartnerPinNo}/status", Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer " + tokenResponse.Token);
request.AddHeader("ClintId", clientId);
request.AddHeader("SecretKey", authKey);
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(requestBody);
var getStatusResponse = client.Execute<StatusResponseModel>(request).Data;
_log.Info($"GUAVAPAYAPI|GETSTATUSSENDMN|RESPONSE : {JsonConvert.SerializeObject(getStatusResponse)}");
statusResponse.ResponseCode = getStatusResponse.Code;
statusResponse.Msg = getStatusResponse.Message;
if (getStatusResponse.Code == "0")
{
statusResponse.Id = getStatusResponse.referenceCode;
statusResponse.Extra = getStatusResponse.Status;
statusResponse.Extra2 = getStatusResponse.statusDescription;
//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($"GUAVAPAYAPI|GETSTATUSSENDMN|EXCEPTION OCCURED|RESPONSE : {JsonConvert.SerializeObject(statusResponse)}");
}
return statusResponse;
}
//private TPResponse AccountVerifySendMN(AccountValidate accountValidate)
//{
// throw new NotImplementedException();
//}
private TPResponse SendTransaction(SendTransaction model)
{
TPResponse txnResponse = new TPResponse();
txnResponse.ResponseCode = "1";
txnResponse.Msg = "Error sending transaction to partner!";
try
{
var tokenResponse = GetToken(model.RequestBy);
if (tokenResponse == null || tokenResponse.Code != "0")
{
txnResponse.ResponseCode = "1";
_log.Error($"GUAVAPAYAPI|SENDTRANSACTION.GETTOKEN()|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}");
return txnResponse;
}
var requestBody = MapSendTxnDetails(model);
if (requestBody == null)
{
txnResponse.ResponseCode = "1";
txnResponse.Msg = "Request body mapping failed";
_log.Error($"GUAVAPAYAPI|SENDTRANSACTION.MAPSENDTXNDETAILS()|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}");
return txnResponse;
}
_log.Info($"GUAVAPAYAPI|SENDTRANSACTION|REQUEST BODY : {JsonConvert.SerializeObject(requestBody)}");
var client = new RestClient(baseUrl);
var request = new RestRequest("/v2/payments/account", Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer " + tokenResponse.Token);
request.AddHeader("ClintId", clientId);
request.AddHeader("SecretKey", authKey);
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(requestBody);
var TxnResponse = client.Execute<SendTransactionResponse>(request);
if (TxnResponse == null || TxnResponse.Data == null)
{
txnResponse.ResponseCode = "1";
txnResponse.Msg = "Transaction response is null";
_log.Error($"GUAVAPAYAPI|SENDTRANSACTION.EXECUTE()|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}");
return txnResponse;
}
var sendTxnResponse = TxnResponse.Data;
_log.Info($"GUAVAPAYAPI|SENDTRANSACTION|RESPONSE : {TxnResponse.Content}");
if (sendTxnResponse.Code == "0")
{
txnResponse.ResponseCode = "0";//success
txnResponse.Id = sendTxnResponse.RRN;
txnResponse.Extra = sendTxnResponse.Status;
txnResponse.Extra2 = sendTxnResponse.StatusDescription;
txnResponse.Extra3 = sendTxnResponse.Fee;
txnResponse.Extra4 = sendTxnResponse.Rate;
}
else
{
txnResponse.ResponseCode = "1";//failed
txnResponse.Extra = sendTxnResponse.Code;
}
txnResponse.Msg = sendTxnResponse.Msg ?? sendTxnResponse.Message ;
txnResponse.Data = sendTxnResponse;
}
catch (Exception ex)
{
txnResponse.ResponseCode = "999";
txnResponse.Msg = ex.ToString();
_log.Error($"GUAVAPAYAPI|SENDTRANSACTION|EXCEPTION OCCURED|RESPONSE : {JsonConvert.SerializeObject(txnResponse)}");
}
return txnResponse;
}
public GuavaSendTransaction MapSendTxnDetails(SendTransaction model)
{
return new GuavaSendTransaction
{
Sender = new Sender
{
FirstName = model.Sender.SFirstName,
LastName = model.Sender.SLastName1,
Address = model.Sender.SCityId,
BirthDate = model.Sender.SBirthDate,
Phone = model.Sender.SMobile,
Document = new DocumentInfo
{
DocumentType = model.Sender.SIdType,
DocumentNumber = model.Sender.SIdNo,
DocumentIssueCountry = model.Sender.SNativeCountry,
DocumentIssueDate = model.Sender.SIdIssueDate,
DocumentEndDate = model.Sender.SIdExpiryDate,
}
},
Receiver = new Receiver
{
FirstName = model.Receiver.RFirstName,
LastName = model.Receiver.RLastName,
Phone = model.Receiver.RMobile,
Document = new DocumentInfo
{
RDocumentNumber = model.Receiver.RIdNo
},
AcountInfo = new AccountInfo
{
AccountNumber = model.Receiver.UnitaryBankAccountNo,
BankName = model.Agent.PBankName
}
},
Country = model.Receiver.RCountry,
AgentName = model.Agent.PBankName,
Amount = Convert.ToString(model.Transaction.PAmt),
AgentTransactionId = model.Transaction.JMEControlNo,
CallBackUrl = ""
};
}
}
}

6
ThirdPartyAPIs/Web.config

@ -98,6 +98,7 @@
<add key="Wing" value="394434" />
<add key="gccremit" value="394449" />
<add key="sendMN" value="394488" />
<add key="guavaPay" value="394490" />
<!-- END API PartnerId-->
<!--GCC Remit API -->
<add key="gcc_base_url" value="http://demo.api.gccremit.com/SendAPI.svc" />
@ -111,6 +112,11 @@
<add key="sendmn_user_name" value="IME Agent" />
<add key="sendmn_auth_key" value="n2PmKhD1V5IwRdDT5pMeOS/x+W4PH3L4nRxvnCoyVhE=" />
<add key="sendmn_agent_code" value="MGO394732" />
<!--Guava Pay Remit API -->
<add key="guavaPay_base_url" value="https://test.remiton.pro/api" />
<add key="guavaPay_clint_Id" value="f3d564dadcb5a4fe9ed0c06da6e3bb5785405bbf" />
<add key="guavaPay_secret_key" value="7cf3288cc67d4a2b965a5d41a4005fc1123fa64081" />
<!--SMS API URL-->
<add key="onewaysmsURL" value="https://api.textmarketer.co.uk/gateway/" />

Loading…
Cancel
Save