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.

175 lines
8.4 KiB

1 year ago
  1. using Common.Model;
  2. using log4net;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Configuration;
  6. using System.Net.Http;
  7. using System.Text;
  8. namespace Common
  9. {
  10. public static class ThirdPartyApi
  11. {
  12. private static readonly ILog Log = LogManager.GetLogger(typeof(ThirdPartyApi));
  13. public static string GetDefExRate(ExRateCalculateRequest model)
  14. {
  15. Log.Debug("GetDefExRate | Calling third party api to fetch the default exrate details " + JsonConvert.SerializeObject(model));
  16. using (var client = RestApiClient.GetThirdPartyClient())
  17. {
  18. if (model.payoutPartner == "415207")
  19. {
  20. client.BaseAddress = new Uri(ConfigurationManager.AppSettings["xPress_Url"].ToString());
  21. }
  22. var obj = JsonConvert.SerializeObject(model);
  23. var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
  24. try
  25. {
  26. HttpResponseMessage resp = client.PostAsync("api/global/ExRate/?isDefault=1", jbdContent).Result;
  27. if (resp.IsSuccessStatusCode)
  28. {
  29. string resultData = resp.Content.ReadAsStringAsync().Result;
  30. Log.Debug("GetDefExRate | Calling GetDefExRate Success, Response:" + resultData);
  31. return resultData;
  32. }
  33. Log.Debug("GetDefExRate | Error occurred while fetching the default ex-rate details from the third party api, Response:" + resp.ToString());
  34. return null;
  35. }
  36. catch (Exception ex)
  37. {
  38. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  39. return null;
  40. }
  41. }
  42. }
  43. public static string AccountValidation(AccountValidationModel model)
  44. {
  45. Log.Debug("AccountValidation | Calling third party api to validate the account/bank details " + JsonConvert.SerializeObject(model));
  46. using (var client = RestApiClient.GetThirdPartyClient())
  47. {
  48. var obj = JsonConvert.SerializeObject(model);
  49. var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
  50. try
  51. {
  52. HttpResponseMessage resp = client.PostAsync("api/global/accountValidation", jbdContent).Result;
  53. if (resp.IsSuccessStatusCode)
  54. {
  55. string resultData = resp.Content.ReadAsStringAsync().Result;
  56. Log.Debug("AccountValidation | Calling AccountValidation Success, Response:" + resultData);
  57. return resultData;
  58. }
  59. Log.Debug("AccountValidation | Error occurred while validating the bank/account details from the third party api , Response:" + resp.ToString());
  60. return null;
  61. }
  62. catch (Exception ex)
  63. {
  64. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  65. return null;
  66. }
  67. }
  68. }
  69. public static string Calculate(ExRateCalculateRequest model)
  70. {
  71. Log.Debug("Calculate | Calling third party api to fetch the ex-rate details " + JsonConvert.SerializeObject(model));
  72. using (var client = RestApiClient.GetThirdPartyClient())
  73. {
  74. if (model.payoutPartner == "415207")
  75. {
  76. client.BaseAddress = new Uri(ConfigurationManager.AppSettings["xPress_Url"].ToString());
  77. }
  78. var obj = JsonConvert.SerializeObject(model);
  79. var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
  80. try
  81. {
  82. HttpResponseMessage resp = client.PostAsync("api/global/ExRate/?isDefault=0", jbdContent).Result;
  83. if (resp.IsSuccessStatusCode)
  84. {
  85. string resultData = resp.Content.ReadAsStringAsync().Result;
  86. Log.Debug("Calculate | Calling send money ex-rate details Success, Response:" + resultData);
  87. return resultData;
  88. }
  89. Log.Debug("Calculate | Error occurred while fetching the ex-rate details from the third party api, Response:" + resp.ToString());
  90. return null;
  91. }
  92. catch (Exception ex)
  93. {
  94. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  95. return null;
  96. }
  97. }
  98. }
  99. public static string SendTransaction(RemittanceRequestModel model)
  100. {
  101. Log.Debug("SendTransaction | Calling third party api to send transaction through mobile " + JsonConvert.SerializeObject(model));
  102. using (var client = RestApiClient.GetThirdPartyClient())
  103. {
  104. if (model.PayOutPartner == "415207")
  105. {
  106. client.BaseAddress = new Uri(ConfigurationManager.AppSettings["xPress_Url"].ToString());
  107. }
  108. var obj = JsonConvert.SerializeObject(model);
  109. Log.Debug(obj);
  110. var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
  111. try
  112. {
  113. HttpResponseMessage resp = client.PostAsync("api/global/sendTxn", jbdContent).Result;
  114. if (resp.IsSuccessStatusCode)
  115. {
  116. string resultData = resp.Content.ReadAsStringAsync().Result;
  117. Log.Debug("SendTransaction | Calling SendTransaction through mobile Success, Response:" + resultData);
  118. return resultData;
  119. }
  120. Log.Debug("SendTransaction | Error occurred from the third party api while sending the transaction through mobile , Response:" + resp.ToString());
  121. return null;
  122. }
  123. catch (Exception ex)
  124. {
  125. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  126. return null;
  127. }
  128. }
  129. }
  130. //public static string SendSms(SmsParameters smsParameters)
  131. //{
  132. // Log.Debug("SendSms | Calling third party api to send the reset password through sms " + JsonConvert.SerializeObject(smsParameters));
  133. // using (var client = RestApiClient.GetThirdPartyClient())
  134. // {
  135. // var data = new
  136. // {
  137. // userId = ApplicationConfig.ReadWebConfig("GmeKTUser"),
  138. // scheduleType = smsParameters.scheduleType,
  139. // subject = smsParameters.subject,
  140. // message = smsParameters.message,
  141. // callBackUrl = smsParameters.callBackUrl,
  142. // todayDate = DateTime.Now.ToString("yyyyMMddHHmmss"),
  143. // sendDate = smsParameters.sendDate,
  144. // mobileNumber = ApplicationConfig.ReadWebConfig("mobileNumberForSms"),
  145. // receiverId = smsParameters.receiverId
  146. // };
  147. // var obj = JsonConvert.SerializeObject(data);
  148. // var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
  149. // try
  150. // {
  151. // HttpResponseMessage resp = client.PostAsync(ApplicationConfig.GetSendSmsApiUrl(), jbdContent).Result;
  152. // if (resp.IsSuccessStatusCode)
  153. // {
  154. // string resultData = resp.Content.ReadAsStringAsync().Result;
  155. // Log.Debug("SendSms | Calling SendSms Success, Response:" + resultData);
  156. // return resultData;
  157. // }
  158. // Log.Debug("SendSms | Error occurred from the third party api while sending the reset password through sms , Response:" + resp.ToString());
  159. // return null;
  160. // }
  161. // catch (Exception ex)
  162. // {
  163. // Log.Error("Something Went Wrong, Please Try Again!!", ex);
  164. // return null;
  165. // }
  166. // }
  167. //}
  168. }
  169. }