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.

163 lines
7.1 KiB

  1. using System;
  2. using System.Net;
  3. using BankOfCeylon.BOCServiceReference;
  4. using BankOfCeylon.Model;
  5. using Common.Models.Bank_Account;
  6. using Common.Models.RequestResponse;
  7. using Common.Models.Status;
  8. using Common.Models.TxnModel;
  9. using Common.TPService;
  10. using Common.Utility;
  11. using log4net;
  12. namespace BankOfCeylon.BankOfCeylonAPIService
  13. {
  14. public class BankOfCeylonAPI : ITPApiServices
  15. {
  16. private readonly ILog _log = LogManager.GetLogger(typeof(BankOfCeylonAPI));
  17. ServiceComClient _service = new ServiceComClient();
  18. string UserName = GetStatic.ReadWebConfig("boc_username", "");
  19. string Password = GetStatic.ReadWebConfig("boc_password", "");
  20. string BankAccLKR = GetStatic.ReadWebConfig("boc_account_no_lkr", "");
  21. string BankAccUSD = GetStatic.ReadWebConfig("boc_account_no_usd", "");
  22. string ChargingType = GetStatic.ReadWebConfig("boc_chargin_type", "");
  23. string SMSAlertReceiver = GetStatic.ReadWebConfig("boc_sms_alert", "");
  24. public BankOfCeylonAPI()
  25. {
  26. _service.ClientCredentials.UserName.UserName = UserName;
  27. _service.ClientCredentials.UserName.Password = Password;
  28. ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072 | (SecurityProtocolType)192 | (SecurityProtocolType)48;
  29. ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
  30. }
  31. public TPResponse GetTPResponse<T>(T model, string MethodName) where T : class
  32. {
  33. switch (MethodName)
  34. {
  35. case "send":
  36. return SendTransaction(model as SendTransaction);
  37. case "verify":
  38. return AccountValidation(model as AccountValidate);
  39. case "status":
  40. return GetTxnStatus(model as GetStatus);
  41. default:
  42. return new TPResponse() { ResponseCode = "1", Msg = "Method Name Not Found !" };
  43. }
  44. }
  45. private TPResponse SendTransaction(SendTransaction sendTransaction)
  46. {
  47. SendMoneyModel requestTxn = SendModelMap(sendTransaction);
  48. TPResponse _response = new CustomModelValidaton().IsModelValid(requestTxn);
  49. if (_response == null)
  50. {
  51. _response = new TPResponse();
  52. string reqJson = GetStatic.ObjectToJson(requestTxn);
  53. _log.Info("SendTransaction | REQUEST :" + GetStatic.ObjectToJson(requestTxn));
  54. remittanceRespons response = _service.SendRem(requestTxn.CUSPIN, requestTxn.SENDERACCOUNTNO, requestTxn.CURRENCY, requestTxn.REMITTENCETYPE
  55. , requestTxn.SENDERNAME, requestTxn.BENEFICIARYNAME, requestTxn.BENEFICIARYADD, requestTxn.BENEFICIARYPHONE
  56. , requestTxn.BENEFICIARYID, requestTxn.BANKACCTNO, requestTxn.BANKNAME, requestTxn.BANKADDRESS, requestTxn.SENDERPHONE
  57. , requestTxn.SENDRESINFO, requestTxn.TRANSACTIONREF, requestTxn.SMSALERT, requestTxn.AMOUNT, requestTxn.CHARGE);
  58. string resJson = GetStatic.ObjectToJson(response);
  59. _log.Info("SendTransaction | RESPONSE :" + GetStatic.ObjectToJson(response));
  60. _response.ResponseCode = response.responseCode == "456" ? "0" : "1";
  61. _response.Msg = response.msg;
  62. //_response.Extra = response.response;
  63. _response.Data = response;
  64. }
  65. else
  66. {
  67. _log.Info("SendTransaction | MODEL VALIDATION FAILED :" + GetStatic.ObjectToJson(requestTxn));
  68. }
  69. return _response;
  70. }
  71. private TPResponse GetTxnStatus(GetStatus getStatus)
  72. {
  73. TPResponse _response = new CustomModelValidaton().IsModelValid(getStatus);
  74. if (_response == null)
  75. {
  76. _response = new TPResponse();
  77. _log.Info("GetTxnStatus | REQUEST :" + GetStatic.ObjectToJson(getStatus));
  78. remittanceRespons response = _service.StatusRem(getStatus.ControlNo);
  79. _log.Info("GetTxnStatus | RESPONSE :" + GetStatic.ObjectToJson(response));
  80. string paidStatus = "UNPAID";
  81. if (response.response.responseStatusCode == "514")
  82. paidStatus = "PAID";
  83. if (response.response.responseStatusCode == "515")
  84. paidStatus = "PAID";
  85. if (response.response.responseStatusCode == "516")
  86. paidStatus = "PAID";
  87. if (response.response.responseStatusCode == "615")
  88. paidStatus = "PAID";
  89. _response.ResponseCode = paidStatus == "PAID" ? "0" : "1";
  90. _response.Msg = response.response.resposnseStatusMsg;
  91. _response.Extra = paidStatus;
  92. _response.Extra2 = response.response.responseStatusCode;
  93. _response.Data = response.response;
  94. if (!_response.ResponseCode.Equals("0"))
  95. {
  96. _response.ResponseCode = "1";
  97. }
  98. }
  99. else
  100. {
  101. _log.Info("GetTxnStatus | MODEL VALIDATION FAILED :" + GetStatic.ObjectToJson(getStatus).ToString());
  102. }
  103. return _response;
  104. }
  105. private SendMoneyModel SendModelMap(SendTransaction sendTransaction)
  106. {
  107. return new SendMoneyModel {
  108. CUSPIN = sendTransaction.Transaction.JMEControlNo,
  109. SENDERACCOUNTNO = sendTransaction.Transaction.PCurr.ToLower() == "lkr" ? BankAccLKR : BankAccUSD,
  110. CURRENCY = sendTransaction.Transaction.PCurr,
  111. REMITTENCETYPE = sendTransaction.Transaction.PaymentType,
  112. SENDERNAME = sendTransaction.Sender.SFullName,
  113. BENEFICIARYNAME = sendTransaction.Receiver.RFullName,
  114. BENEFICIARYADD = sendTransaction.Receiver.RAdd1,
  115. BENEFICIARYPHONE = sendTransaction.Receiver.RMobile,
  116. BENEFICIARYID = sendTransaction.Receiver.RIdNo,
  117. BANKACCTNO = sendTransaction.Receiver.RAccountNo,
  118. BANKNAME = sendTransaction.Agent.PBankId,
  119. BANKADDRESS = sendTransaction.Receiver.RLocation,
  120. SENDERPHONE = sendTransaction.Sender.SMobile,
  121. SENDRESINFO = sendTransaction.Transaction.PayoutMsg,
  122. TRANSACTIONREF = sendTransaction.TranId.ToString(),
  123. SMSALERT = SMSAlertReceiver,
  124. AMOUNT = Convert.ToDouble(sendTransaction.Transaction.PAmt),
  125. CHARGE = ChargingType
  126. };
  127. }
  128. private TPResponse AccountValidation(AccountValidate accountValidate)
  129. {
  130. TPResponse response = new TPResponse();
  131. response.SetResponse("1", "Invalid Account", null);
  132. verifyAccResponse res = _service.VerifyAccount(accountValidate.AccountNumber);
  133. if (res.verifyCode == "028")
  134. {
  135. response.ResponseCode = "0";
  136. response.Msg = res.verifyMsg;
  137. }
  138. return response;
  139. }
  140. }
  141. }