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.

131 lines
4.6 KiB

1 year ago
  1. using Business.TPApi;
  2. using Repository.TrustDoc;
  3. using Business.TrustDoc;
  4. using Common;
  5. using Common.Model;
  6. using Common.Helper;
  7. using Common.Model.TPSendMoney;
  8. using log4net;
  9. using Newtonsoft.Json;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Runtime.Remoting.Messaging;
  14. using System.Text;
  15. using System.Net.Http;
  16. using Repository.KFTCRepository;
  17. using System.Net;
  18. namespace Business.TrustDoc
  19. {
  20. public class TrustDocBusiness : ITrustDocBusiness
  21. {
  22. private readonly ITrustDocRepository _trustrepo;
  23. private readonly ThirdPartyAPI _tpApi = new ThirdPartyAPI();
  24. private static readonly ILog Log = LogManager.GetLogger(typeof(TrustDocBusiness));
  25. private readonly IKftcProcessRepository _repo;
  26. public string Token { get; set; }
  27. public string TrustDocURL { get; set; }
  28. public TrustDocBusiness(ITrustDocRepository trustrepo, KftcProcessRepository repo)
  29. {
  30. _trustrepo = trustrepo;
  31. _repo = repo;
  32. TrustDocURL = ApplicationConfig.ReadWebConfig("TrustDocURL", "");
  33. Token = ApplicationConfig.ReadWebConfig("TrustToken", "");
  34. }
  35. public JsonRxResponse Webhook(TrustDocModel doc)
  36. {
  37. JsonRxResponse jsonRx = new JsonRxResponse();
  38. try
  39. {
  40. jsonRx = _trustrepo.Webhook(doc);
  41. Log.Debug("Webhook | DB RESPONSE : " + JsonConvert.SerializeObject(jsonRx));
  42. if (!jsonRx.ErrorCode.Equals("0"))
  43. {
  44. Log.Debug("Webhook | Error occurred while calling CustomerKYC...");
  45. return jsonRx;
  46. }
  47. return jsonRx;
  48. }
  49. catch (Exception ex)
  50. {
  51. Log.Error("Something Went Wrong, Please Try Again!!", ex);
  52. jsonRx.SetResponse("1", "Error occurred while fetching data.");
  53. return jsonRx;
  54. }
  55. }
  56. public JsonRxResponse CompareData(TrustDocRequest request, string id, string user, string customerId)
  57. {
  58. DbResult _dbResult = new DbResult();
  59. JsonRxResponse jsonResponse = new JsonRxResponse();
  60. try
  61. {
  62. HttpClient client = new HttpClient();
  63. var bodyData = JsonConvert.SerializeObject(request);
  64. //LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "CompareData";
  65. LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = user;
  66. Log.Debug("CompareData | REQUEST : " + bodyData);
  67. _dbResult= _repo.LogRequest(user, "TrustDoc", "comparing_data", customerId, bodyData, id);
  68. client.DefaultRequestHeaders.Add("Authorization", $"Bearer {Token}");
  69. var jbdContent = new StringContent(bodyData, Encoding.UTF8, "application/json");
  70. var URL = TrustDocURL + "verifications/" + id + "/comparing_data";
  71. System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00);
  72. System.Net.ServicePointManager.ServerCertificateValidationCallback =
  73. ((sender, certificate, chain, sslPolicyErrors) => true);
  74. var resp = client.PutAsync(URL, jbdContent).Result;
  75. string resultData = resp.Content.ReadAsStringAsync().Result;
  76. Log.Debug("CompareData | RESPONSE : " + resultData);
  77. _repo.LogResponse(_dbResult.Id, resultData, ((int)resp.StatusCode).ToString(), _dbResult.Extra2);
  78. if (resp.IsSuccessStatusCode)
  79. {
  80. jsonResponse.ErrorCode = "0";
  81. jsonResponse.Msg = "Success";
  82. jsonResponse.Data = resp;
  83. }
  84. else
  85. {
  86. ErrorJosn errorJson = JsonConvert.DeserializeObject<ErrorJosn>(resultData);
  87. //JsonResponse jsonResponseData = JsonConvert.DeserializeObject<JsonResponse>(errorJson.Message);
  88. jsonResponse.ErrorCode = "1";
  89. jsonResponse.Msg = errorJson.Message;
  90. jsonResponse.Data = errorJson;
  91. }
  92. return jsonResponse;
  93. }
  94. catch (Exception ex)
  95. {
  96. var e = new JsonRxResponse()
  97. {
  98. ErrorCode = "1",
  99. Msg = (ex.InnerException == null ? ex.Message : ex.InnerException.Message)
  100. };
  101. _repo.LogResponse(_dbResult.Id, _dbResult.Extra2, "999", JsonConvert.SerializeObject(e));
  102. return e;
  103. }
  104. }
  105. }
  106. }