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.

193 lines
7.2 KiB

1 year ago
  1. using Common;
  2. using Common.Helper;
  3. using Common.InboundModel;
  4. using Common.Model.AutoRefund;
  5. using Common.Model.Enum;
  6. using Common.Model.KwangjuBank;
  7. using Common.Model.PennyTest;
  8. using log4net;
  9. using Newtonsoft.Json;
  10. using Repository.Inbound;
  11. using System;
  12. namespace Business.Inbound
  13. {
  14. public interface IInboundPennyTestBusiness
  15. {
  16. JsonRxResponse StartInbound(string user, PennyTestRequestParam param, string reSendCode);
  17. JsonRxResponse VerifyCertificate(PennyCertVerifyRequestModel model);
  18. }
  19. public class InboundPennyTestBusiness : IInboundPennyTestBusiness
  20. {
  21. private readonly IInboundPennyTestRepository _repo;
  22. private static readonly ILog Log = LogManager.GetLogger(typeof(InboundPennyTestBusiness));
  23. public InboundPennyTestBusiness(IInboundPennyTestRepository repo)
  24. {
  25. _repo = repo;
  26. }
  27. public JsonRxResponse StartInbound(string user, PennyTestRequestParam param, string reSendCode)
  28. {
  29. var response = new JsonRxResponse();
  30. if (!string.IsNullOrWhiteSpace(param.accountID) && !string.IsNullOrWhiteSpace(param.accountType) && param.accountType == "autodebit")
  31. {
  32. var s = GetAutoDebitAccountById(param);
  33. if (s != null)
  34. {
  35. param.AccountNo = s.AccountNo;
  36. param.BankCode = s.BankCode;
  37. }
  38. else
  39. {
  40. response.SetResponse("1", "Penny test request failed");
  41. return response;
  42. }
  43. }
  44. string certNumber = Crypto.GetRandomNumber(4);
  45. //GET CUSTOMER DETAIL FOR REAL NAME VERIFICATION AND PENNY TEST
  46. var model = new PennyTestStartRequestModel();
  47. model.CustomerId = user;
  48. model.BankCode = param.BankCode;
  49. model.BankAccountNo = param.AccountNo;
  50. var succesMsg = string.Format("We have sent 1 KRW to your Bank Account {0} with {1} Bank, Please check the statement and enter the 4 digit number display after GME.", model.BankAccountNo, model.BankName);
  51. if (model.ErrorCode == "1")
  52. {
  53. response.ErrorCode = "0";
  54. response.Msg = succesMsg;
  55. response.Data = new { Message = succesMsg };
  56. return response;
  57. }
  58. else if (model.ErrorCode == "10" && reSendCode.ToLower() == "n")
  59. {
  60. response.ErrorCode = "0";
  61. response.Msg = succesMsg;
  62. response.Data = new { Message = succesMsg };
  63. return response;
  64. }
  65. //FOR TESTING
  66. //req.institution = "034";
  67. //req.no = "145121636083";
  68. //req.realNameDivision = "02";
  69. //req.realNameNo = "8502046803408";
  70. //SENDING 1KRW INTO CUSTOMER PRIMARY BANK TO VERIFY BANK DETAIL
  71. AmountTransferToBank pennyTrans = new AmountTransferToBank
  72. {
  73. obpId = "", // "001-90010001-000001-6000001", //GME OBPID
  74. accountNo = "KJ",// "1107020345626", //GME ????
  75. accountPassword = "", // "1212", //GME ????
  76. receiveInstitution = model.BankCode.ToString(),
  77. receiveAccountNo = model.BankAccountNo.Replace("-", ""),
  78. amount = "1",
  79. bankBookSummary = String.Format("PENNY-{0}", model.BankAccountNo.Replace("-", "").ToString()),
  80. transactionSummary = String.Format("GME-{0}", certNumber)// THIS IS NARRATION FIELD
  81. };
  82. //FOR TESTING
  83. //pennyTrans.receiveInstitution = "034";
  84. //pennyTrans.receiveAccountNo = "145121636083";
  85. var body = JsonConvert.SerializeObject(pennyTrans);
  86. var resp = KwangjuBankApi.TransferAmount(body);
  87. var dbApiRes = JsonConvert.DeserializeObject<JsonRxResponse>(resp);
  88. if (!dbApiRes.ErrorCode.Equals("0"))
  89. {
  90. if (dbApiRes.ErrorCode.Equals(ErrorCode.One))
  91. {
  92. var kjMsg = JsonConvert.DeserializeObject<KwangjuResult>(dbApiRes.Msg);
  93. var eCode = kjMsg.error.code.ToString();
  94. var eMessage = kjMsg.error.message.ToString();
  95. dbApiRes.Msg = "Something is wrong. " + eCode + " " + eMessage;
  96. }
  97. dbApiRes.Data = new { Message = dbApiRes.Msg };
  98. return dbApiRes;
  99. }
  100. var idNum = !string.IsNullOrWhiteSpace(model.IdNumber) ? model.IdNumber.Replace("-", "") : "";
  101. var cert = new PennyTestCustomerCert()
  102. {
  103. CustomerId = model.CustomerId,
  104. CertNumber = certNumber,
  105. CertLimitCount = "",
  106. BankCode = model.BankCode,
  107. BankAccountNo = model.BankAccountNo.Replace("-", ""),
  108. IdType = model.IdType ?? "",
  109. IdNumber = idNum,
  110. Dob = model.Dob ?? "",
  111. Gender = model.Gender ?? "",
  112. NativeCountry = model.NativeCountry ?? "",
  113. Action = "REQ"
  114. };
  115. var respon = _repo.SavePennyTestCustomerCertificate(cert);
  116. if (!respon.ErrorCode.Equals("0"))
  117. {
  118. respon.Data = new { Message = respon.Msg };
  119. }
  120. else
  121. {
  122. respon.Msg = succesMsg;
  123. respon.Data = new { Message = succesMsg };
  124. }
  125. return respon;
  126. }
  127. public JsonRxResponse VerifyCertificate(PennyCertVerifyRequestModel model)
  128. {
  129. JsonRxResponse rsp = new JsonRxResponse();
  130. if (!string.IsNullOrWhiteSpace(model.accountID) && !string.IsNullOrWhiteSpace(model.accountType) && model.accountType == "autodebit")
  131. {
  132. var param = new PennyTestRequestParam()
  133. {
  134. accountID = model.accountID,
  135. AccountNo = model.AccountNo,
  136. accountType = model.accountType
  137. ,
  138. BankCode = model.BankCode
  139. };
  140. var s = GetAutoDebitAccountById(param);
  141. if (s != null)
  142. {
  143. model.AccountNo = s.AccountNo;
  144. model.BankCode = s.BankCode;
  145. }
  146. else
  147. {
  148. rsp.SetResponse("1", "Penny test verification failed");
  149. return rsp;
  150. }
  151. }
  152. rsp = _repo.VerifyCertificate(model.CustomerId, model.CertNumber, model.BankCode, model.AccountNo);
  153. rsp.Data = new { Message = rsp.Msg };
  154. return rsp;
  155. }
  156. private PennyTestRequestParam GetAutoDebitAccountById(PennyTestRequestParam param)
  157. {
  158. try
  159. {
  160. var id = Crypto.Decrypt(param.accountID, Utilities.ReadWebConfig("ktft_client_info_salt", ""));
  161. PennyTestRequestParam res = _repo.GetAutoDebitAccountById(id);
  162. return res;
  163. }
  164. catch (Exception ex)
  165. {
  166. Log.Error("Error during decrypting autodebit id", ex);
  167. return null;
  168. }
  169. }
  170. }
  171. }