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.

261 lines
10 KiB

1 year ago
  1. using Business.TPApi;
  2. using Common;
  3. using Common.Helper;
  4. using Common.Model.Remit;
  5. using log4net;
  6. using Newtonsoft.Json;
  7. using System;
  8. namespace Business.Remit
  9. {
  10. public class RemitBusiness : IRemitBusiness
  11. {
  12. private readonly ThirdPartyAPI _tpApi = new ThirdPartyAPI();
  13. private static readonly ILog Log = LogManager.GetLogger(typeof(RemitBusiness));
  14. public RemitBusiness() { }
  15. public JsonRxResponse SearchTxnByControlNumber(SearchTxnModel searchTxn)
  16. {
  17. APIJsonResponse _apiJsonResponse = new APIJsonResponse();
  18. JsonRxResponse _jsonResp = new JsonRxResponse();
  19. try
  20. {
  21. Log.DebugFormat("SearchTxnByControlNumber | Calling SearchTxnByControlNumber method.");
  22. SearchTxnThirdparty _searchTxn = new SearchTxnThirdparty
  23. {
  24. PBranch = GetStatic.ReadWebConfig("sBranch", ""),
  25. ControlNo = searchTxn.controlNumber,
  26. ProcessId = searchTxn.ProcessId,
  27. RequestFrom = "mobile",
  28. SessionId = searchTxn.ProcessId,
  29. UserName = searchTxn.userID
  30. };
  31. APIJsonResponse _result = new APIJsonResponse();
  32. //uncoment after creating the lo0gic in TP API
  33. _result = _tpApi.ThirdPartyApiGetDataOnly<SearchTxnThirdparty, APIJsonResponse>(_searchTxn, "TP/payTxnCheck", out _apiJsonResponse);
  34. //for now putting hardcode value by creating a dummy method
  35. //_result = GetResponseDummyData(searchTxn);
  36. Log.Debug("SearchTxnByControlNumber | Calling SearchTxnByControlNumber with response..." + JsonConvert.SerializeObject(_result));
  37. return _jsonResp = new JsonRxResponse()
  38. {
  39. ErrorCode = _result.ResponseCode,
  40. Id = _result.Id,
  41. Msg = _result.Msg,
  42. Data = _result.Data,
  43. Extra = _result.Extra,
  44. Extra2 = _result.Extra1
  45. };
  46. }
  47. catch (Exception ex)
  48. {
  49. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  50. _jsonResp.SetResponse("1", "Could not complete the request.");
  51. return _jsonResp;
  52. }
  53. }
  54. public JsonRxResponse RedeemCashPayment(ConfirmTxnModel redeemTxn)
  55. {
  56. APIJsonResponse _apiJsonResponse = new APIJsonResponse();
  57. JsonRxResponse _jsonResp = new JsonRxResponse();
  58. try
  59. {
  60. Log.DebugFormat("RedeemCashPayment | Calling RedeemCashPayment method.");
  61. ConfirmTxnThirdParty _confirmTxn = new ConfirmTxnThirdParty
  62. {
  63. PBranch = GetStatic.ReadWebConfig("sBranch", ""),
  64. ControlNo = redeemTxn.controlNumber,
  65. ProcessId = redeemTxn.ProcessId,
  66. RequestFrom = "mobile",
  67. SessionId = redeemTxn.ProcessId,
  68. UserName = redeemTxn.userID,
  69. txnId = redeemTxn.txnId,
  70. password = redeemTxn.password
  71. };
  72. APIJsonResponse _result = new APIJsonResponse();
  73. //uncoment after creating the lo0gic in TP API
  74. _result = _tpApi.ThirdPartyApiGetDataOnly<ConfirmTxnThirdParty, APIJsonResponse>(_confirmTxn, "TP/payTxnConfirm", out _apiJsonResponse);
  75. Log.Debug("RedeemCashPayment | Calling RedeemCashPayment with response..." + JsonConvert.SerializeObject(_result));
  76. //for now returning harcode success value
  77. return _jsonResp = new JsonRxResponse()
  78. {
  79. ErrorCode = _result.ResponseCode,
  80. Msg = _result.Msg,
  81. };
  82. }
  83. catch (Exception ex)
  84. {
  85. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  86. _jsonResp.SetResponse("1", "Could not complete the request.");
  87. return _jsonResp;
  88. }
  89. }
  90. public JsonRxResponse WithdrawWalletRequest(WithdrawWalletRequestModel withdrawWalletRequest)
  91. {
  92. APIJsonResponse _apiJsonResponse = new APIJsonResponse();
  93. JsonRxResponse _jsonResp = new JsonRxResponse();
  94. try
  95. {
  96. Log.DebugFormat("WithdrawWalletRequest | Calling WithdrawWalletRequest method.");
  97. APIJsonResponse _result = new APIJsonResponse();
  98. withdrawWalletRequest.UserName = withdrawWalletRequest.userID;
  99. _result = _tpApi.ThirdPartyApiGetDataOnly<WithdrawWalletRequestModel, APIJsonResponse>(withdrawWalletRequest, "TP/withdrawWalletRequest", out _apiJsonResponse);
  100. Log.Debug("WithdrawWalletRequest | Calling WithdrawWalletRequest with response..." + JsonConvert.SerializeObject(_result));
  101. //for now returning harcode success value
  102. return _jsonResp = new JsonRxResponse()
  103. {
  104. ErrorCode = _result.ResponseCode,
  105. Id = _result.Id,
  106. Msg = _result.Msg,
  107. Data = _result.Data,
  108. Extra = _result.Extra,
  109. Extra2 = _result.Extra1
  110. };
  111. }
  112. catch (Exception ex)
  113. {
  114. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  115. _jsonResp.SetResponse("1", "Could not complete the request.");
  116. return _jsonResp;
  117. }
  118. }
  119. public JsonRxResponse WithdrawFromWallet(WithdrawFromWalletModel withdrawWallet)
  120. {
  121. APIJsonResponse _apiJsonResponse = new APIJsonResponse();
  122. JsonRxResponse _jsonResp = new JsonRxResponse();
  123. try
  124. {
  125. Log.DebugFormat("WithdrawFromWallet | Calling WithdrawFromWallet method.");
  126. APIJsonResponse _result = new APIJsonResponse();
  127. withdrawWallet.UserName = withdrawWallet.userID;
  128. _result = _tpApi.ThirdPartyApiGetDataOnly<WithdrawFromWalletModel, APIJsonResponse>(withdrawWallet, "TP/withdrawFromWallet", out _apiJsonResponse);
  129. Log.Debug("WithdrawFromWallet | Calling WithdrawFromWallet with response..." + JsonConvert.SerializeObject(_result));
  130. //for now returning harcode success value
  131. return _jsonResp = new JsonRxResponse()
  132. {
  133. ErrorCode = _result.ResponseCode,
  134. Msg = _result.Msg
  135. };
  136. }
  137. catch (Exception ex)
  138. {
  139. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  140. _jsonResp.SetResponse("1", "Could not complete the request.");
  141. return _jsonResp;
  142. }
  143. }
  144. public APIJsonResponse GetResponseDummyData(SearchTxnModel searchTxn)
  145. {
  146. APIJsonResponse _apiResp = new APIJsonResponse();
  147. if (searchTxn.controlNumber != "12345678")
  148. {
  149. _apiResp = new APIJsonResponse
  150. {
  151. ResponseCode = "1",
  152. Msg = "Invalid Transaction!"
  153. };
  154. return _apiResp;
  155. }
  156. _apiResp = new APIJsonResponse
  157. {
  158. ResponseCode = "0",
  159. Msg = "Success"
  160. };
  161. _apiResp.Data = new
  162. {
  163. txnId = "100001",
  164. sendingCountryCode = "NP",
  165. sendingCountryName = "Nepal",
  166. controlNo = searchTxn.controlNumber,
  167. tranDate = "2020-01-01",
  168. senderName = "Test Sender For Nepal",
  169. receiverName = "Test Recv. Name",
  170. receiverAddress = "Mongolia, test address",
  171. receiverMobile = "9848741445",
  172. status = "Unpaid",
  173. serviceFee = "0.00",
  174. exrate = "2.00",
  175. receivedAmount = "1000.00"
  176. };
  177. return _apiResp;
  178. }
  179. private APIJsonResponse GetResponseDummyDataWithdraw(WithdrawWalletRequestModel withdrawWalletRequest)
  180. {
  181. APIJsonResponse _apiResp = new APIJsonResponse();
  182. if (GetStatic.ParseDouble(withdrawWalletRequest.amount) > 100000)
  183. {
  184. _apiResp = new APIJsonResponse
  185. {
  186. ResponseCode = "1",
  187. Msg = "Withdraw amount can not be greater than 100,000!"
  188. };
  189. return _apiResp;
  190. }
  191. if (GetStatic.ParseDouble(withdrawWalletRequest.amount) < 1000)
  192. {
  193. _apiResp = new APIJsonResponse
  194. {
  195. ResponseCode = "1",
  196. Msg = "Withdraw amount can not be less than 1000!"
  197. };
  198. return _apiResp;
  199. }
  200. _apiResp = new APIJsonResponse
  201. {
  202. ResponseCode = "0",
  203. Msg = "Success"
  204. };
  205. string sc = "0";
  206. if (GetStatic.ParseDouble(withdrawWalletRequest.amount) > 1000 && GetStatic.ParseDouble(withdrawWalletRequest.amount) <= 10000)
  207. sc = "50";
  208. if (GetStatic.ParseDouble(withdrawWalletRequest.amount) > 10000 && GetStatic.ParseDouble(withdrawWalletRequest.amount) <= 20000)
  209. sc = "80";
  210. if (GetStatic.ParseDouble(withdrawWalletRequest.amount) > 20000 && GetStatic.ParseDouble(withdrawWalletRequest.amount) <= 50000)
  211. sc = "150";
  212. if (GetStatic.ParseDouble(withdrawWalletRequest.amount) > 50000 && GetStatic.ParseDouble(withdrawWalletRequest.amount) <= 100000)
  213. sc = "250";
  214. _apiResp.Data = new
  215. {
  216. bankName = "Mangolia test Bank",
  217. accountNo = "789748524",
  218. serviceCharge = sc,
  219. amount = withdrawWalletRequest.amount,
  220. noticeMessage = "This is test notice msg!"
  221. };
  222. return _apiResp;
  223. }
  224. }
  225. }