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.

162 lines
6.2 KiB

  1. using System;
  2. using Swift.DAL.BL.Remit.Transaction;
  3. using Swift.web.Library;
  4. using System.Text;
  5. using Swift.DAL.Common;
  6. using Swift.DAL.SwiftDAL;
  7. using System.Web.Script.Serialization;
  8. namespace Swift.web.Remit.Transaction.Cancel
  9. {
  10. public partial class CancelReceipt : System.Web.UI.Page
  11. {
  12. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  13. private CancelTransactionDao _obj = new CancelTransactionDao();
  14. private const string ViewFunctionId = "20121400";
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. Authenticate();
  18. LoadReceipt();
  19. }
  20. private void Authenticate()
  21. {
  22. _sl.CheckAuthentication(ViewFunctionId);
  23. }
  24. private long GetTranId()
  25. {
  26. return GetStatic.ReadNumericDataFromQueryString("tranId");
  27. }
  28. private void LoadReceipt()
  29. {
  30. var dr = _obj.LoadReceipt(GetStatic.GetUser(), GetTranId().ToString());
  31. if (dr == null)
  32. return;
  33. controlNo.Text = dr["controlNo"].ToString();
  34. postedBy.Text = dr["postedBy"].ToString();
  35. sender.Text = dr["sender"].ToString();
  36. receiver.Text = dr["receiver"].ToString();
  37. rContactNo.Text = dr["rContactNo"].ToString();
  38. collCurr.Text = dr["collCurr"].ToString();
  39. cAmt.Text = GetStatic.FormatData(dr["cAmt"].ToString(), "M");
  40. serviceCharge.Text = GetStatic.FormatData(dr["serviceCharge"].ToString(), "M");
  41. pAmt.Text = GetStatic.FormatData(dr["pAmt"].ToString(), "M");
  42. cancelCharge.Text = GetStatic.FormatData(dr["cancelCharge"].ToString(), "M");
  43. returnAmt.Text = GetStatic.FormatData(dr["returnAmt"].ToString(), "M");
  44. sendDate.Text = dr["createdDate"].ToString();
  45. cancelDate.Text = dr["cancelDate"].ToString();
  46. if (!string.IsNullOrWhiteSpace(dr["BankName"].ToString()))
  47. {
  48. autoDebitTR.Visible = true;
  49. accName.Text = dr["AccName"].ToString();
  50. accNo.Text = dr["AccNo"].ToString();
  51. bankName.Text = dr["BankName"].ToString();
  52. // REQUEST FOR KFCT AUTO REFUND TRANSACTION
  53. KJAutoRefundModel postData = new KJAutoRefundModel()
  54. {
  55. flag = "Autodebit_REQ",
  56. customerId = dr["customerId"].ToString(),
  57. customerSummary = "",
  58. amount = GetStatic.RemoveComaFromMoney(dr["returnAmt"].ToString()),
  59. action = "REQ",
  60. actionBy = GetStatic.GetUser(),
  61. bankCode = dr["bankCode"].ToString(),
  62. bankAccountNo = dr["AccNo"].ToString()
  63. };
  64. // REFUNDING KFTC AUTO DEBIT TRANSACTION
  65. var Response = RefundAutodebitTxnAmount(postData);
  66. if (Response.ErrorCode == "1")
  67. {
  68. SendEmail();
  69. }
  70. }
  71. }
  72. private DbResult RefundAutodebitTxnAmount(KJAutoRefundModel postData)
  73. {
  74. DbResult dbResult = new DbResult()
  75. {
  76. ErrorCode = "1",
  77. Msg = "Fail!"
  78. };
  79. /* 1. KFTC AUTO REFUND LOG
  80. * */
  81. dbResult = _obj.SendAutoRefund(postData);
  82. postData.rowId = dbResult.Id;
  83. if (dbResult.ErrorCode != "0")
  84. {
  85. return dbResult;
  86. }
  87. /*
  88. * 3. KJ API FOR AUTO REFUND
  89. * */
  90. AccountTransferToBank req = new AccountTransferToBank()
  91. {
  92. obpId = "", // "001-90010001-000001-6000001", //GME OBPID
  93. accountNo = "",// "1107020345626", //GME 계좌코드
  94. accountPassword = "", // "1212", //GME 패스워드
  95. receiveInstitution = postData.bankCode,
  96. receiveAccountNo = postData.bankAccountNo,
  97. //receiveInstitution = data.Msg,
  98. //receiveAccountNo = data.Id,
  99. amount = Convert.ToString(postData.amount),
  100. bankBookSummary = String.Format("REFUND{0}", postData.bankAccountNo),
  101. transactionSummary = "GME Refund"
  102. };
  103. var baseUrl = GetStatic.ReadWebConfig("KJURL", "");
  104. var kjSecretKey = GetStatic.ReadWebConfig("KJsecretKey", "");
  105. var clientId = GetStatic.ReadWebConfig("client_id", "");
  106. string body = new JavaScriptSerializer().Serialize((req));
  107. // KJ BANK API CALLING FOR AMOUNT REFUND IN BANK
  108. var apiResponse = KJBankAPIConnection.AccountTransferKJBank(body, baseUrl, kjSecretKey, clientId);
  109. if (apiResponse.ErrorCode != "0")
  110. {
  111. postData.flag = "Autodebit_FAIL";
  112. postData.action = "FAIL";
  113. }
  114. else
  115. {
  116. postData.flag = "SUCCESS";
  117. postData.action = "SUCCESS";
  118. }
  119. dbResult = _obj.SendAutoRefund(postData);
  120. return apiResponse;
  121. }
  122. private void SendEmail()
  123. {
  124. StringBuilder sb = new StringBuilder();
  125. sb.AppendLine("KFTC auto refund process has failed!.");
  126. sb.AppendLine("Kindly refund JPY " + returnAmt.Text + " to customer's account for cancelled auto debit transaction " + controlNo.Text);
  127. sb.AppendLine("</br>");
  128. sb.AppendLine("Account Name: <strong>" + accName.Text + "</strong>");
  129. sb.AppendLine("</br>");
  130. sb.AppendLine("Account Number: <strong>" + accNo.Text + "</strong>");
  131. sb.AppendLine("</br>");
  132. sb.AppendLine("Bank Name: <strong>" + bankName.Text + "</strong>");
  133. sb.AppendLine("Regards,");
  134. sb.AppendLine("JME Remittance<br>, Japan");
  135. SmtpMailSetting mail = new SmtpMailSetting
  136. {
  137. MsgBody = sb.ToString(),
  138. MsgSubject = "AUTODEBIT CANCELLATION REFUND",
  139. ToEmails = "atit.pandey@gmeremit.com",
  140. CcEmails = "itsupport@gmeremit.com"
  141. };
  142. mail.SendSmtpMail(mail);
  143. }
  144. }
  145. }