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 System.Collections; using SPC.Kiosk.Common; namespace SPC.Kiosk.Payments { /// /// POS HappyPoint Approval Process /// public class posPaymentsCancel : IDisposable { #region [ Members ] /// /// HappyPointCertify ErrorCode /// public enum ErrorCode { posPaymentsCancelNotInitailzedError, posPaymentsCancelProcessingTimeOut, posPaymentsCancelPaymentSEQError, posPaymentsCancelCanceledItemError, posPaymentsCancelNotFoundError, posPaymentsCancelUnknownError, } /// /// 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 IPaymentUs m_cPayCancel = null; /// /// 성공 여부 /// private bool m_bSearchSuccess = false; /// /// POS 초기화 필요 유무 /// public bool NeedInitModule { get; set; } /// /// 승인 수단 /// public string CertifyKey { get; set; } = string.Empty; public long PaySEQ { get; protected set; } /// /// 인증 처리 성공 유무 /// public bool ProcessOK { get { return m_bSearchSuccess; } } /// /// Processing TimeOut /// public bool IsTimeout { set { if (value) { ErrorEvent(ErrorCode.posPaymentsCancelProcessingTimeOut); } } } #endregion #region [ Ctor && Dispose ] /// /// Ctor /// public posPaymentsCancel() { 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; } } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "Ctor", "Fail", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } } /// /// /// public void Dispose() { try { sManager = null; StateObject = null; m_cPosStatus = null; // POS 기본정보 m_cTrnStatus = null; // POS 거래정보 m_cDevStatus = null; m_cPayCancel = null; } 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 StartProcessing(long _paySeq) { try { CommonLog.InfoLogWrite(this, "StartProcessing()", string.Format("Start [{0}]", _paySeq)); SendReadStart(); if (NeedInitModule) { Thread.Sleep(1000); //진행창 보이기 위한 딜레이 ErrorEvent(ErrorCode.posPaymentsCancelNotInitailzedError); } else { var startPorcess = false; var payRowNo = -1; if (_paySeq > 0) { m_cTrnStatus.Head.TradeDiv = ItemConst.TRAN_DIV.NORMAL; ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM); foreach (var aPayItme in alPayItem) { if (aPayItme is Column.TR_PAYMENT.DATA findPayItem && findPayItem.SEQ.Equals(_paySeq)) { payRowNo = alPayItem.IndexOf(aPayItme); if (!findPayItem.CANCEL_DIV.Equals(ItemConst.PAY_CANCEL_DIV.CANCEL)) { startPorcess = true; } else { SendErrLogEvent(ErrorCode.posPaymentsCancelCanceledItemError); } break; } } if (!startPorcess && payRowNo < 0) { SendErrLogEvent(ErrorCode.posPaymentsCancelNotFoundError); } else { //승인 취소 처리 CompleteTxtInPut(payRowNo); if (m_bSearchSuccess) { alPayItem.RemoveAt(payRowNo); } } } else { SendErrLogEvent(ErrorCode.posPaymentsCancelPaymentSEQError); } } SendReadEnd(); CommonLog.InfoLogWrite(this, "StartProcessing()", string.Format("End : Result={0}", ProcessOK ? "OK" : "Fail")); } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "StartProcessing()", "Fail", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } } /// /// 승인 취소 처리 /// /// private void CompleteTxtInPut(int _rowNo) { CommonLog.DebugLogWrite(this, "CompleteTxtInPut()", "Start"); string sRet = UserCom.RST_ERR; try { m_bSearchSuccess = false; m_cPayCancel = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.PAYMENTCANCEL); var alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM); var cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[_rowNo]; // 포인트 사용 승인 처리 sRet = m_cPayCancel.CancelPayment(new string[] { cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, _rowNo.ToString() }); if (sRet != UserCom.RST_OK) { if (sRet == null || sRet.Equals(UserCom.RST_ERR)) { SendErrLogEvent(ErrorCode.posPaymentsCancelUnknownError); } else { SendErrorMessageEvent(sRet); } } else { m_bSearchSuccess = true; } } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "CompleteTxtInPut()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } CommonLog.DebugLogWrite(this, "CompleteTxtInPut()", "End"); } 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 { } } #endregion } }