You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

176 lines
8.4 KiB

using Common.Model;
using log4net;
using Newtonsoft.Json;
using System;
using System.Configuration;
using System.Net.Http;
using System.Text;
namespace Common
{
public static class ThirdPartyApi
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ThirdPartyApi));
public static string GetDefExRate(ExRateCalculateRequest model)
{
Log.Debug("GetDefExRate | Calling third party api to fetch the default exrate details " + JsonConvert.SerializeObject(model));
using (var client = RestApiClient.GetThirdPartyClient())
{
if (model.payoutPartner == "415207")
{
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["xPress_Url"].ToString());
}
var obj = JsonConvert.SerializeObject(model);
var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
try
{
HttpResponseMessage resp = client.PostAsync("api/global/ExRate/?isDefault=1", jbdContent).Result;
if (resp.IsSuccessStatusCode)
{
string resultData = resp.Content.ReadAsStringAsync().Result;
Log.Debug("GetDefExRate | Calling GetDefExRate Success, Response:" + resultData);
return resultData;
}
Log.Debug("GetDefExRate | Error occurred while fetching the default ex-rate details from the third party api, Response:" + resp.ToString());
return null;
}
catch (Exception ex)
{
Log.Error("Something Went Wrong, Please Try Again!!", ex);
return null;
}
}
}
public static string AccountValidation(AccountValidationModel model)
{
Log.Debug("AccountValidation | Calling third party api to validate the account/bank details " + JsonConvert.SerializeObject(model));
using (var client = RestApiClient.GetThirdPartyClient())
{
var obj = JsonConvert.SerializeObject(model);
var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
try
{
HttpResponseMessage resp = client.PostAsync("api/global/accountValidation", jbdContent).Result;
if (resp.IsSuccessStatusCode)
{
string resultData = resp.Content.ReadAsStringAsync().Result;
Log.Debug("AccountValidation | Calling AccountValidation Success, Response:" + resultData);
return resultData;
}
Log.Debug("AccountValidation | Error occurred while validating the bank/account details from the third party api , Response:" + resp.ToString());
return null;
}
catch (Exception ex)
{
Log.Error("Something Went Wrong, Please Try Again!!", ex);
return null;
}
}
}
public static string Calculate(ExRateCalculateRequest model)
{
Log.Debug("Calculate | Calling third party api to fetch the ex-rate details " + JsonConvert.SerializeObject(model));
using (var client = RestApiClient.GetThirdPartyClient())
{
if (model.payoutPartner == "415207")
{
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["xPress_Url"].ToString());
}
var obj = JsonConvert.SerializeObject(model);
var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
try
{
HttpResponseMessage resp = client.PostAsync("api/global/ExRate/?isDefault=0", jbdContent).Result;
if (resp.IsSuccessStatusCode)
{
string resultData = resp.Content.ReadAsStringAsync().Result;
Log.Debug("Calculate | Calling send money ex-rate details Success, Response:" + resultData);
return resultData;
}
Log.Debug("Calculate | Error occurred while fetching the ex-rate details from the third party api, Response:" + resp.ToString());
return null;
}
catch (Exception ex)
{
Log.Error("Something Went Wrong, Please Try Again!!", ex);
return null;
}
}
}
public static string SendTransaction(RemittanceRequestModel model)
{
Log.Debug("SendTransaction | Calling third party api to send transaction through mobile " + JsonConvert.SerializeObject(model));
using (var client = RestApiClient.GetThirdPartyClient())
{
if (model.PayOutPartner == "415207")
{
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["xPress_Url"].ToString());
}
var obj = JsonConvert.SerializeObject(model);
Log.Debug(obj);
var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
try
{
HttpResponseMessage resp = client.PostAsync("api/global/sendTxn", jbdContent).Result;
if (resp.IsSuccessStatusCode)
{
string resultData = resp.Content.ReadAsStringAsync().Result;
Log.Debug("SendTransaction | Calling SendTransaction through mobile Success, Response:" + resultData);
return resultData;
}
Log.Debug("SendTransaction | Error occurred from the third party api while sending the transaction through mobile , Response:" + resp.ToString());
return null;
}
catch (Exception ex)
{
Log.Error("Something Went Wrong, Please Try Again!!", ex);
return null;
}
}
}
//public static string SendSms(SmsParameters smsParameters)
//{
// Log.Debug("SendSms | Calling third party api to send the reset password through sms " + JsonConvert.SerializeObject(smsParameters));
// using (var client = RestApiClient.GetThirdPartyClient())
// {
// var data = new
// {
// userId = ApplicationConfig.ReadWebConfig("GmeKTUser"),
// scheduleType = smsParameters.scheduleType,
// subject = smsParameters.subject,
// message = smsParameters.message,
// callBackUrl = smsParameters.callBackUrl,
// todayDate = DateTime.Now.ToString("yyyyMMddHHmmss"),
// sendDate = smsParameters.sendDate,
// mobileNumber = ApplicationConfig.ReadWebConfig("mobileNumberForSms"),
// receiverId = smsParameters.receiverId
// };
// var obj = JsonConvert.SerializeObject(data);
// var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
// try
// {
// HttpResponseMessage resp = client.PostAsync(ApplicationConfig.GetSendSmsApiUrl(), jbdContent).Result;
// if (resp.IsSuccessStatusCode)
// {
// string resultData = resp.Content.ReadAsStringAsync().Result;
// Log.Debug("SendSms | Calling SendSms Success, Response:" + resultData);
// return resultData;
// }
// Log.Debug("SendSms | Error occurred from the third party api while sending the reset password through sms , Response:" + resp.ToString());
// return null;
// }
// catch (Exception ex)
// {
// Log.Error("Something Went Wrong, Please Try Again!!", ex);
// return null;
// }
// }
//}
}
}