package itn.let.mjo.event.web;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import egovframework.rte.fdl.idgnr.EgovIdGnrService;
import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import itn.com.cmm.LoginVO;
import itn.com.cmm.util.KgmPayUtil;
import itn.com.cmm.util.StringUtil;
import itn.com.utl.fcc.service.EgovStringUtil;
import itn.let.cop.bbs.service.BoardVO;
import itn.let.mail.service.StatusResponse;
import itn.let.mjo.event.service.MjonEventService;
import itn.let.mjo.event.service.MjonEventVO;
import itn.let.mjo.msgcampain.service.MjonCandidateService;
import itn.let.mjo.msgcampain.service.MjonCandidateVO;
import itn.let.mjo.pay.service.MjonKgmVO;
import itn.let.mjo.pay.service.MjonPayService;
import itn.let.mjo.pay.service.MjonPayVO;
import itn.let.mjo.pay.service.MjonVaMsgLogVO;
import itn.let.mjo.payva.service.VacsVactService;
import itn.let.mjo.payva.service.VacsVactVO;
import itn.let.sym.site.service.JoinSettingVO;
import itn.let.uss.umt.service.EgovMberManageService;
import itn.let.uss.umt.service.MberManageVO;
import itn.let.uss.umt.service.UserManageVO;

@Controller
public class MjonEventPayV2Controller {
	@Resource(name = "MjonEventService")
    private MjonEventService mjonEventService;
	
	@Resource(name = "mberManageService")
	private EgovMberManageService mberManageService;
	
	@Resource(name = "mjonCandidateService")
    private MjonCandidateService mjonCandidateService;
	
	//전용계좌 서비스
	@Resource(name = "vacsVactService")
	private VacsVactService vacsVactService;
	
	@Resource(name = "mjonPayService")
    private MjonPayService mjonPayService;
	
	@Resource(name = "egovPgMoidGnrService")
    private EgovIdGnrService idgenPgMoid;
	
	@Resource(name = "kgmPayUtil")
	KgmPayUtil kgmPayUtil;
	
	
    /**
     * 이벤트 결제하기 화면
     * @param searchVO
     * @param model
     * @return	"/web/event/member/pay/PayView.do"
     * @throws Exception
     */
    @RequestMapping(value= {"/web/event/member/pay/PayView.do"})
	public String PayViewV2(@ModelAttribute("mjonPayVO") MjonPayVO mjonPayVO, 
			HttpServletRequest request, RedirectAttributes redirectAttributes,
			ModelMap model) throws Exception{
    	
    	String pattern = (String) request.getAttribute(
                HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE) ;

    	//로그인 정보 획득
//    	LoginVO loginVO = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
    	LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
    	String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
    	
		if(loginVO == null) {
			//redirectAttributes.addFlashAttribute("message", "문자온 서비스는 로그인 후 이용 가능합니다.");
			return "redirect:/web/user/login/login.do";
		}
		
		//기존 결제 내역이 있는 회원인지 확인
		int payCnt = 0;
		if(StringUtil.isNotEmpty(userId)) {
			//결제내역 카운트 조회
			payCnt = mjonPayService.selectMemerPayCount(userId);
			
			if(payCnt > 0) {
				
				redirectAttributes.addFlashAttribute("message", "고객님께서는 첫결제 이벤트 대상이 아닙니다.");
				return "redirect:/web/main/mainPage.do";
				
			}else {
				
				String bbsId = "BBSMSTR_000000000731";	//이벤트 게시판 번호
				String nttSj = "[첫결제 이벤트] 첫 결제 시, 누구나 조건 없이 인생 최저가!";
				BoardVO resultEvent = selectEventBoardInfo(bbsId, nttSj);
				
				
				if(resultEvent != null) {//진행중 이벤트 이면 이벤트 게시글 번호 셋팅
					
					// Step 0. B선 전송사 이용고객 => 이벤트대상 제외처리
					MberManageVO mberManageVO = new MberManageVO();
					mberManageVO.setMberId(userId);
					String blineCode = mberManageService.selectBlineCodeByMberId(mberManageVO);
					if (blineCode != null && blineCode.equals("N")) {
						//이벤트 회원 정보 조회
						MjonEventVO mjonEventVO = new MjonEventVO();
						MjonEventVO eventMberInfo = selectEventMsgMberDefaultInfo(mjonEventVO, resultEvent.getNttId(), bbsId, loginVO.getId(), loginVO.getName());
						
						int resultCnt = 0;
						
						if(eventMberInfo == null) {//등록된 회원정보가 없으면 정보 입력
							mjonEventVO.setEventStatus("N");
							resultCnt = mjonEventService.insertEventMsgMberDefaultInfo(mjonEventVO);
						}else {//등록된 회원정보가 있으면 화면 이동 및 메세지 처리
							
							String status = eventMberInfo.getEventStatus();
							
							if(status.equals("Y")) {//이벤트가 진행중인 경우
								
								redirectAttributes.addFlashAttribute("message", "현재 첫 결제 이벤트를 진행중입니다.");
								return "redirect:/web/main/mainPage.do";
								
							}else if(status.equals("E")) {//이벤트가 종료된 경우
								
								redirectAttributes.addFlashAttribute("message", "현재 첫 결제 이벤트를 완료 하였습니다.");
								return "redirect:/web/main/mainPage.do";
								
							}
							
						}						
					}
					else {
						redirectAttributes.addFlashAttribute("message", "이벤트 대상자가 아닙니다.");
						return "redirect:/web/main/mainPage.do";						
					}
					
				}else {//이벤트 게시글 정보가 없으면 0으로 셋팅.
					
					redirectAttributes.addFlashAttribute("message", "첫 결제 이벤트는 종료 되었습니다.");
					return "redirect:/web/main/mainPage.do";
					
				}
				
			}
			
		}

		MberManageVO mberManageVO = mberManageService.selectMber(loginVO.getId());
    	model.addAttribute("mberManageVO", mberManageVO);
    	
    	MjonCandidateVO mjonCandidateVO = new MjonCandidateVO();
    	if(userId != "") { 
    		mjonCandidateVO = mjonCandidateService.selectCandidateDataInfo(userId);
    		model.addAttribute("mjonCandidateVO",mjonCandidateVO);
    	}
		
    	mjonPayVO.setReturnURL(request.getRequestURL().toString().split("pay")[0] + "nicepay/payResultAjax.do") ;
    	
		/** pageing */
		PaginationInfo paginationInfo = new PaginationInfo();
		paginationInfo.setCurrentPageNo(mjonPayVO.getPageIndex());
		paginationInfo.setRecordCountPerPage(mjonPayVO.getPageUnit());
		paginationInfo.setPageSize(mjonPayVO.getPageSize());
		
		mjonPayVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
		mjonPayVO.setLastIndex(paginationInfo.getLastRecordIndex());
		mjonPayVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
		
		if("".equals(mjonPayVO.getSearchSortCnd())){ //최초조회시 최신것 조회List
			mjonPayVO.setSearchSortCnd("moid");
			mjonPayVO.setSearchSortOrd("desc");
		}
		mjonPayVO.setUserId(loginVO.getId());
		
        /*List<MjonPayVO> resultList = mjonPayService.selectPayList(mjonPayVO);*/   
        
        /*model.addAttribute("resultList", resultList);
        paginationInfo.setTotalRecordCount(resultList.size() > 0 ? ((MjonPayVO)resultList.get(0)).getTotCnt() : 0);*/
		/*model.addAttribute("paginationInfo", paginationInfo);*/
		
		//대상 리스트 가져오기    
		VacsVactVO vacsVactVO = new VacsVactVO();
		vacsVactVO.setMberId(loginVO.getId());
    	//List<?> bankList = vacsVactService.selectBankAcctList(tempVO);		//할당 가능한 계좌 수량  리스트 받아오기
    	List<?> bankList = vacsVactService.selectBankAcctAllList(vacsVactVO);		//할당 가능한 계좌 수량  리스트 받아오기
    	List<?> myBankList = vacsVactService.selectMyBankAcctList(vacsVactVO);		//내가 할당받은 전용계좌 리스트 받아오기
    	
    	MjonVaMsgLogVO vaMsgLogVO = new MjonVaMsgLogVO();
    	vaMsgLogVO.setMberId(loginVO.getId());
    	
    	Date now = new Date();
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String date = sdf.format(now);
		vaMsgLogVO.setSendDate(date);
		
    	MjonVaMsgLogVO resultMsgInfo = mjonPayService.selectMyAcctSendCnt(vaMsgLogVO);
    	
    	//대상 리스트, 페이징 정보 전달
    	model.addAttribute("resultList", bankList);
    	model.addAttribute("resultMyList", myBankList);
    	model.addAttribute("resultMsgInfo", resultMsgInfo);
    	model.addAttribute("mjonPayVO", mjonPayVO);
    	
    	// 탭이동
    	String tabType = "1";
    	if(request.getParameter("tabType") != null) {
    		tabType = request.getParameter("tabType");
   		}
    	model.addAttribute("tabType", tabType);
    	
		return "/web/event/pay/EventPayView";
	}
    
    
    //이벤트 게시글 정보 불러오기 함수
    public BoardVO selectEventBoardInfo(String bbsId, String nttSj) throws Exception{
    	
		BoardVO boardVO = new BoardVO();
		boardVO.setBbsId(bbsId);
		boardVO.setNttSj(nttSj);
		BoardVO resultEvent = mjonEventService.selectEventInfoByNttSj(boardVO);
		
		return resultEvent;
    }
    
    //이벤트 회원 정보 불러오기 함수
    public MjonEventVO selectEventMsgMberDefaultInfo(MjonEventVO mjonEventVO, float nttId, String bbsId, String mberId, String mberNm) throws Exception{
    	
    	mjonEventVO.setEventNttId(Float.toString(nttId));
		mjonEventVO.setEventBbsId(bbsId);
		mjonEventVO.setMberId(mberId);
		mjonEventVO.setMberNm(mberNm);
		mjonEventVO.setEventShortPrice("7.5");
		mjonEventVO.setEventLongPrice("32");
		mjonEventVO.setEventPicturePrice("59");
		mjonEventVO.setEventPicture2Price("67");
		mjonEventVO.setEventPicture3Price("70");
		
		//이벤트 회원정보 존재여부 확인 및 회원 정보 불러오기
		MjonEventVO eventMberInfo = mjonEventService.selectEventMsgMberDefaultInfo(mjonEventVO);
		
		return eventMberInfo;
    }
    
    // 나이스페이 
    @RequestMapping(value= {"/web/event/member/pay/firstEventPayActionAjax.do"})
	public String firstEventPayAction(
			@ModelAttribute("mjonPayVO") MjonPayVO mjonPayVO
			, HttpServletRequest request
			, ModelMap model) throws Exception{
    	
    	String pattern = (String) request.getAttribute(
                HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE) ;
    	
    	mjonPayVO.setReturnURL(request.getRequestURL().toString().split("pay")[0] + "pay/firstPayResultAjax.do") ;
    	LoginVO	loginVO = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
    	//테스트
    	mjonPayVO.setBuyerName(loginVO.getName());			//구매자 이름
    	mjonPayVO.setBuyerEmail(loginVO.getEmail());		//구매자 이메일
    	mjonPayVO.setBuyerTel(loginVO.getMoblphonNo());		//구매자 휴대폰 번호
    	//moid 생성 위치 변경
    	mjonPayVO.setMoid(idgenPgMoid.getNextStringId());				
    	
    	//결제 페이지
    	mjonPayVO.setReturnURL("/web/event/member/pay/firstEventPayResultAjax.do");
    	
		model.addAttribute("mjonPayVO", mjonPayVO);
		return "web/cop/nicepay/payRequestMber";
	}
    
    @RequestMapping( value = {"/web/event/member/pay/firstEventPayResultAjax.do"}) 
	public String firstEventPayResult(HttpServletRequest request, 
			ModelMap model , @RequestParam Map<String, Object> commandMap, 
			@ModelAttribute("searchVO") MjonPayVO mjonPayVO) throws Exception {
		
    	String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE) ;
		
		//mjonPayVO.setReturnURL(request.getRequestURL().toString().split("nice")[0] + "payResult.do") ;
		MjonPayVO returnMjonPayVO = new MjonPayVO();
		mjonPayVO.setPageType("event");
		
		// returnMjonPayVO = mjonPayService.insertPay(mjonPayVO , request, "nice" ); //PG, PGTXT, CASH , 포인트 insert / 회원정보 캐시,포인트 update
		returnMjonPayVO = mjonEventService.insertFirstEventNicePay_advc(mjonPayVO , request, "nice" ); //PG, PGTXT, CASH , 포인트 insert / 회원정보 캐시,포인트 update
		
		model.addAttribute("mjonPayVO", returnMjonPayVO);
		if(pattern.equals("/web/member/pay/payResultAjax.do")){
			model.addAttribute("userPage", true);
		}
		
		return "web/cop/nicepay/payResultAjax";
	}
    
    
    // KG모빌런스
	/////////////////////////////////////////////////////////////////////////////////////////
	//
	//	Mobile Start
	//
	/**
	* KGM 정보 Encode
	* @param MjonPayVO
	* @param modelAndView
	* @return /web/event/member/pay/firstEventKgmMobileEncodeAjax.do
	* @throws Exception
	*/
    @RequestMapping(value = "/web/event/member/pay/firstEventKgmMobileEncodeAjax.do")
   	public ResponseEntity<StatusResponse>  firstEventKgmMobileEncodeAjax(
   			MjonPayVO mjonPayVO
   			, HttpServletRequest request ) throws Exception {
      
		LoginVO	loginVO = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
   		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
   		
   		if(StringUtils.isEmpty(userId)) {
			return ResponseEntity.ok().body(new StatusResponse(HttpStatus.OK, "", ""));
		}
   		
   		MjonKgmVO mjonKgmVO = kgmPayUtil.kgmMobileEncode(request
   				, "/web/event/member/pay/firstEventOkUrlMobileAjax.do"
   				, "/web/event/member/pay/firstEventNotiUrlMobileAjax.do");
   		return ResponseEntity.ok().body(new StatusResponse(HttpStatus.OK, "", mjonKgmVO));
   	}
    
    @RequestMapping(value= {"/web/event/member/pay/firstEventOkUrlMobileAjax.do"})
	public String firstEventOkUrlMobileAjax(			
			HttpServletRequest request
			, HttpSession session
			, HttpServletResponse response			
			, ModelMap model
		) throws Exception{

		//크롬 SameSite정책 방지 - 도메인이 다른 타사로 이동 시 크롬 정책에 의해 세션 유실이 일어나는 경우가 있는데, 이를 방지하기 위해 samesite 보안을 none처리
		response.setHeader("Set-Cookie", "mberSession=mberSession; Secure; SameSite=None");
		
    	String rstMsg = "";
    	if("0000".equals(request.getParameter("Resultcd"))) {
    		rstMsg = "휴대폰결제가 정상적으로 완료되었습니다.";
    	}
    	else {
    		rstMsg = "휴대폰결제가 실패했습니다.";
    	}

    	model.addAttribute("Resultcd", request.getParameter("Resultcd"));
    	model.addAttribute("Resultmsg", rstMsg);

    	System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
		System.out.println("KG MOBILIANS OkUrl - MOBILE ResultCd : " + request.getParameter("Resultcd"));
		System.out.println("KG MOBILIANS OkUrl - MOBILE ResultMsg : " + rstMsg);    					    			
		
    	return "web/cop/kgmV2/mobileOkUrl";
	}
    
    @RequestMapping(value= {"/web/event/member/pay/firstEventNotiUrlMobileAjax.do"})
	public String firstEventNotiUrlMobileAjax(HttpServletRequest request, HttpServletResponse response
			, @ModelAttribute("searchVO") MjonPayVO mjonPayVO
			, ModelMap model) throws Exception{
    	
    	ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("jsonView");
		
    	//크롬 SameSite정책 방지 - 도메인이 다른 타사로 이동 시 크롬 정책에 의해 세션 유실이 일어나는 경우가 있는데, 이를 방지하기 위해 samesite 보안을 none처리
    	response.setHeader("Set-Cookie", "mberSession=mberSession; Secure; SameSite=None");

    	String rtnMsg = mjonEventService.insertFirstEventKgPayMobile_advc(mjonPayVO, response, request);
		
		model.addAttribute("returnMsg", rtnMsg);
		
		return "web/cop/kgmV2/mobileNotiUrl";
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////
    //
    //	BANK Start
    //
    /**
   	 * KGM 정보 Encode
   	 * @param MjonPayVO
   	 * @param modelAndView
   	 * @return /web/event/member/pay/kgmEncodeAjax.do
   	 * @throws Exception
   	 */
    @RequestMapping(value = "/web/event/member/pay/firstEventKgmBankEncodeAjax.do")
   	public ResponseEntity<StatusResponse>  firstEventKgmBankEncodeAjax(
   			MjonPayVO mjonPayVO
   			, HttpServletRequest request ) throws Exception {
      
		LoginVO	loginVO = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
   		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
   		
   		if(StringUtils.isEmpty(userId)) {
			return ResponseEntity.ok().body(new StatusResponse(HttpStatus.OK, "", ""));
		}
   		
   		MjonKgmVO mjonKgmVO = kgmPayUtil.kgmBankEncode(request
   				, "/web/event/member/pay/firstEventOkUrlBankAjax.do"
   				, "/web/event/member/pay/firstEventNotiUrlBankAjax.do");
   		return ResponseEntity.ok().body(new StatusResponse(HttpStatus.OK, "", mjonKgmVO));
   	}
    
    @RequestMapping(value= {"/web/event/member/pay/firstEventOkUrlBankAjax.do"})
    public String okUrlBankAjax(			
			HttpServletRequest request
			, HttpSession session
			, HttpServletResponse response			
			, ModelMap model
		) throws Exception{

		//크롬 SameSite정책 방지 - 도메인이 다른 타사로 이동 시 크롬 정책에 의해 세션 유실이 일어나는 경우가 있는데, 이를 방지하기 위해 samesite 보안을 none처리
		response.setHeader("Set-Cookie", "mberSession=mberSession; Secure; SameSite=None");
		
    	String rstMsg = "";
    	if("0000".equals(request.getParameter("Resultcd"))) {
    		rstMsg = "즉시이체가 정상적으로 완료되었습니다.";
    	}
    	else {
    		rstMsg = "즉시이체가 실패했습니다.";
    	}

    	model.addAttribute("Resultcd", request.getParameter("Resultcd"));
    	model.addAttribute("Resultmsg", rstMsg);

		System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
		System.out.println("KG MOBILIANS OkUrl - BANK ResultCd : " + request.getParameter("Resultcd"));
		System.out.println("KG MOBILIANS OkUrl - BANK ResultMsg : " + rstMsg);    					    			
		
    	return "web/cop/kgmV2/bankOkUrl";
    }
    /**
     * KGM Bank 결제notiUrl 페이지 
     * @param searchVO
     * @param model
     * @throws Exception
     */
    @RequestMapping(value= {"/web/event/member/pay/firstEventNotiUrlBankAjax.do"})
	public String notiUrlBankAjax(HttpServletRequest request, HttpServletResponse response
		, @ModelAttribute("searchVO") MjonPayVO mjonPayVO
		, ModelMap model) throws Exception{
	
		//크롬 SameSite정책 방지 - 도메인이 다른 타사로 이동 시 크롬 정책에 의해 세션 유실이 일어나는 경우가 있는데, 이를 방지하기 위해 samesite 보안을 none처리
		response.setHeader("Set-Cookie", "mberSession=mberSession; Secure; SameSite=None");
		
		String rtnMsg = mjonEventService.insertFirstEventKgPayBank_advc(mjonPayVO, response, request);
		
		model.addAttribute("returnMsg", rtnMsg);
		
		return "web/cop/kgmV2/bankNotiUrl";
	}
   
	/////////////////////////////////////////////////////////////////////////////////////////
	//
	//	card Start
	//
    /**
   	 * KGM 정보 Encode
   	 * @param MjonPayVO
   	 * @param modelAndView
   	 * @return /web/event/member/pay/firstEventKgmCardEncodeAjax.do
   	 * @throws Exception
   	 */
    @RequestMapping(value = "/web/event/member/pay/firstEventKgmCardEncodeAjax.do")
   	public ResponseEntity<StatusResponse>  firstEventKgmCardEncodeAjax(
   			MjonPayVO mjonPayVO
   			, HttpServletRequest request ) throws Exception {
      
		LoginVO	loginVO = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
   		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
   		
   		if(StringUtils.isEmpty(userId)) {
			return ResponseEntity.ok().body(new StatusResponse(HttpStatus.OK, "", ""));
		}
   		
   		MjonKgmVO mjonKgmVO = kgmPayUtil.kgmCardEncode(request
   				, "/web/event/member/pay/firstEventOkUrlCardAjax.do"
   				, "/web/event/member/pay/firstEventNotiUrlCardAjax.do");
   		return ResponseEntity.ok().body(new StatusResponse(HttpStatus.OK, "", mjonKgmVO));
   	}
    
    @RequestMapping(value= {"/web/event/member/pay/firstEventOkUrlCardAjax.do"})
    public String firstEventOkUrlCardAjax(			
			HttpServletRequest request
			, HttpSession session
			, HttpServletResponse response			
			, ModelMap model
		) throws Exception{

		//크롬 SameSite정책 방지 - 도메인이 다른 타사로 이동 시 크롬 정책에 의해 세션 유실이 일어나는 경우가 있는데, 이를 방지하기 위해 samesite 보안을 none처리
		response.setHeader("Set-Cookie", "mberSession=mberSession; Secure; SameSite=None");
		
    	String rstMsg = "";
    	if("0000".equals(request.getParameter("Resultcd"))) {
    		rstMsg = "즉시이체가 정상적으로 완료되었습니다.";
    	}
    	else {
    		rstMsg = "즉시이체가 실패했습니다.";
    	}

    	model.addAttribute("Resultcd", request.getParameter("Resultcd"));
    	model.addAttribute("Resultmsg", rstMsg);

		System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
		System.out.println("KG MOBILIANS OkUrl - CARD ResultCd : " + request.getParameter("Resultcd"));
		System.out.println("KG MOBILIANS OkUrl - CARD ResultMsg : " + rstMsg);    					    			
		
    	return "web/cop/kgmV2/cardOkUrl";
    }
    /**
     * KGM card 결제notiUrl 페이지 
     * @param searchVO
     * @param model
     * @throws Exception
     */
    @RequestMapping(value= {"/web/event/member/pay/firstEventNotiUrlCardAjax.do"})
	public String firstEventNotiUrlCardAjax(HttpServletRequest request, HttpServletResponse response
		, @ModelAttribute("searchVO") MjonPayVO mjonPayVO
		, ModelMap model) throws Exception{
	
		//크롬 SameSite정책 방지 - 도메인이 다른 타사로 이동 시 크롬 정책에 의해 세션 유실이 일어나는 경우가 있는데, 이를 방지하기 위해 samesite 보안을 none처리
		response.setHeader("Set-Cookie", "mberSession=mberSession; Secure; SameSite=None");
		
		String rtnMsg = mjonEventService.insertFirstEventKgPayBank_advc(mjonPayVO, response, request);
		
		model.addAttribute("returnMsg", rtnMsg);
		
		return "web/cop/kgmV2/cardNotiUrl";
	}
}
