<!--[submit]인증응답 페이지-->
<!--메뉴얼 '인증페이지 작성' 인증응답 파라미터 포함.-->

<!DOCTYPE html>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
/* -------------------------------------------------------------------------- */
/* 캐쉬 사용안함                                                              */
/* -------------------------------------------------------------------------- */
response.setHeader("cache-control","no-cache");
response.setHeader("expires","-1");
response.setHeader("pragma","no-cache");

request.setCharacterEncoding("utf-8");

System.out.println("sp_res_cd ===> " + request.getParameter("sp_res_cd"));
%>
<%!
    /*
     * 파라미터 체크 메소드
     */
    public String getNullToSpace(String param) 
    {
        return (param == null) ? "" : param.trim();
    }
%>
<c:set var="contextPath" value="${pageContext.request.contextPath}" /> 
<html lang="ko" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="robots" content="noindex, nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../../../../js/jquery.min.js"></script>
<script>
    /*--KICC 서버로부터 인증응답 파라미터 수신--*/
    window.onload = function()
    {
        var res_cd = "<%=getNullToSpace(request.getParameter("sp_res_cd"))%>";
        // <!--공통-->
        document.getElementById("sp_res_cd").value             = res_cd;  // [필수]응답코드
        document.getElementById("sp_res_msg").value            = "<%=getNullToSpace(request.getParameter("sp_res_msg"))          %>";  // [필수]응답메세지
        document.getElementById("sp_tr_cd").value              = "<%=getNullToSpace(request.getParameter("sp_tr_cd"))            %>";  // [필수]결제창 요청구분
        document.getElementById("sp_ret_pay_type").value       = "<%=getNullToSpace(request.getParameter("sp_ret_pay_type"))     %>";  // [필수]결제수단
        document.getElementById("sp_trace_no").value           = "<%=getNullToSpace(request.getParameter("sp_trace_no"))         %>";  // [선택]추적번호
        document.getElementById("sp_order_no").value           = "<%=getNullToSpace(request.getParameter("sp_order_no"))         %>";  // [필수]가맹점 주문번호
        document.getElementById("sp_sessionkey").value         = "<%=getNullToSpace(request.getParameter("sp_sessionkey"))       %>";  // [필수]세션키
        document.getElementById("sp_encrypt_data").value       = "<%=getNullToSpace(request.getParameter("sp_encrypt_data"))     %>";  // [필수]암호화전문
        document.getElementById("sp_mall_id").value            = "<%=getNullToSpace(request.getParameter("sp_mall_id"))          %>";  // [필수]가맹점 ID
        document.getElementById("sp_mobilereserved1").value    = "<%=getNullToSpace(request.getParameter("sp_mobilereserved1"))  %>";  // [선택]여유필드
        document.getElementById("sp_mobilereserved2").value    = "<%=getNullToSpace(request.getParameter("sp_mobilereserved2"))  %>";  // [선택]여유필드
        document.getElementById("sp_reserved1").value          = "<%=getNullToSpace(request.getParameter("sp_reserved1"))        %>";  // [선택]여유필드
        document.getElementById("sp_reserved2").value          = "<%=getNullToSpace(request.getParameter("sp_reserved2"))        %>";  // [선택]여유필드
        document.getElementById("sp_reserved3").value          = "<%=getNullToSpace(request.getParameter("sp_reserved3"))        %>";  // [선택]여유필드
        document.getElementById("sp_reserved4").value          = "<%=getNullToSpace(request.getParameter("sp_reserved4"))        %>";  // [선택]여유필드

        // <!--신용카드-->
        document.getElementById("sp_card_code").value          = "<%=getNullToSpace(request.getParameter("sp_card_code"))        %>";  // [필수]카드코드
        document.getElementById("sp_eci_code").value           = "<%=getNullToSpace(request.getParameter("sp_eci_code"))         %>";  // [선택]ECI코드(MPI인 경우)
        document.getElementById("sp_card_req_type").value      = "<%=getNullToSpace(request.getParameter("sp_card_req_type"))    %>";  // [필수]거래구분
        document.getElementById("sp_save_useyn").value         = "<%=getNullToSpace(request.getParameter("sp_save_useyn"))       %>";  // [선택]카드사 세이브 여부
        document.getElementById("sp_card_prefix").value        = "<%=getNullToSpace(request.getParameter("sp_card_prefix"))      %>";  // [선택]신용카드 Prefix
        document.getElementById("sp_card_no_7").value          = "<%=getNullToSpace(request.getParameter("sp_card_no_7"))        %>";  // [선택]신용카드번호 앞7자리

        // <!--간편결제-->
        document.getElementById("sp_spay_cp").value            = "<%=getNullToSpace(request.getParameter("sp_spay_cp"))          %>";  // [선택]간편결제 CP코드

        // <!--선불카드-->
        document.getElementById("sp_prepaid_cp").value         = "<%=getNullToSpace(request.getParameter("sp_prepaid_cp"))       %>";  // [선택]선불카드 CP코드

        console.log("res_cd ===> " + res_cd);
        if( res_cd == "0000" )
        {
            location.replace('app:pay:result:' + JSON.stringify(serialize()));
        }
        else
        {
            alert( urldecode(res_cd + " : <%=request.getParameter("sp_res_msg") %>"));
            var resText = '{\"sp_res_cd\" : \"' + res_cd + '\"}';
            location.replace('app:pay:result:' + resText);
        }
    };
    
    function urldecode( str ) {
        // 공백 문자인 + 를 처리하기 위해 +('%20') 을 공백으로 치환
        return decodeURIComponent((str + '').replace(/\+/g, '%20'));
    }

    function serialize() {
        var form = document.getElementById("frm_pay");
        const serialized = {};
        for (let i = 0, length = form.elements.length; i < length; i++) {
            const field = form.elements[i];
            if (field.name && !field.disabled && "file" !== field.type && "reset" !== field.type && "submit" !== field.type && "button" !== field.type) {
                if(field.type === 'text' || field.type === 'hidden') {
                    serialized[field.name] = trim(field.value);
                }
            }
        }
        console.log('serialize : ' + JSON.stringify(serialized));
        return serialized;
    }

    function trim(text) {
        var regex = / /gi;
        return text.replace(regex, '');
    }
</script>
<title>오더퀸 수발주 결제하기</title>
</head>
<body>
<form name="frm_pay" id="frm_pay" method="post" >
    <!-- [START] 인증응답 필드 -->

    <!--공통-->
    <input type="hidden" id="sp_res_cd"              name="sp_res_cd"                value="" />         <!-- [필수]응답코드        -->
    <input type="hidden" id="sp_res_msg"             name="sp_res_msg"               value="" />         <!-- [필수]응답메시지      -->
    <input type="hidden" id="sp_tr_cd"               name="sp_tr_cd"                 value="" />         <!-- [필수]결제창 요청구분 -->
    <input type="hidden" id="sp_ret_pay_type"        name="sp_ret_pay_type"          value="" />         <!-- [필수]결제수단        -->
    <input type="hidden" id="sp_trace_no"            name="sp_trace_no"              value="" />         <!-- [선택]추적번호        -->
    <input type="hidden" id="sp_order_no"            name="sp_order_no"              value="" />         <!-- [필수]가맹점 주문번호 -->
    <input type="hidden" id="sp_sessionkey"          name="sp_sessionkey"            value="" />         <!-- [필수]세션키          -->
    <input type="hidden" id="sp_encrypt_data"        name="sp_encrypt_data"          value="" />         <!-- [필수]암호화전문      -->
    <input type="hidden" id="sp_mall_id"             name="sp_mall_id"               value="" />         <!-- [필수]가맹점 ID       -->
    <input type="hidden" id="sp_mobilereserved1"     name="sp_mobilereserved1"       value="" />         <!-- [선택]여유필드        -->
    <input type="hidden" id="sp_mobilereserved2"     name="sp_mobilereserved2"       value="" />         <!-- [선택]여유필드        -->
    <input type="hidden" id="sp_reserved1"           name="sp_reserved1"             value="" />         <!-- [선택]여유필드        -->
    <input type="hidden" id="sp_reserved2"           name="sp_reserved2"             value="" />         <!-- [선택]여유필드        -->
    <input type="hidden" id="sp_reserved3"           name="sp_reserved3"             value="" />         <!-- [선택]여유필드        -->
    <input type="hidden" id="sp_reserved4"           name="sp_reserved4"             value="" />         <!-- [선택]여유필드        -->

    <!--신용카드-->
    <input type="hidden" id="sp_card_code"            name="sp_card_code"            value="" />         <!-- [필수]카드코드               -->
    <input type="hidden" id="sp_eci_code"             name="sp_eci_code"             value="" />         <!-- [선택]ECI코드(MPI인 경우)    -->
    <input type="hidden" id="sp_card_req_type"        name="sp_card_req_type"        value="" />         <!-- [필수]거래구분               -->
    <input type="hidden" id="sp_save_useyn"           name="sp_save_useyn"           value="" />         <!-- [선택]카드사 세이브 여부     -->
    <input type="hidden" id="sp_card_prefix"          name="sp_card_prefix"          value="" />         <!-- [선택]신용카드 Prefix        -->
    <input type="hidden" id="sp_card_no_7"            name="sp_card_no_7"            value="" />         <!-- [선택]신용카드번호 앞7자리   -->

    <!--간편결제-->
    <input type="hidden" id="sp_spay_cp"              name="sp_spay_cp"              value="" />          <!-- [선택]간편결제 CP코드 -->

    <!--선불카드-->
    <input type="hidden" id="sp_prepaid_cp"           name="sp_prepaid_cp"           value="" />          <!-- [선택]선불카드 CP코드 -->

    <!-- [END] 인증응답 필드  -->
</form>
</body>
</html>
