Browse Source

Guava Pay api changes

master
Shakun Shrestha 2 weeks ago
parent
commit
7212a66817
  1. 6
      Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs
  2. 33
      GMENepal/GMENepalAPIService/GMENepalAPI.cs
  3. 99
      TPServices/GuavaPayRemit/Model/GuavaPayModel.cs
  4. 242
      TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs
  5. 2
      TPServices/TPServices.csproj
  6. 12
      ThirdPartyAPIs/Web.config

6
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<SendMNAPI>();
}
else if (providerNo == GetStatic.ReadWebConfig("guavaPay", ""))
{
log.Debug("Choose Provider as guavaPay");
apiFactory = _container.Resolve<GuavaPayAPI>();
}
return apiFactory;
}
}

33
GMENepal/GMENepalAPIService/GMENepalAPI.cs

@ -227,6 +227,7 @@ namespace GMENepal.GMENepalAPIService
private TPResponse SendTransaction(SendTransaction sendTransaction)
{
GMESendMoney gS = SendModelMap(sendTransaction);
gS.SessionId = sendTransaction.ProcessId;
DbResult model = new DbResult();
SendMoneyResult sendMoneyRes = new SendMoneyResult();
TPResponse _response = new CustomModelValidaton().IsModelValid(gS);
@ -243,17 +244,18 @@ namespace GMENepal.GMENepalAPIService
_response = new TPResponse();
var exRate = _fastMoneyWeb.GetCalculation(
gS.PartnerId, gS.UserName, gS.Password, gS.SessionId, "",
gS.PartnerId, gS.UserName, gS.Password, gS.ControlNo, "",
"1000", "C", gS.BeneCountry, "P"
);
_log.Info("GetExRate | RESPONSE :" + JsonConvert.SerializeObject(model).ToString());
_log.Info("GetCalculation | RESPONSE :" + JsonConvert.SerializeObject(exRate).ToString());
var exConfirmId = exRate.ExConfirmId;
sendTransaction.ExRateConfirmId = exConfirmId;
sendMoneyRes = _fastMoneyWeb.SendMoney(PartnerId, UserName, Password, gS.ControlNo, exConfirmId, gS.MembershipId, gS.CustomerName, gS.CustomerAddress,
gS.CustomerContact, gS.CustomerCity, gS.CustomerCountry, gS.CustomerIdType, gS.CustomerIdNumber, gS.BeneName, gS.BeneAddress, gS.BeneContact, gS.BeneCity
, gS.BeneCountry, gS.Profession, gS.IncomeSource, gS.Relationship, gS.PurposeOfRemittance, gS.SendingAmount, gS.ReceivingAmount, gS.PaymentMethod
, gS.BankCode, gS.BankName, gS.BankBranchName, gS.BankAccountNumber, dateTxn, gS.CalculateBy, gS.FreeCharge);
gS.CustomerContact, gS.CustomerCity, gS.CustomerCountry, gS.CustomerIdType, gS.CustomerIdNumber, gS.BeneName, gS.BeneAddress, gS.BeneContact, gS.BeneCity
, gS.BeneCountry, gS.Profession, gS.IncomeSource, gS.Relationship, gS.PurposeOfRemittance, gS.SendingAmount, gS.ReceivingAmount, gS.PaymentMethod
, gS.BankCode, gS.BankName, gS.BankBranchName, gS.BankAccountNumber, dateTxn, gS.CalculateBy, gS.FreeCharge);
_log.Info("SendTransaction | RESPONSE :" + JsonConvert.SerializeObject(sendMoneyRes).ToString());
_response.ResponseCode = sendMoneyRes.ErrorCode;
@ -265,13 +267,22 @@ namespace GMENepal.GMENepalAPIService
return _response;
}
else if (gS.PaymentMethod.ToLower() == "w" && (gS.BankCode.ToLower() == "imepay" || gS.BankCode.ToLower() == "khalti"))
else if (gS.PaymentMethod.ToLower() == "w" && (gS.BankCode.ToLower() == "imepay" || gS.BankCode.ToLower() == "khalti"))
{
var exRate = _fastMoneyWeb.GetCalculation(
gS.PartnerId, gS.UserName, gS.Password, gS.SessionId, "",
"1000", "W", gS.BeneCountry, "P"
);
_log.Info("GetExRate | RESPONSE :" + JsonConvert.SerializeObject(exRate).ToString());
var exConfirmId = exRate.ExConfirmId;
sendTransaction.ExRateConfirmId = exConfirmId;
model = _fastMoneyWeb.RealTimeWalletDeposit(PartnerId, UserName, Password, gS.BankCode, gS.CustomerName, gS.CustomerAddress
, gS.CustomerContact, gS.CustomerCountry, gS.CustomerIdType, gS.CustomerIdNumber, gS.BeneName, gS.BeneAddress
, gS.BankAccountNumber, gS.BeneCountry, gS.IncomeSource, gS.Relationship, gS.PurposeOfRemittance, Convert.ToString(gS.CollectionAmount)
, gS.CollectionCurrency, gS.SendingAmount, gS.ReceivingAmount, gS.FreeCharge, gS.PayoutCommCurr, dateTxn, gS.ControlNo
, gS.SenderCostRate, gS.ReceiverCostRate, Convert.ToString(gS.ExRate), gS.Signature);
, gS.SenderCostRate, gS.ReceiverCostRate, exConfirmId, gS.Signature);
}
else
{
@ -286,17 +297,19 @@ namespace GMENepal.GMENepalAPIService
var response = AccountValidation(accValidate);
if (response.ResponseCode.Equals("0") || response.ResponseCode.Equals("100"))
{
var exRateBank = _fastMoneyWeb.GetCalculation(gS.PartnerId, gS.UserName, gS.Password, gS.SessionId, "", "1000", "B", gS.BeneCountry, "P");
var exRateBank = _fastMoneyWeb.GetCalculation(gS.PartnerId, gS.UserName, gS.Password, gS.ControlNo, "", gS.ReceivingAmount, "B", gS.BeneCountry, "P");
_log.Info("GetExRate | RESPONSE :" + JsonConvert.SerializeObject(exRateBank));
model = _fastMoneyWeb.ProcessBankDeposit(gS.PartnerId, gS.UserName, gS.Password, gS.ControlNo, exRateBank.ExConfirmId
model = _fastMoneyWeb.ProcessBankDeposit(gS.PartnerId, gS.UserName, gS.Password, gS.ControlNo, exRateBank.ExConfirmId
, gS.MembershipId, gS.CustomerName, gS.CustomerAddress, gS.CustomerContact, gS.CustomerCity, gS.CustomerCountry
, gS.CustomerIdType, gS.CustomerIdNumber, gS.BeneName, gS.BeneAddress, gS.BeneContact, gS.BeneCity, gS.BeneCountry, gS.Profession
, gS.IncomeSource, gS.Relationship, gS.PurposeOfRemittance, gS.SendingAmount, gS.ReceivingAmount, gS.PaymentMethod, gS.BankCode
, gS.BankName, gS.BankAccountNumber, dateTxn, gS.CalculateBy, gS.FreeCharge, gS.ControlNo, gS.PayoutCurrency, gS.ReceiverCostRate
, gS.SenderCostRate, gS.Signature);
_response.Extra = exRateBank.UsdVsNpr;
_response.Extra = exRateBank.UsdVsNpr;
}
else
{

99
TPServices/GuavaPayRemit/Model/GuavaPayModel.cs

@ -0,0 +1,99 @@
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 string BankBranchCode { get; set; }
public string BankCode { get; set; }
public string AccountType { 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<string> 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; }
}
}

242
TPServices/GuavaPayRemit/Services/GuavaPayAPI.cs

@ -0,0 +1,242 @@
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>(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<AuthResponseModel>(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<StatusResponseModel>(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<SendTransactionResponse>(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)
{
//_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)
{
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
{
//DocumentType = model.Receiver.RIdType,
DocumentNumber = model.Receiver.RIdNo
},
accountInfo = new AccountInfo
{
AccountNumber = model.Receiver.UnitaryBankAccountNo,// "1312431424141414",
BankName = model.Agent.PBankName, //"MeezanBank"
BankBranchCode = model.Agent.PAgentName,
BankCode = model.Agent.PBranchId,
//AccountType = model.Agent.PBankType
}
},
Country = model.Receiver.RNativeCountry,
AgentName = model.Agent.PBankId, //"MeezanBank",
Amount = Convert.ToString(model.Transaction.PAmt),
AgentTransactionId = model.Transaction.JMEControlNo,
Currency = model.Transaction.PCurr,
CallBackUrl = ""
};
}
}
}

2
TPServices/TPServices.csproj

@ -66,6 +66,8 @@
</Compile>
<Compile Include="GCC\Model\GCCSendMoney.cs" />
<Compile Include="GCC\Services\GCCAPI.cs" />
<Compile Include="GuavaPayRemit\Model\GuavaPayModel.cs" />
<Compile Include="GuavaPayRemit\Services\GuavaPayAPI.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SendMNRemit\Model\SendMNModel.cs" />

12
ThirdPartyAPIs/Web.config

@ -63,6 +63,7 @@
<add key="gmenepal" value="394397" />
<add key="gccremit" value="394449" />
<add key="sendMN" value="394502" />
<add key="guavaPay" value="394515" />
<!-- END API PartnerId-->
<!--GCC Remit API -->
<!--<add key="gcc_base_url" value="http://demo.api.gccremit.com/SendAPI.svc" />
@ -85,7 +86,16 @@
<add key="sendmn_user_name" value="IME Agent" />
<add key="sendmn_auth_key" value="n2PmKhD1V5IwRdDT5pMeOS/x+W4PH3L4nRxvnCoyVhE=" />
<add key="sendmn_agent_code" value="MGO394732" />
<!--SMS API URL-->
<!--guava Remit API -->
<add key="guavaPay" value="" />
<add key="guavaPay_base_url" value="https://remiton.pro/api" />
<add key="guavaPay_clint_Id" value="97c94396c207a306dd756a6054e8721867fa4cd7" />
<add key="guavaPay_secret_key" value="70322746a99223dad201b48624d133989f3c69eacd" />
<!--SMS API URL-->
<add key="onewaysmsURL" value="https://api.textmarketer.co.uk/gateway/" />
<add key="onewaysmsURLStatus" value="http://gateway.onewaysms.jp:10001/bulktrx.aspx" />
<add key="onewaysmsUserName" value="Vy5Vkw" />

Loading…
Cancel
Save