using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using Cosmos.BaseFrame; using Cosmos.UserFrame; using Cosmos.ServiceProvider; using Cosmos.Common; using Cosmos.CommonManager; using System.Threading; using SPC.Kiosk.Common; namespace SPC.Kiosk.Payments { public class posOkCashBag : IDisposable { #region [ Members ] /// /// OkCashBagCertify Error Code /// public enum ErrorCode { OkCashBagCertifyMobilePhoneNumberError, OkCashBagCertifyMobileCardNumberError, OkCashBagCertifyMemInfoEncryptedCardNoError, OkCashBagCertifyEncrtipError, OkCashBagCertifyNotInitailzedError, OkCashBagCertifyProcessingTimeOut, OkCashBagUnknownError } /// /// ErrorMessage Event /// /// 반환 로그 public delegate void ErrorMessageEventHandler(string ErrorString); /// /// 로그메세지 이벤트 반환용 /// public event ErrorMessageEventHandler ErrorMessageEvent; /// /// Error 반환 Event /// /// 반환 Error Code public delegate void LogErrorHandler(ErrorCode errorCode); /// /// Error Code 이벤트 반환용 /// public event LogErrorHandler ErrorEvent; /// /// IcReadStart Event /// /// public delegate void IcReadStart(object sender); /// /// IcReadStart Event 반환용 /// public event IcReadStart ReadStart; /// /// IcReadStart Event /// /// public delegate void IcReadEnd(object sender); /// /// IcReadStart Event 반환용 /// public event IcReadEnd ReadEnd; private SManager sManager = null; // 이 객체를 통해 업무 Service 호출 private StateServer StateObject = null; // StateObject : StateServer Object (객체) private PosStatus m_cPosStatus = null; // 기본정보 참조 private TranStatus m_cTrnStatus = null; // 거래정보 참조 private DeviceStatus m_cDevStatus = null; // 디바이스 관리 private PosOLEDevice.DelegateIcReader delegateReader; // IC리더 콜백 private IICReaderUs m_cDeviceICReader = null; private IPaymentExpUs m_cPntOcbSave = null; /// /// 입력구분 /// private string m_sInPutType = ""; /// /// 입력데이터 /// private string m_sInPutData = ""; /// /// 마스킹데이터 /// private string m_sInMaskData = ""; /// /// 카드데이터(암호화) /// private string m_sInEncData = ""; /// /// 서비스코드 /// private string m_sServiceCode = ""; /// /// 조회 성공 여부 /// private bool m_bSearchSuccess = false; /// /// POS 초기화 필요 유무 /// public bool NeedInitModule { get; set; } /// /// 승인 수단 /// public string CertifyKey { get; set; } = string.Empty; private bool icCallBack = false; /// /// Ic Reader CallBack Switch /// public bool IcCallBack { get { return icCallBack; } set { if (value) { m_cDeviceICReader.RegIcCallback(delegateReader); } icCallBack = value; } } /// /// 마스크된 회원성명 /// public string MemberName { get; protected set; } = string.Empty; /// /// 적립 가능 유무 /// public bool CanReservePoint { get; protected set; } /// /// 회원 가용 Point /// public double MemberPoint { get; protected set; } = 0d; /// /// Point 사용시 비번 필요 유무 /// public bool NeedPassword { get; protected set; } public string ApprovalNo { get; protected set; } = string.Empty; public string ApprovalDate { get; protected set; } = string.Empty; /// /// 인증 처리 성공 유무 /// public bool ProcessOK { get { return m_bSearchSuccess; } } /// /// Processing Timeout /// public bool IsTimeout { set { if (value) { ErrorEvent(ErrorCode.OkCashBagCertifyProcessingTimeOut); } } } #endregion #region [ Ctor && Dispose ] /// /// Ctor /// public posOkCashBag() { try { sManager = new SManager(); StateObject = (StateServer)StateServer.GetInstance(); NeedInitModule = StateObject.POS == null || StateObject.TRAN == null || StateObject.DEVICE == null; if (!NeedInitModule) { m_cPosStatus = (PosStatus)StateObject.POS; // POS 기본정보 m_cTrnStatus = (TranStatus)StateObject.TRAN; // POS 거래정보 m_cDevStatus = (DeviceStatus)StateObject.DEVICE; m_cDeviceICReader = (IICReaderUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_ICREADER); m_cPntOcbSave = (IPaymentExpUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.PNT_OCB_SAVE); delegateReader = new PosOLEDevice.DelegateIcReader(OnIcReaderCallBack); // IC리더 콜백 } } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "Ctor", "Fail", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } } /// /// /// public void Dispose() { try { InDataToZeroFill(); sManager = null; StateObject = null; m_cPosStatus = null; // POS 기본정보 m_cTrnStatus = null; // POS 거래정보 m_cDevStatus = null; m_cDeviceICReader = null; m_cPntOcbSave = null; delegateReader = null; // IC리더 콜백 } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "Dispose", "Fail", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } } #endregion #region [ Methods ] /// /// HappyPoint 회원 조회 (16 자리이면 Mobile BarCode, 그외는 전화 번호) /// /// public void StartCertifyProcessing(string _inputString) { try { CommonLog.InfoLogWrite(this, "StartCertifyProcessing()", "Start"); SendReadStart(); if (NeedInitModule) { Thread.Sleep(1000); //진행창 보이기 위한 딜레이 ErrorEvent(ErrorCode.OkCashBagCertifyNotInitailzedError); } else { var startPorcess = false; if (_inputString.Length.Equals(16)) { // Mobile BarCode m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN; m_sInMaskData = _inputString; m_sInPutData = _inputString + "="; startPorcess = true; } else { // 전화 번호 if (IsCellularPhoneNumber(_inputString)) { m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN; m_sInMaskData = m_sInPutData = _inputString; startPorcess = true; } else { SendErrLogEvent(ErrorCode.OkCashBagCertifyMobilePhoneNumberError); } } //조회 전문 처리 if (startPorcess) { if (EncryptedCardNo(m_sInPutData, ref m_sInMaskData, ref m_sInEncData)) { SearchTxtInPut(); } else { SendErrLogEvent(ErrorCode.OkCashBagCertifyEncrtipError); } } } SendReadEnd(); CommonLog.InfoLogWrite(this, "StartCertifyProcessing()", string.Format("End : Result={0}", ProcessOK ? "OK" : "Fail")); } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "StartCertifyProcessing()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } } /// /// 휴대폰 번호 형식 확인 /// /// /// private bool IsCellularPhoneNumber(string sInputData) { bool bRet = false; try { if (sInputData.Length == 10 || sInputData.Length == 11) { if (sInputData.StartsWith("010") == true || sInputData.StartsWith("011") == true || sInputData.StartsWith("017") == true || sInputData.StartsWith("016") == true || sInputData.StartsWith("018") == true || sInputData.StartsWith("019") == true) { bRet = true; } } } catch { bRet = false; } return bRet; } /// /// OK CashBag 조회 전문 처리 /// private void SearchTxtInPut() { CommonLog.DebugLogWrite(this, "SearchTxtInPut()", "Start"); string sRet = UserCom.RST_ERR; try { m_bSearchSuccess = false; // 조회 string[] saRecvdData = null; sRet = m_cPntOcbSave.SearchPayment(new string[] { m_sInPutType, m_sInMaskData, m_sInEncData, "0"}, ref saRecvdData); if (sRet != UserCom.RST_OK) { CertifyKey = string.Empty; InDataToZeroFill(); if (sRet == null || sRet.Equals(UserCom.RST_ERR)) { SendErrLogEvent(ErrorCode.OkCashBagUnknownError); } else { SendErrorMessageEvent(sRet); } } else { CertifyKey = m_sInPutData; var cEtcItem = (Column.TR_ETC.DATA)m_cPntOcbSave.GetPayment(new string[] { }); NeedPassword = true; MemberPoint = cEtcItem.AMT_ENTRY_04; m_bSearchSuccess = true; } } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "SearchTxtInPut()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } CommonLog.DebugLogWrite(this, "SearchTxtInPut()", "End"); } /// /// 카드 번호 암호화 /// /// /// /// /// private bool EncryptedCardNo(string sInData, ref string sInMaskData, ref string sInEncData) { string sEncData = sInData; bool bRet = false; try { //#20170913 현금영수증, 포인트카드 마스킹 미적용 start // "0"인 경우 마스킹 미처리 //기존 //sEncData = m_cDeviceICReader.GetEncryptedCardNo(sInData).Trim(); //변경 sEncData = m_cDeviceICReader.GetEncryptedCardNo(sInData, "0").Trim(); //#20170913 현금영수증, 포인트카드 마스킹 미적용 end if (CmUtil.MidH(sEncData, 0, 2) == "00") { sInEncData = CmUtil.MidH(sEncData, 2, 512).Trim(); // 암호화 데이터 sInMaskData = CmUtil.MidH(sEncData, 514, sEncData.Length - 514).Trim(); // 마스킹 데이터 //#20170913 현금영수증, 포인트카드 마스킹 미적용 start sInMaskData = CmUtil.MidH(sInMaskData, 0, 6) + "********"; //#20170913 현금영수증, 포인트카드 마스킹 미적용 end bRet = true; } else { CommonLog.ErrorLogWrite(this, "EncryptedCardNo()", "Fail !!"); } } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "EncryptedCardNo()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } return bRet; } #region DeviceEvent 관련 /// /// IC 카드 정보 입력 처리 /// /// private bool GetIcCardData() { string sRsvStr = ""; try { //IcCallBack = false; // IC리더 콜백 해지 ClearCardInfo(); // 카드 입력 정보 클리어 if (m_cDeviceICReader.GetCardInfo_ICReader(PosConst.IC_READER_TRAN_TYPE.POINT, 0, ref sRsvStr) == true) { if (CmUtil.MidH(sRsvStr, 0, 2) == "00") { m_sInEncData = CmUtil.MidH(sRsvStr, 6, 512).Trim(); m_sInMaskData = CmUtil.MidH(sRsvStr, 1030, 37).Trim(); m_sServiceCode = CmUtil.MidH(sRsvStr, 1067, 5).Trim(); m_sInPutData = m_sInMaskData; m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP; return true; } } } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "GetIcCardData()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } finally { // 여전법 대응//////////////////////////////////////////////////////////////////// CmUtil.ZeroFillClear(ref sRsvStr); ////////////////////////////////////////////////////////////////////////////////// } return false; } /// /// RF 카드 정보 입력 처리 /// /// private bool GetRfCardData() { string sRsvStr = ""; try { //IcCallBack = false; // IC리더 콜백 해지 ClearCardInfo(); // 카드 입력 정보 클리어 //카드 정보 입력 if (m_cDeviceICReader.GetRfCreditCardInfo("1", m_cTrnStatus.Head.NetSaleAmt.ToString(), "", "", "", ref sRsvStr) == false) { if (sRsvStr != "") SendErrorMessageEvent(sRsvStr); return false; } m_sInEncData = CmUtil.MidH(sRsvStr, 2, 512).Trim(); m_sInMaskData = CmUtil.MidH(sRsvStr, 514, 40).Trim(); m_sServiceCode = CmUtil.MidH(sRsvStr, 554, 5).Trim(); m_sInPutData = m_sInMaskData; m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF; //ReadBarCode= m_sInPutData.Length > 16 ? CmUtil.MidH(m_sInPutData, 0, 16) : m_sInPutData; //return true; } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "GetRfCardData()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } finally { // 여전법 대응//////////////////////////////////////////////////////////////////// CmUtil.ZeroFillClear(ref sRsvStr); ////////////////////////////////////////////////////////////////////////////////// } return false; } /// /// POP 카드 정보 입력 처리 /// /// private bool GetPopCardData() { string sRsvStr = ""; try { //IcCallBack = false; // IC리더 콜백 해지 ClearCardInfo(); // 카드 입력 정보 클리어 if (m_cDeviceICReader.RfPrepaidCardInfo(ref sRsvStr) == false) { if (sRsvStr != "") SendErrorMessageEvent(sRsvStr); return false; } if (sRsvStr.StartsWith("T") == true) { m_sInPutData = sRsvStr.Substring(7, 16).Trim(); } else if (sRsvStr.StartsWith("E") == true) { m_sInPutData = sRsvStr.Substring(1, 20).Trim(); } else { return false; } bool bRet = EncryptedCardNo(m_sInPutData, ref m_sInMaskData, ref m_sInEncData); if (bRet == true) { m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF; } return bRet; } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "GetPopCardData()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } finally { // 여전법 대응//////////////////////////////////////////////////////////////////// CmUtil.ZeroFillClear(ref sRsvStr); ////////////////////////////////////////////////////////////////////////////////// } return false; } #endregion #region 여전법 대응 /// /// ZeroFill 초기화 /// private void InDataToZeroFill() { try { //여전법 대응! ////////////////////////////////////////////////////////////////////////////////// CmUtil.ZeroFillClear(ref m_sInPutData); CmUtil.ZeroFillClear(ref m_sInEncData); CmUtil.ZeroFillClear(ref m_sInMaskData); ////////////////////////////////////////////////////////////////////////////////// } catch { } } #endregion 여전법 대응 #region IC리더 콜백 //delegate void DelegateIcReaderCallBack(int rc, StringBuilder str); /// /// IC리더 콜백 함수 /// /// /// public void OnIcReaderCallBack(int num, StringBuilder str) { try { SendReadStart(); if (num == 1) { GetIcCardData(); } else { if (str.ToString().StartsWith("EN")) { ClearCardInfo(); // 카드 입력 정보 클리어 m_sInEncData = CmUtil.MidH(str.ToString(), 0, 512).Trim(); m_sInMaskData = CmUtil.MidH(str.ToString(), 512, 40).Trim(); m_sInPutData = m_sInMaskData; m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP; } } if (!string.IsNullOrEmpty(m_sInPutData)) SearchTxtInPut(); SendReadEnd(); } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "OnIcReaderCallBack()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } } #endregion private void SendErrorMessageEvent(string _errorMessageString) { try { CommonLog.ErrorLogWrite(this, "SendErrorMessageEvent()", _errorMessageString); ErrorMessageEvent(_errorMessageString); } catch { } } private void SendErrLogEvent(ErrorCode _errorCode) { try { CommonLog.DebugLogWrite(this, "SendErrLogEvent()", _errorCode.ToString()); ErrorEvent(_errorCode); } catch { } } private void SendReadStart() { try { CommonLog.DebugLogWrite(this, "SendReadStart()"); ReadStart(this); } catch { } } private void SendReadEnd() { try { CommonLog.DebugLogWrite(this, "SendReadEnd()"); ReadEnd(this); } catch { } } private void ClearCardInfo() { try { m_sInPutType = ""; // 입력구분 m_sInPutData = ""; // 입력데이터 m_sInMaskData = ""; // 마스킹 m_sInEncData = ""; // 카드데이터인카드번호 m_bSearchSuccess = false; } catch { } } #endregion } }