Shakun Shrestha
3 months ago
11 changed files with 921 additions and 39 deletions
-
4Business/App.config
-
7Business/BusinessLogic/TPApiServices/Factory/ApiFactoryServices.cs
-
1Common/Models/StaticData.cs
-
24TPServices/App.config
-
183TPServices/SendMNRemit/Model/SendMNModel.cs
-
677TPServices/SendMNRemit/Services/SendMNAPI.cs
-
6TPServices/TPServices.csproj
-
1TPServices/packages.config
-
2ThirdPartyAPIs/ApiControllers/ThirdPartyAPIController.cs
-
34ThirdPartyAPIs/App_Data/Templates/BANK_TRANSFER_TXN_PENDING.html
-
21ThirdPartyAPIs/Web.config
@ -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; } |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -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>(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<SendMNAuthResponsetModel>(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<SendMNExRateResponseModel>(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<SendMNSendTransactionResponseModel>(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<SendMNStatusResponseModel>(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<SendMNStatusResponseModel>(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<SendMNGResponseNameModel>(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; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue