|
|
using Common.Model; using Common.Model.KftcSendMoney; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace Business.KFTCSendMoneyBussiness { public class KftcSendMoney : IKftcSendMoney { public DbResult DebitAccount(KftcSendMoneyRequest model) { DbResult _dbRes = new DbResult(); DbResult _logResp = new DbResult();
string customerId = model.CustomerId; string accessToken = model.AccessToken; string fintechUseNo = model.FintechUseNo; string cAmt = model.CollAmt; string accountName = model.AccountName; string customerBankCode = model.BankCode; string accountNum = model.AccountNum; string accHolderInfoType = model.AccHolderInfoType; string accHolderInfo = model.AccHolderInfo;
if (string.IsNullOrWhiteSpace(customerId) || string.IsNullOrWhiteSpace(accessToken) || string.IsNullOrWhiteSpace(fintechUseNo) || string.IsNullOrWhiteSpace(cAmt) || string.IsNullOrWhiteSpace(accountName) || string.IsNullOrWhiteSpace(customerBankCode) || string.IsNullOrWhiteSpace(accountNum) || string.IsNullOrWhiteSpace(accHolderInfoType) || string.IsNullOrWhiteSpace(accHolderInfo)) { _dbRes.ResponseCode = "999"; _dbRes.Msg = "Oops! Something went wrong please re-login and try again."; return _dbRes; } cAmt = cAmt.Split('.')[0];
_dbRes = CheckBankStatus(customerBankCode, customerId); if (_dbRes.ResponseCode != "A0000") { return _dbRes; }
if (String.IsNullOrEmpty(accHolderInfoType) == true) { _dbRes.ResponseCode = "999"; _dbRes.Msg = "[FAIL] Customer's real name number type is null ";
return _dbRes; }
if (String.IsNullOrEmpty(accHolderInfo) == true) { _dbRes.ResponseCode = "999"; _dbRes.Msg = "[FAIL] Customer's real name number is null ";
return _dbRes; } if (String.IsNullOrEmpty(accountNum) == true) { _dbRes.ResponseCode = "999"; _dbRes.Msg = "[FAIL] Customer's real number is null ";
return _dbRes; }
var accountHolderInfoType = accHolderInfoType; var accountHolderInfo = accHolderInfo.Replace("-", "").Trim();
_dbRes = CheckRealName(customerId, customerBankCode, accountNum, accountHolderInfoType, accountHolderInfo);
/* 계좌실명조회가 실패하면... */ if (_dbRes.ResponseCode != "A0000") { return _dbRes; }
/* * 출금이체 서비스 * * */ var req = new Common.KFTC.Request.withdraw();
req.dps_print_content = accountName; //입금계좌내역
req.fintech_use_num = fintechUseNo; //산업은행-1234567890
req.tran_amt = cAmt; //거래금액
req.tran_dtime = DateTime.Now.ToString("yyyyMMddHHmmss"); //요청일시
string tranDtime = req.tran_dtime;
//string tranDtime_1 = DateTime.Now.AddSeconds(-1).ToString("yyyyMMddHHmmss");
string _URL = _utility.ReadWebConfig("TRANSFER_WITHDRAW", ""); //@"transfer/withdraw";
var access_token = accessToken;
//log request
_logResp = _utility.LogRequestKFTC(customerId, "DebitAccount", "access_token :" + access_token + "req :" + JsonConvert.SerializeObject(req));
KFTCPostGet kftcRequest = new KFTCPostGet();
try { string postData = JsonConvert.SerializeObject(req);
/* * 출금이체 요청 * */ var resp = kftcRequest.PostToKFTC(_URL, access_token, postData);
/* * 출금이체 요청 실패!!! * */ if (string.IsNullOrEmpty(resp)) { _dbRes.ResponseCode = "999"; _dbRes.Msg = "FAILED TO KFTC OPEN-FLATFORM (TRANSFER/WITHDRAW)!";
//log response
_utility.LogResponseKFTC(_logResp.Id, resp, _dbRes.ResponseCode, _dbRes.Msg);
return _dbRes; }
var respObj = JsonConvert.DeserializeObject<Response.withdraw>(resp);
//log response
_utility.LogResponseKFTC(_logResp.Id, resp, respObj.rsp_code, (respObj.rsp_code == "A0000") ? "Success!" : respObj.rsp_message);
if (respObj.rsp_code == "A0001") { Thread.Sleep(1 * 60 * 1000);
/* 이체결과확인 * */ respObj = transfer_result(ref respObj, customerId, "1"); if (respObj.rsp_code == "A0001") { Thread.Sleep(2 * 60 * 1000);
/* 이체결과확인 * */ respObj = transfer_result(ref respObj, customerId, "2"); if (respObj.rsp_code == "A0001") { _dbRes.ResponseCode = respObj.rsp_code; _dbRes.Msg = respObj.rsp_message; _dbRes.Id = respObj.api_tran_id; _dbRes.Extra = respObj.api_tran_dtm;
return _dbRes; } } }
DbResult _saveKFTCData = new DbResult(); if (respObj.rsp_code == "A0000") { /* * 송금인 정보조회 삭제 * * @Max-2018.09.07 * */ //string fromTime = respObj.api_tran_dtm.Substring(0, 14);
//max-20180615
//_dbRes = CheckRemittant(fromTime, customerId, accountNum, accountName, processId);
//respObj.remittance_check = (_dbRes.ResponseCode == "A0000") ? "Y" : "N";
respObj.remittance_check = "Y"; _saveKFTCData = SaveKFTCTranData(respObj, customerId);
//if (_dbRes.ResponseCode != "A0000")
//{
// return _dbRes;
//}
}
_dbRes.ResponseCode = respObj.rsp_code; _dbRes.Msg = respObj.rsp_message; _dbRes.Id = _saveKFTCData.Id;
return _dbRes; } catch (Exception ex) { //log response
_utility.LogResponseKFTC(_logResp.Id, "Exception occured!", "999", ex.Message);
_dbRes.SetError("999", ex.Message, null); return _dbRes; }
} private DbResult CheckBankStatus(string customerBankCode, string customerId) { DbResult dbRes = new DbResult(); DbResult logRes = new DbResult(); KFTCPostGet kftcRequest = new KFTCPostGet();
//string _URL = @"bank/status";
string httpUrl = _utility.ReadWebConfig("BANK_STATUS", ""); string access_token = _utility.ReadSession("oob_access_token", ""); string gmeBankCode = _utility.ReadSession("gmeBankCode", ""); string processId = _utility.ReadSession(_utility.GetSessionKey(customerId), "");
//log request
logRes = _utility.LogRequestKFTC(customerId, "CheckBankStatus", "_URL :" + httpUrl + " access_token :" + access_token, processId);
try { /* * 참가은행 상태조회!!! * */ var resBankStatusStr = kftcRequest.GetFromKFTC(httpUrl, access_token);
/* * 참가은행 상태조회 실패!!! * */ if (string.IsNullOrEmpty(resBankStatusStr)) { dbRes.ErrorCode = "999"; dbRes.Msg = "[FAIL] KFTC OPEN-FLATFORM (BANK/STATUS)!";
//log response
_utility.LogResponseKFTC(logRes.Id, null, dbRes.ErrorCode, dbRes.Msg);
return dbRes; }
var resBankStatusObj = JsonConvert.DeserializeObject<Response.bank_status>(resBankStatusStr);
//log response
//_utility.LogResponseKFTC(_logResp.Id, resp, bankList.rsp_code, bankList.rsp_message);
//정상응답이 아닌경우...
if (resBankStatusObj.rsp_code != "A0000") { dbRes.SetError("999", resBankStatusObj.rsp_message, null);
//log response
_utility.LogResponseKFTC(logRes.Id, null, resBankStatusObj.rsp_code, dbRes.Msg);
return dbRes; }
List<Response.bank_unit> bankUnit = resBankStatusObj.res_list;
//dbRes.Extra = logRes.Extra;
//dbRes.Id = "";
//고객은행과 GME은행이 정상이면 "YY"
string bankStatus = "N"; foreach (var item in bankUnit) { //customer bank
if (item.bank_code_std == customerBankCode) { bankStatus = item.bank_status; } }
if (bankStatus != "Y") { dbRes.ErrorCode = "999"; dbRes.Msg = String.Format("[FAIL] This bank{0} service is not available right now, please try again later !!", customerBankCode);
//log response
_utility.LogResponseKFTC(logRes.Id, null, dbRes.ErrorCode, dbRes.Msg);
return dbRes; }
bankStatus = "N"; foreach (var item in bankUnit) { //GME bank
if (item.bank_code_std == gmeBankCode) { bankStatus = item.bank_status; } }
if (bankStatus != "Y") { dbRes.ErrorCode = "999"; dbRes.Msg = String.Format("[FAIL] This bank {0} service is not available right now, please try again later !!", gmeBankCode);
//log response
_utility.LogResponseKFTC(logRes.Id, null, dbRes.ErrorCode, dbRes.Msg);
return dbRes; }
//성공
dbRes.SetError("A0000", "", null); return dbRes; } catch (Exception ex) { dbRes.SetError("999", ex.Message, null);
//log response
_utility.LogResponseKFTC(logRes.Id, "Exception occured", "999", ex.Message);
return dbRes; } }
public DbResult CheckRealName(string customerId, string custBankCode, string custAccountNum, string accountHolderInfoType, string accountHolderInfo) { DbResult _dbRes = new DbResult(); DbResult _logResp = new DbResult(); KFTCPostGet kftcRequest = new KFTCPostGet();
string httpUrl = _utility.ReadWebConfig("INQUIRY_REALNAME", ""); //@"inquiry/real_name";
string oob_access_token = _utility.ReadSession("oob_access_token", ""); string processId = _utility.ReadSession(_utility.GetSessionKey(customerId), "");
//주민등록번호 Resident registration number
if (accountHolderInfoType == "8008") { accountHolderInfoType = "1"; } //외국인등록번호 Foreigner registration number
else if (accountHolderInfoType == "1302") { accountHolderInfoType = "2"; } //여권번호이면 조합주민번호로 조회 Passport with Combination no
else if (accountHolderInfoType == "10997") { accountHolderInfoType = "5"; } //사업자등록번호 Company Registration Number
else if (accountHolderInfoType == "10988") { accountHolderInfoType = "6"; }
var reqRealNameObj = new Common.KFTC.Request.real_name();
reqRealNameObj.bank_code_std = custBankCode; reqRealNameObj.account_num = custAccountNum; reqRealNameObj.account_holder_info_type = accountHolderInfoType; reqRealNameObj.account_holder_info = accountHolderInfo; reqRealNameObj.tran_dtime = DateTime.Now.ToString("yyyyMMddHHmmss");
try { string reqRealNameStr = JsonConvert.SerializeObject(reqRealNameObj);
//로그-요청로그
_logResp = _utility.LogRequestKFTC(customerId, httpUrl, reqRealNameStr, processId);
var resRealNameStr = kftcRequest.PostToKFTC(httpUrl, oob_access_token, reqRealNameStr);
/* * 계좌실명조회 실패!!! * */ if (string.IsNullOrEmpty(resRealNameStr)) { _dbRes.ErrorCode = "999"; _dbRes.Msg = "[FAIL] KFTC OPEN-FLATFORM (inquiry/real_name)";
//로그-결과로그(실패)
_utility.LogResponseKFTC(_logResp.Id, null, _dbRes.ErrorCode, _dbRes.Msg);
return _dbRes; }
var resRealNameObj = JsonConvert.DeserializeObject<Response.real_name>(resRealNameStr);
//응답메시지가 성공일때...
if (resRealNameObj.rsp_code == "A0000" && resRealNameObj.bank_rsp_code == "000") { _dbRes.ErrorCode = "A0000"; _dbRes.Msg = "[SUCCESS] KFTC OPEN-FLATFORM INQUIRY"; } //응답메시지가 성공이 아닐때..
else if (resRealNameObj.rsp_code != "A0000") { _dbRes.ErrorCode = resRealNameObj.rsp_code; _dbRes.Msg = String.Format("[FAIL] KFTC OPEN-FLATFORM INQUIRY rsp_message:{0}", resRealNameObj.rsp_message);
//_dbRes.Msg = String.Format("[FAIL] inquiry/real_name : rsp_message={0}, req_type={1}, req_num={2}, res_type={3}, res_num={4}",
// resRealNameObj.rsp_message,
// accountHolderInfoType,
// accountHolderInfo,
// resRealNameObj.account_holder_info_type,
// resRealNameObj.account_holder_info);
} else if (resRealNameObj.bank_rsp_code != "000") { _dbRes.ErrorCode = resRealNameObj.bank_rsp_code; _dbRes.Msg = String.Format("[FAIL] KFTC OPEN-FLATFORM INQUIRY bank_rsp_message:{0}", resRealNameObj.bank_rsp_message);
//_dbRes.Msg = String.Format("[FAIL] inquiry/real_name : rsp_message={0}, req_type={1}, req_num={2}, res_type={3}, res_num={4}",
// resRealNameObj.bank_rsp_message,
// accountHolderInfoType,
// accountHolderInfo,
// resRealNameObj.account_holder_info_type,
// resRealNameObj.account_holder_info);
} else { _dbRes.ErrorCode = resRealNameObj.rsp_code; _dbRes.Msg = "[FAIL] KFTC OPEN-FLATFORM INQUIRY"; }
// 로그-응답로그
_utility.LogResponseKFTC(_logResp.Id, resRealNameStr, _dbRes.ErrorCode, _dbRes.Msg);
_dbRes.SetError(_dbRes.ErrorCode, _dbRes.Msg, null); return _dbRes; } catch (Exception ex) { //로그-응답로그
_utility.LogResponseKFTC(_logResp.Id, "Exception occured!", "999", ex.Message);
_dbRes.SetError("999", ex.Message, null); return _dbRes; }
}
} }
|