using System;
using System.Collections;
using System.Windows.Forms;

using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using System.Text;

namespace Cosmos.Service
{
    class PaymentCancel : IPaymentUs
    {
        protected SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        protected StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        protected PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        protected TranStatus m_cTrnStatus = new TranStatus();                         // 거래정보 참조
        protected DeviceStatus m_cDevStatus = new DeviceStatus();                     // 디바이스 관리

        protected IDataProcessUs m_cDataService = null;                               // 거래데이터 합계금액 계산 및 관리
        protected IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스

        public PaymentCancel()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    // POS 거래정보    
            m_cDevStatus = (DeviceStatus)StateObject.DEVICE;

            m_cDataService = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);
            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
        }

        public string SearchPayment(string[] aParam, ref string[] aRet)
        {
            throw new NotImplementedException();
        }
        public object GetPayment(string[] aParam)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 카드번호 재입력 처리
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string SetPayment(string[] aParam)
        {

            string sReturnData = string.Empty;

            try
            {
                // 카드번호 입력 화면
                frmInputCardCom fForm = (frmInputCardCom)FormManager.GetForm(FormManager.FORM_INPUT_CARD);
                if (fForm == null)
                {
                    fForm = new frmInputCardCom();
                    FormManager.AddForm(FormManager.FORM_INPUT_CARD, fForm);
                }
                fForm.PAY_WAY_CD = aParam[0];
                fForm.SetCardNo = aParam[1];
                fForm.SetAppAmt = aParam[2];
                fForm.SetCardNm = aParam[3];
                fForm.SetInPutType = aParam[4];
                fForm.PAY_DTL_CD = aParam[5];
                fForm.PassWordYn = aParam[6];

                if (fForm.ShowDialog() == DialogResult.OK)
                {
                    sReturnData = CmUtil.RPadH(fForm.PassWordOut, 20);      
                    sReturnData += fForm.CardInfoOut;
                    
                    if (!(string.IsNullOrEmpty(fForm.CardInfoOut)))
                    {
                        int nLen = fForm.CardInfoOut.Length;

                        string sFill = "";
                        sFill = new string('A', nLen); fForm.CardInfoOut = sFill;
                        sFill = new string('0', nLen); fForm.CardInfoOut = sFill;
                        sFill = new string('X', nLen); fForm.CardInfoOut = sFill;   
                    }
                    fForm.CardInfoOut = string.Empty;

                    return sReturnData;         //비밀번호(20) + 카드정보
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref aParam);
                CmUtil.ZeroFillClear(ref sReturnData);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return "";
        }

        /// <summary>
        /// 결제수단 취소 처리
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string CancelPayment(string[] aParam)
        {
            return ExecutePayCancel(false, aParam[0], aParam[1], aParam[2]);
        }

        /// <summary>
        /// 결제수단 반품 처리
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string RefundPayment(string[] aParam)
        {
            return ExecutePayCancel(true, aParam[0], aParam[1], aParam[2]);
        }

        public string SetMenualPayment(string[] aParam)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 결제 취소(직전취소 및 반품 처리)
        /// </summary>
        /// <param name="bRefund">true:반품, flase:취소</param>
        /// <param name="sPAY_WAY_CD"></param>
        /// <param name="sPAY_DTL_CD"></param>
        /// <param name="sSeqNo"></param>
        /// <returns></returns>
        private string ExecutePayCancel(bool bRefund, string sPAY_WAY_CD, string sPAY_DTL_CD, string sSeqNo)
        {
            //#20171020 log 추가 
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                 "TradeDiv : " + m_cTrnStatus.Head.TradeDiv + ", 반품구분: " + bRefund.ToString() + ", 결제코드: " + sPAY_WAY_CD + ", 상세코드: " + sPAY_DTL_CD + ", SeqNo: " + sSeqNo);
            
            string sRet = UserCom.RST_ERR;
            IPaymentUs cPayItem = null;
            try
            {
                switch (sPAY_WAY_CD)
                {
                    case ItemConst.TR_ITEM_ID.CREDITCARD_ITEM:
                        if (m_cDevStatus.ICReader.UseYn == true)             // 여전법 인증여부(0:MSR, 1:IC)
                        {
                            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                "ExecutePayCancel IC");
                            // IC
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.CREDITCARD);
                        }
                        else
                        {
                            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                "ExecutePayCancel MSR");
                            // MSR
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.MSRCARD);
                        }
                        break;

                    case ItemConst.TR_ITEM_ID.MOBILE_COM_POINT: 
                        // 제휴 통신사 할인 취소
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT || sPAY_DTL_CD == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_LGT
                            || sPAY_DTL_CD == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KTF || sPAY_DTL_CD == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_VIP || sPAY_DTL_CD == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_DOUBLE)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTMOBILECOM);
                        }
                        //#20180413 웰컴카드 신규기능 추가 start,phj
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.WELCOMECARD_ISSUE);
                        }
                        //#20180413 웰컴카드 신규기능 추가 end,phj
                        else
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTMEMBERUSE);
                        }
                        break;

                    case ItemConst.TR_ITEM_ID.CASH_ITEM:
                    case ItemConst.TR_ITEM_ID.CHECK_ITEM:
                        // 현금
                        cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.CASH);
                        break;

                    case ItemConst.TR_ITEM_ID.COUPON_ITEM:      
                        // 쿠폰
                        if( sPAY_DTL_CD == ItemConst.TR_ITEM_ID.COUPON.INCARD)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYCOUPON);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.COUPON.ONLINE)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.ONLINE_COUPON);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.COUPON.CAKE_CHANGE)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.CAKECHANGE);
                        }
                        else
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.COUPONDC);
                        }
                        break;  
     
                    case ItemConst.TR_ITEM_ID.MOBILECON_ITEM:
                        // 모바일 쿠폰
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.MOBILECON.HPCON || sPAY_DTL_CD == ItemConst.TR_ITEM_ID.MOBILECON.E_BAYCON)
                        {
                            // 해피콘
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.MOBILECOUPON_HAPPYCON);
                        }
                        else
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.MOBILECOUPON);
                        }
                        break;

                    case ItemConst.TR_ITEM_ID.EMP_DC_ITEM:
                        // 직원 할인
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.EMP_DC.SEVERANCE)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SEVERANCEDC);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.EMP_DC.SPC)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SPCEMPLOYEEDC);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.EMP_DC.SPC_PAY)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SPCEMPLOYEEDC);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.EMP_DC.SPC_CHINA)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SPCEMPLOYEEDC_CHINA);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.EMP_DC.SAMSUNGCARD)
                        {

                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SAMSUNG_FAMILY_CARD);

                            //if ( bRefund == true)
                            //    return UserCom.RST_OK;
                            //else 
                            //    WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0341);
                        }
                        break;

                    case ItemConst.TR_ITEM_ID.POINT_ITEM:
                        // 포인트 사용
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYPOINTUSE);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT_USE_CHINA)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYPOINT_USE_CHINA);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.POINT_USE.OKCASHBACK_POINT)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTMEMBERUSE);
                        }
                        //grayber@20180208 코레일 마일리지 입력 start - 결제취소 및 반품 처리 분기 추가
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.POINT_USE.KORAIL_MILEAGE)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.KORAIL_MAILEAGE);
                        }
                        //grayber@20180208 코레일 마일리지 입력 end
                        break;

                    case ItemConst.TR_ITEM_ID.USER_DC_ITEM:
                        // 임의 할인
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.USER_DC.IN_EMP_DC || sPAY_DTL_CD == ItemConst.TR_ITEM_ID.USER_DC.IN_EMP_DC_5
                            || sPAY_DTL_CD == ItemConst.TR_ITEM_ID.USER_DC.TOTAL_DC_AMT 
                            || sPAY_DTL_CD == ItemConst.TR_ITEM_ID.USER_DC.TOTAL_DC_RATE
                            || sPAY_DTL_CD == ItemConst.TR_ITEM_ID.USER_DC.TOTAL_ADDDC_AMT)
                        //|| sPAY_DTL_CD == ItemConst.TR_ITEM_ID.USER_DC.CAKE_CHANGE
                        {
                            // 입점건물직원할인 취소, 전체금액할인, 전체%할인
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.iNStorDC);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.USER_DC.KAIST_DC)
                        {
                            // 카이스트 할인(2017.05.15)
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.PAYDCMST_TO_DC);
                        }
                        break;

                    case ItemConst.TR_ITEM_ID.PAYETC_ITEM:
                        // 기타결제
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAYETC.MEAL_TIKET)
                        {
                            // 식권취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.MEALTICKET);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAYETC.BALANCE_VOUCHER)
                        {
                            // 잔액교환권 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.EXCHANGETICKET);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAYETC.PAYETC_ITEM)
                        {
                            // 기타결제 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.iNStorDC);
                        }
                        //#20180202 인천공항 VIP 라운지 기능미사용으로 주석처리 start,phj
                        /*
                        // grayber@20180115 인천공항 VIP 라운지 start - 결제 취소 추가
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAYETC.VIP_LOUNGE)
                        {
                            // 인천공항 VIP 라운지 결제 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.VIP_LOUNGE);
                        }
                        // grayber@20180115 인천공항 VIP 라운지 end
                        */
                        //#20180202 인천공항 VIP 라운지 기능미사용으로 주석처리 end,phj

                        break;
                            
                    case ItemConst.TR_ITEM_ID.GIFT_ITEM:
                        // 상품권 취소
                        cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.GIFT);
                        break;

                    case ItemConst.TR_ITEM_ID.CREDIT_ITEM:
                        // 외상 취소
                        cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SALEONCUSTOMER);
                        break;

                    case ItemConst.TR_ITEM_ID.FOREIGNEX_ITEM:
                        // 외화 취소
                        cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.FOREIGN);
                        break;
                            
                    case ItemConst.TR_ITEM_ID.PPCARD_ITEM:
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PPCARD.PP_CARD)
                        {
                            // 선불카드 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.PREPAIDCARD);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PPCARD.HP_GIFT)
                        {
                            // 해피 기프트 사용 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.HAPPYGIFTUSE);
                        }
                        //#20171018, 해피기프트(코나머니) 결제코드(신용->선불) 변경 Start, srlee
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PPCARD.HPGIFT_CARD)
                        {
                            // 해피기프트카드(코나머니)
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.HPGIFTCARD);
                        }
                        //#20171018, 해피기프트(코나머니) 결제코드(신용->선불) 변경 End, srlee
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PPCARD.HPPP_CARD)
                        {
                            // 선불카드 취소 - 중국
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.PREPAIDCARD_CHINA);
                        }
                        break;

                    case ItemConst.TR_ITEM_ID.EMP_PAY_ITEM:
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.EMP_PAY.SPC)
                        {
                            // SPC 임직원 결제 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SPCEMPLOYEEUSE);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.EMP_PAY.SEVERANCE)
                        {
                            // 세브란스 직원 결제 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SEVERANCEDC);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.EMP_PAY.OURHOME)
                        {
                            // 아워홈 직원 결제 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.OURHOME);
                        }
                        break;

                    case ItemConst.TR_ITEM_ID.PAY_ITEM:
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAY.ALIPAY_PAY )
                        {
                            // 알리페이 취소
                            if (m_cPosStatus.Mst.CntryDiv == ItemConst.CNTRY_DIV.KR)
                                cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.ALIPAY);
                            else
                                cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.WECHATPAY);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAY.WECHAT_PAY)
                        {
                            // 위챗페이 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.WECHATPAY);
                        }
                        // #Rhee, 20170922 중국 은련페이 추가 start
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAY.UNION_PAY)
                        {
                            // 은련페이 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.WECHATPAY);
                        }
                        // #Rhee, 20170922 중국 은련페이 추가 end
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAY.SMILE_PAY)
                        {
                            // 스마일페이 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SMAILPAY);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAY.T_PAY )
                        {
                            // T페이 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.TPAY);
                        }
                        //2017.09.11.001;바이롱 위쳇페이 추가 start ; girak.kim
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAY.WECHAT_BIORONG_PAY)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.WECHATPAY_BAIRONG);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.PAY.XIAO_GIFTCARD_PAY)
                        {
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.XIAOCHENGXU_GIFT_CARD);
                        }
                        //2017.09.11.001;바이롱 위쳇페이 추가 end ; girak.kim


                        break;

                    case ItemConst.TR_ITEM_ID.ETC_INFO_ITEM:
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT)
                        {
                            // 해피포인트 적립 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYPOINT);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.ETC_INFO.POINT_SAVE_CHINA )
                        {
                            // 해피포인트 적립 취소 - 중국
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYPOINT_SAVE_CHINA);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.ETC_INFO.CASHBILL)
                        {
                            // 현금영수증 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.CASHBILL);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.ETC_INFO.OCB_SAVE)
                        {
                            // OCB 적립 취소
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.PNT_OCB_SAVE);
                        }
                        else if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.ETC_INFO.ONLINE_CPN)
                        {
                            // 온라인쿠폰발행 취소 - 중국
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.ONLINE_COUPON_PRT);
                        }
                        break;
                    case ItemConst.TR_ITEM_ID.MOBILECASH_ITEM:
                        // 티머니/캐시비 취소
                        cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.TMONEY);
                        break;
                    case ItemConst.TR_ITEM_ID.ORDER_ITEM:
                        if (sPAY_DTL_CD == ItemConst.TR_ITEM_ID.ORDER.HPORDER_REVDC )
                        {
                            // 해피오더사전예약 할인(2017.05.15)
                            cPayItem = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.PAYDCMST_TO_DC);
                        }
                        break;
                    default:
                        break;
                }

                if (cPayItem == null) return sRet;

                if (bRefund == true)
                {
                    //#20171020 log 추가 
                    UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                        "cPayItem.RefundPayment START" + sSeqNo);



                    //#20180410 인천공항 반품 시 원승인번호,원거래일자 저장 start,phj
                    //기존
                    //#20171227 인천공항 포스연동 start, phj
                    if (PosMstManager.GetPosOption(POS_OPTION.OPT512) == "1" &&
                        (sPAY_WAY_CD == ItemConst.TR_ITEM_ID.CREDITCARD_ITEM &&
                        sPAY_DTL_CD == ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD))
                    {
                        sRet = UserCom.RST_OK;
                    }
                    else
                    {
                        sRet = cPayItem.RefundPayment(new string[] { sSeqNo });
                    } 
                    //#20171227 인천공항 포스연동 end, phj
                    
                    //수정
                    //sRet = cPayItem.RefundPayment(new string[] { sSeqNo });
                    //#20180410 인천공항 반품 시 원승인번호,원거래일자 저장 end,phj

                    UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                        "cPayItem.RefundPayment END" + sSeqNo);
                }
                else
                {
                    //#20171020 log 추가 
                    UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                        "cPayItem.CancelPayment " + sSeqNo);

                    sRet = cPayItem.CancelPayment(new string[] { sSeqNo });
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }
    }
}
