|
|
using Common; using Common.Helper; using Common.InboundModel; using Common.Model.AutoRefund; using Common.Model.Enum; using Common.Model.KwangjuBank; using Common.Model.PennyTest; using log4net; using Newtonsoft.Json; using Repository.Inbound; using System;
namespace Business.Inbound { public interface IInboundPennyTestBusiness { JsonRxResponse StartInbound(string user, PennyTestRequestParam param, string reSendCode);
JsonRxResponse VerifyCertificate(PennyCertVerifyRequestModel model); }
public class InboundPennyTestBusiness : IInboundPennyTestBusiness { private readonly IInboundPennyTestRepository _repo; private static readonly ILog Log = LogManager.GetLogger(typeof(InboundPennyTestBusiness));
public InboundPennyTestBusiness(IInboundPennyTestRepository repo) { _repo = repo; }
public JsonRxResponse StartInbound(string user, PennyTestRequestParam param, string reSendCode) { var response = new JsonRxResponse(); if (!string.IsNullOrWhiteSpace(param.accountID) && !string.IsNullOrWhiteSpace(param.accountType) && param.accountType == "autodebit") { var s = GetAutoDebitAccountById(param); if (s != null) { param.AccountNo = s.AccountNo; param.BankCode = s.BankCode; } else { response.SetResponse("1", "Penny test request failed"); return response; } }
string certNumber = Crypto.GetRandomNumber(4);
//GET CUSTOMER DETAIL FOR REAL NAME VERIFICATION AND PENNY TEST
var model = new PennyTestStartRequestModel(); model.CustomerId = user; model.BankCode = param.BankCode; model.BankAccountNo = param.AccountNo; 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);
if (model.ErrorCode == "1") { response.ErrorCode = "0"; response.Msg = succesMsg; response.Data = new { Message = succesMsg }; return response; } else if (model.ErrorCode == "10" && reSendCode.ToLower() == "n") { response.ErrorCode = "0"; response.Msg = succesMsg; response.Data = new { Message = succesMsg }; return response; } //FOR TESTING
//req.institution = "034";
//req.no = "145121636083";
//req.realNameDivision = "02";
//req.realNameNo = "8502046803408";
//SENDING 1KRW INTO CUSTOMER PRIMARY BANK TO VERIFY BANK DETAIL
AmountTransferToBank pennyTrans = new AmountTransferToBank { obpId = "", // "001-90010001-000001-6000001", //GME OBPID
accountNo = "KJ",// "1107020345626", //GME ????
accountPassword = "", // "1212", //GME ????
receiveInstitution = model.BankCode.ToString(), receiveAccountNo = model.BankAccountNo.Replace("-", ""), amount = "1", bankBookSummary = String.Format("PENNY-{0}", model.BankAccountNo.Replace("-", "").ToString()), transactionSummary = String.Format("GME-{0}", certNumber)// THIS IS NARRATION FIELD
};
//FOR TESTING
//pennyTrans.receiveInstitution = "034";
//pennyTrans.receiveAccountNo = "145121636083";
var body = JsonConvert.SerializeObject(pennyTrans); var resp = KwangjuBankApi.TransferAmount(body); var dbApiRes = JsonConvert.DeserializeObject<JsonRxResponse>(resp);
if (!dbApiRes.ErrorCode.Equals("0")) { if (dbApiRes.ErrorCode.Equals(ErrorCode.One)) { var kjMsg = JsonConvert.DeserializeObject<KwangjuResult>(dbApiRes.Msg); var eCode = kjMsg.error.code.ToString(); var eMessage = kjMsg.error.message.ToString();
dbApiRes.Msg = "Something is wrong. " + eCode + " " + eMessage; }
dbApiRes.Data = new { Message = dbApiRes.Msg }; return dbApiRes; }
var idNum = !string.IsNullOrWhiteSpace(model.IdNumber) ? model.IdNumber.Replace("-", "") : "";
var cert = new PennyTestCustomerCert() { CustomerId = model.CustomerId, CertNumber = certNumber, CertLimitCount = "", BankCode = model.BankCode, BankAccountNo = model.BankAccountNo.Replace("-", ""), IdType = model.IdType ?? "", IdNumber = idNum, Dob = model.Dob ?? "", Gender = model.Gender ?? "", NativeCountry = model.NativeCountry ?? "", Action = "REQ" };
var respon = _repo.SavePennyTestCustomerCertificate(cert); if (!respon.ErrorCode.Equals("0")) { respon.Data = new { Message = respon.Msg }; } else { respon.Msg = succesMsg; respon.Data = new { Message = succesMsg }; }
return respon; }
public JsonRxResponse VerifyCertificate(PennyCertVerifyRequestModel model) { JsonRxResponse rsp = new JsonRxResponse(); if (!string.IsNullOrWhiteSpace(model.accountID) && !string.IsNullOrWhiteSpace(model.accountType) && model.accountType == "autodebit") { var param = new PennyTestRequestParam() { accountID = model.accountID, AccountNo = model.AccountNo, accountType = model.accountType , BankCode = model.BankCode };
var s = GetAutoDebitAccountById(param); if (s != null) { model.AccountNo = s.AccountNo; model.BankCode = s.BankCode; } else { rsp.SetResponse("1", "Penny test verification failed"); return rsp; } }
rsp = _repo.VerifyCertificate(model.CustomerId, model.CertNumber, model.BankCode, model.AccountNo); rsp.Data = new { Message = rsp.Msg }; return rsp; }
private PennyTestRequestParam GetAutoDebitAccountById(PennyTestRequestParam param) { try { var id = Crypto.Decrypt(param.accountID, Utilities.ReadWebConfig("ktft_client_info_salt", "")); PennyTestRequestParam res = _repo.GetAutoDebitAccountById(id); return res; } catch (Exception ex) { Log.Error("Error during decrypting autodebit id", ex); return null; } } } }
|