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.

356 lines
19 KiB

3 months ago
  1. using Business.BusinessLogic.TPApiServices.TPServices;
  2. using Common.Models;
  3. using Common.Models.Address;
  4. using Common.Models.Agent;
  5. using Common.Models.Bank;
  6. using Common.Models.Bank_Account;
  7. using Common.Models.Notification;
  8. using Common.Models.ExchangeRate;
  9. using Common.Models.Payer;
  10. using Common.Models.RequestResponse;
  11. using Common.Models.Sender;
  12. using Common.Models.SendSMS;
  13. using Common.Models.SendTransactionMobile;
  14. using Common.Models.Status;
  15. using Common.Models.TxnAmendModel;
  16. using Common.Models.TxnModel;
  17. using log4net;
  18. using System;
  19. using System.Web.Http;
  20. using Common.Utility;
  21. using Common.Models.DigitalSignature;
  22. using Newtonsoft.Json;
  23. namespace ThirdPartyAPIs.ApiControllers
  24. {
  25. [RoutePrefix("api/v1")]
  26. public class ThirdPartyAPIController : ApiController
  27. {
  28. private readonly ILog _log = LogManager.GetLogger(typeof(ThirdPartyAPIController));
  29. private readonly ThirdPartyServices _sendTxnServices;
  30. public ThirdPartyAPIController(ThirdPartyServices sendTxnServices)
  31. {
  32. _sendTxnServices = sendTxnServices;
  33. }
  34. [HttpGet]
  35. [Route("Tp/ping")]
  36. public IHttpActionResult Ping()
  37. {
  38. _log.Debug("Ping " + JsonConvert.SerializeObject("Mobile Api Call Successfully"));
  39. return Ok(new TPResponse() { Id = "1", Msg = "Mobile Api Call Successfully" });
  40. }
  41. [Route("TP/SMSApi")]
  42. [HttpPost]
  43. public IHttpActionResult SendSMSApi(SMSRequestModel model)
  44. {
  45. if (string.IsNullOrEmpty(model.ProcessId))
  46. model.ProcessId = Guid.NewGuid().ToString();
  47. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  48. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  49. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  50. LogicalThreadContext.Properties["ControlNo"] = string.IsNullOrEmpty(model.ControlNo) ? model.MobileNumber : model.ControlNo;
  51. LogicalThreadContext.Properties["MethodName"] = "SendSMSApi";
  52. _log.Debug("SendSMSApi Request: " + JsonConvert.SerializeObject(model));
  53. var response = _sendTxnServices.GetTPResponse(model, "SMSApi");
  54. _log.Debug("SendSMSApi Response: " + JsonConvert.SerializeObject(response));
  55. return Json(response);
  56. }
  57. [Route("TP/ExRate")]
  58. [HttpPost]
  59. public IHttpActionResult GetExRate(ExchangeRate model)
  60. {
  61. if (string.IsNullOrEmpty(model.ProcessId))
  62. model.ProcessId = Guid.NewGuid().ToString();
  63. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  64. LogicalThreadContext.Properties["requestBy"] = model.UserName ?? model.RequestedBy;
  65. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  66. LogicalThreadContext.Properties["MethodName"] = "GetExRate";
  67. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  68. // model.SessionId = GetStatic.GetSessionId();
  69. _log.Debug("ExRate Request: " + JsonConvert.SerializeObject(model));
  70. var response = _sendTxnServices.GetTPResponse(model, "exRate");
  71. _log.Debug("GetExRate Response: " + JsonConvert.SerializeObject(response));
  72. return Json(response);
  73. }
  74. [Route("TP/GetStatus")]
  75. [HttpPost]
  76. public IHttpActionResult GetStatus(GetStatus model)
  77. {
  78. if (string.IsNullOrEmpty(model.ProcessId))
  79. model.ProcessId = Guid.NewGuid().ToString();
  80. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  81. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  82. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  83. LogicalThreadContext.Properties["ControlNo"] = model.ControlNo;
  84. LogicalThreadContext.Properties["MethodName"] = "GetStatus";
  85. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  86. // model.SessionId = GetStatic.GetSessionId();
  87. _log.Debug("GetStatus Request: " + JsonConvert.SerializeObject(model));
  88. var response = _sendTxnServices.GetTPResponse(model, "status");
  89. _log.Debug("GetStatus Response: " + JsonConvert.SerializeObject(response));
  90. return Json(response);
  91. }
  92. [Route("TP/sendTxn")]
  93. [HttpPost]
  94. public IHttpActionResult SendTransaction(SendTransaction model)
  95. {
  96. if (string.IsNullOrEmpty(model.ProcessId))
  97. model.ProcessId = Guid.NewGuid().ToString();
  98. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  99. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  100. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  101. LogicalThreadContext.Properties["ControlNo"] = model.Transaction.JMEControlNo;
  102. LogicalThreadContext.Properties["MethodName"] = "SendTransaction";
  103. LogicalThreadContext.Properties["user_name"] = model.TranId;
  104. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  105. // model.SessionId = GetStatic.GetSessionId();
  106. _log.Debug("SendTransaction Request: " + JsonConvert.SerializeObject(model));
  107. TPResponse response = _sendTxnServices.GetTPResponse(model, "send");
  108. LogicalThreadContext.Properties["MethodName"] = "SendTransaction";
  109. _log.Debug("SendTransaction Response: " + JsonConvert.SerializeObject(response));
  110. return Ok(response);
  111. }
  112. [Route("TP/mobileSendTxn")]
  113. [HttpPost]
  114. public IHttpActionResult OnlineOrMobileSendTransaction(SendTransactionMobile model)
  115. {
  116. if (string.IsNullOrEmpty(model.ProcessId))
  117. model.ProcessId = Guid.NewGuid().ToString();
  118. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  119. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  120. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  121. LogicalThreadContext.Properties["ControlNo"] = model.RequestedBy;
  122. LogicalThreadContext.Properties["MethodName"] = "OnlineOrMobileSendTransaction";
  123. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  124. // model.SessionId = GetStatic.GetSessionId();
  125. _log.Debug("OnlineOrMobileSendTransaction Request: " + JsonConvert.SerializeObject(model));
  126. TPResponse response = _sendTxnServices.GetTPResponse(model, "sendV2");
  127. _log.Debug("OnlineOrMobileSendTransaction Response: " + JsonConvert.SerializeObject(response));
  128. return Ok(response);
  129. }
  130. [Route("TP/releaseTxn")]
  131. [HttpPost]
  132. public IHttpActionResult ReleaseTransaction(TFReleaseTxnRequest model)
  133. {
  134. if (string.IsNullOrEmpty(model.ProcessId))
  135. model.ProcessId = Guid.NewGuid().ToString();
  136. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  137. LogicalThreadContext.Properties["requestBy"] = model.UserName ?? model.RequestBy;
  138. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  139. LogicalThreadContext.Properties["ControlNo"] = model.TfPin;
  140. LogicalThreadContext.Properties["MethodName"] = "ReleaseTransaction";
  141. _log.Debug("Transaction release initiated" + JsonConvert.SerializeObject(model));
  142. TPResponse response = _sendTxnServices.GetTPResponse(model, "release");
  143. _log.Debug("Transaction release Response " + JsonConvert.SerializeObject(response));
  144. return Ok(response);
  145. }
  146. [Route("TP/cancelTxn")]
  147. [HttpPost]
  148. public IHttpActionResult CancelTransaction(CancelTxn model)
  149. {
  150. if (string.IsNullOrEmpty(model.ProcessId))
  151. model.ProcessId = Guid.NewGuid().ToString();
  152. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  153. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  154. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  155. LogicalThreadContext.Properties["ControlNo"] = model.PartnerPinNo;
  156. LogicalThreadContext.Properties["MethodName"] = "CancelTransaction";
  157. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  158. // model.SessionId = GetStatic.GetSessionId();
  159. _log.Debug("CancelTransaction initiated" + JsonConvert.SerializeObject(model));
  160. TPResponse response = _sendTxnServices.GetTPResponse(model, "cancelSend");
  161. _log.Debug("CancelTransaction Response " + JsonConvert.SerializeObject(response));
  162. return Ok(response);
  163. }
  164. [Route("TP/amendTxn")]
  165. [HttpPost]
  166. public IHttpActionResult AmendmentRequest(AmendTransaction model)
  167. {
  168. if (string.IsNullOrEmpty(model.ProcessId))
  169. model.ProcessId = Guid.NewGuid().ToString();
  170. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  171. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  172. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  173. LogicalThreadContext.Properties["ControlNo"] = model.TfPinno;
  174. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  175. // model.SessionId = GetStatic.GetSessionId();
  176. LogicalThreadContext.Properties["MethodName"] = "AmendmentRequest";
  177. _log.Debug("AmendmentRequest initiated" + JsonConvert.SerializeObject(model));
  178. TPResponse response = _sendTxnServices.GetTPResponse(model, "amendment");
  179. _log.Debug("AmendmentRequest Response " + JsonConvert.SerializeObject(response));
  180. return Ok(response);
  181. }
  182. [Route("TP/bankList")]
  183. [HttpPost]
  184. public IHttpActionResult GetBankList(BankRequest model)
  185. {
  186. if (string.IsNullOrEmpty(model.ProcessId))
  187. model.ProcessId = Guid.NewGuid().ToString();
  188. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  189. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  190. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  191. LogicalThreadContext.Properties["MethodName"] = "GetBankList";
  192. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  193. _log.Debug("GetBankList initiated" + JsonConvert.SerializeObject(model));
  194. TPResponse response = _sendTxnServices.GetTPResponse(model, "bankList");
  195. //_log.Debug("GetBankList Response " + JsonConvert.SerializeObject(response));
  196. return Ok(response);
  197. }
  198. [Route("TP/agentList")]
  199. [HttpPost]
  200. public IHttpActionResult GetAgentList(AgentRequest model)
  201. {
  202. if (string.IsNullOrEmpty(model.ProcessId))
  203. model.ProcessId = Guid.NewGuid().ToString();
  204. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  205. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  206. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  207. LogicalThreadContext.Properties["MethodName"] = "GetAgentList";
  208. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  209. _log.Debug("GetAgentList initiated" + JsonConvert.SerializeObject(model));
  210. TPResponse response = _sendTxnServices.GetTPResponse(model, "agentList");
  211. //_log.Debug("GetAgentList Response " + JsonConvert.SerializeObject(response));
  212. return Ok(response);
  213. }
  214. [Route("TP/addressList")]
  215. [HttpPost]
  216. public IHttpActionResult GetAddressList(AddressRequest model)
  217. {
  218. if (string.IsNullOrEmpty(model.ProcessId))
  219. model.ProcessId = Guid.NewGuid().ToString();
  220. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  221. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  222. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  223. LogicalThreadContext.Properties["MethodName"] = "GetAddressList";
  224. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  225. // model.SessionId = GetStatic.GetSessionId();
  226. _log.Debug("GetAgentList initiated" + JsonConvert.SerializeObject(model));
  227. string method = "address";
  228. if (model.MethodType!=null && model.MethodType.Equals("loqate"))
  229. {
  230. method = "loqate";
  231. }
  232. TPResponse response = _sendTxnServices.GetTPResponse(model, method);
  233. //_log.Debug("GetAgentList Response " + JsonConvert.SerializeObject(response));
  234. return Ok(response);
  235. }
  236. [Route("TP/senderInfo")]
  237. [HttpPost]
  238. public IHttpActionResult SenderInformation(SenderRequest model)
  239. {
  240. if (string.IsNullOrEmpty(model.ProcessId))
  241. model.ProcessId = Guid.NewGuid().ToString();
  242. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  243. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  244. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  245. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  246. // model.SessionId = GetStatic.GetSessionId();
  247. _log.Debug("SenderInformation initiated" + JsonConvert.SerializeObject(model));
  248. TPResponse response = _sendTxnServices.GetTPResponse(model, "senderinfo");
  249. //_log.Debug("GetAgentList Response " + JsonConvert.SerializeObject(response));
  250. return Ok(response);
  251. }
  252. [Route("TP/getData")]
  253. [HttpPost]
  254. public IHttpActionResult GetStaticData(StaticData model)
  255. {
  256. if (string.IsNullOrEmpty(model.ProcessId))
  257. model.ProcessId = Guid.NewGuid().ToString();
  258. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  259. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  260. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  261. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  262. // model.SessionId = GetStatic.GetSessionId();
  263. _log.Debug("SenderInformation initiated" + JsonConvert.SerializeObject(model));
  264. TPResponse response = _sendTxnServices.GetTPResponse(model, "staticData");
  265. //_log.Debug("GetAgentList Response " + JsonConvert.SerializeObject(response));
  266. return Ok(response);
  267. }
  268. [Route("TP/payer")]
  269. [HttpPost]
  270. public IHttpActionResult GetPayerData(PayerRequest model)
  271. {
  272. if (string.IsNullOrEmpty(model.ProcessId))
  273. model.ProcessId = Guid.NewGuid().ToString();
  274. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  275. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  276. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  277. LogicalThreadContext.Properties["MethodName"] = "GetPayerData";
  278. //if (string.IsNullOrEmpty(model.SessionId) || string.IsNullOrWhiteSpace(model.SessionId))
  279. // model.SessionId = GetStatic.GetSessionId();
  280. _log.Debug("SenderInformation initiated" + JsonConvert.SerializeObject(model));
  281. TPResponse response = _sendTxnServices.GetTPResponse(model, "payer");
  282. //_log.Debug("GetAgentList Response " + JsonConvert.SerializeObject(response));
  283. return Ok(response);
  284. }
  285. [Route("TP/Verify")]
  286. [HttpPost]
  287. public IHttpActionResult VerifyAccount(AccountValidate model)
  288. {
  289. if (string.IsNullOrEmpty(model.ProcessId))
  290. model.ProcessId = Guid.NewGuid().ToString();
  291. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  292. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  293. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  294. LogicalThreadContext.Properties["ControlNo"] = string.IsNullOrEmpty(model.ControlNo) ? model.AccountNumber : model.ControlNo;
  295. LogicalThreadContext.Properties["MethodName"] = "VerifyAccount";
  296. _log.Debug("VerifyAccount Request: " + JsonConvert.SerializeObject(model));
  297. var response = _sendTxnServices.GetTPResponse(model, "verify");
  298. _log.Debug("VerifyAccount Response: " + JsonConvert.SerializeObject(response));
  299. return Json(response);
  300. }
  301. [Route("TP/NotificationAPI")]
  302. [HttpPost]
  303. public IHttpActionResult SendNotificationApi(SendNotificationRequest model)
  304. {
  305. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  306. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  307. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  308. LogicalThreadContext.Properties["ControlNo"] = model.ControlNo;
  309. LogicalThreadContext.Properties["client_ip_address"] = new GetClientIpAddress().GetIpAddress(Request);
  310. LogicalThreadContext.Properties["MethodName"] = "SendNotificationApi";
  311. _log.Debug("SendNotificationApi Request: " + JsonConvert.SerializeObject(model));
  312. var response = _sendTxnServices.GetTPResponse(model, "SendNotificationApi");
  313. _log.Debug("SendNotificationApi Response: " + JsonConvert.SerializeObject(response));
  314. return Json(response);
  315. }
  316. [Route("TP/JWTHelper")]
  317. [HttpPost]
  318. public IHttpActionResult JWTHelper(JWTRequest model)
  319. {
  320. LogicalThreadContext.Properties["processId"] = model.ProcessId;
  321. LogicalThreadContext.Properties["requestBy"] = model.UserName;
  322. LogicalThreadContext.Properties["Provider"] = model.ProviderId;
  323. LogicalThreadContext.Properties["ControlNo"] = model.ControlNo;
  324. LogicalThreadContext.Properties["client_ip_address"] = new GetClientIpAddress().GetIpAddress(Request);
  325. LogicalThreadContext.Properties["MethodName"] = "JWTHelper";
  326. _log.Debug("JWTHelper Request: " + JsonConvert.SerializeObject(model));
  327. var response = _sendTxnServices.GetTPResponse(model, "JWTHelper");
  328. _log.Debug("JWTHelper Response: " + JsonConvert.SerializeObject(response));
  329. return Json(response);
  330. }
  331. }
  332. }