payment.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. var ajax_flag = true;
  2. var req01_AJAX;
  3. var PayUrl="";
  4. function initRequest() {
  5. if ( window.XMLHttpRequest ) {
  6. return new XMLHttpRequest();
  7. } else if ( window.ActiveXObject ) {
  8. return new ActiveXObject( "Microsoft.XMLHTTP" );
  9. }
  10. }
  11. function sendRequest( url ) {
  12. req01_AJAX = null;
  13. req01_AJAX = initRequest();
  14. if ( req01_AJAX ) {
  15. req01_AJAX.onreadystatechange = process_AJAX;
  16. req01_AJAX.open( "POST", url, true );
  17. req01_AJAX.send( null );
  18. }
  19. }
  20. function kcp_AJAX() {
  21. // 해당 소스는 jQuery를 사용 하지 않는 업체에서도 작동 할수 있도록 구현되었습니다.
  22. // 이 부분은 javascript로 구현시 jQuery를 이용하면 더욱 쉽게 구현 할수 있습니다.
  23. // 또는
  24. // javascript를 통한 ajax 통신을 할 필요 없이 소스내에 order_approval.jsp를 연동해서 사용 하셔도 관계 없으며
  25. // 제공되는 jar 파일에 직접 전달된 데이터를 사용할수 있도록 method가 구현 되어 있습니다.
  26. if(ajax_flag) {
  27. var url = "/pg/kcp/approval";
  28. var form = document.order_info;
  29. var params = "?site_cd=" + form.site_cd.value
  30. + "&ordr_idxx=" + form.ordr_idxx.value
  31. + "&good_mny=" + form.good_mny.value
  32. + "&pay_method=" + form.pay_method.value
  33. + "&escw_used=" + form.escw_used.value
  34. + "&good_name=" + form.good_name.value
  35. + "&response_type=" + form.response_type.value
  36. + "&Ret_URL=" + form.Ret_URL.value;
  37. sendRequest( url + params );
  38. ajax_flag = false;
  39. } else {
  40. alert("통신 중입니다. 잠시만 기다려 주세요.");
  41. }
  42. }
  43. function process_AJAX() {
  44. if ( req01_AJAX.readyState == 4 ) { //READY_STATE_COMPLETE = 4
  45. if ( req01_AJAX.status == 200 ) {
  46. if ( req01_AJAX.responseText != null ) {
  47. // 해당 소스는 jQuery를 사용 하지 않는 업체에서도 작동 할수 있도록 구현되었습니다.
  48. // 이 부분은 javascript로 구현시 jQuery를 이용하면 더욱 쉽게 구현 할수 있습니다.
  49. // 또는
  50. // javascript를 통한 ajax 통신을 할 필요 없이 소스내에 order_approval.jsp를 연동해서 사용 하셔도 관계 없으며
  51. // 제공되는 jar 파일에 직접 전달된 데이터를 사용할수 있도록 method가 구현 되어 있습니다.
  52. try {
  53. var form = document.order_info;
  54. if( form.response_type.value == "JSON" ) {
  55. StateChangeForJSON( req01_AJAX ); // JSON 방식일 경우
  56. } else if( form.response_type.value == "XML" ) {
  57. StateChangeForXML( req01_AJAX ); // XML 방식일 경우
  58. } else if( form.response_type.value == "TEXT" || form.response_type.value == "" ) {
  59. StateChangeForText( req01_AJAX ); // TEXT 방식일 경우
  60. }
  61. } catch( e ) {
  62. StateChangeForText( req01_AJAX ); // TEXT 방식일 경우
  63. }
  64. }
  65. } else {
  66. ajax_flag=true;
  67. alert( req01_AJAX.responseJSON );
  68. }
  69. }
  70. }
  71. function StateChangeForText( req ) {
  72. var txt = req01_AJAX.responseText.split( ":" );
  73. if( txt[0].replace(/^\s*/,'').replace(/\s*$/,'') == '0000' ) {
  74. document.getElementById( "approval" ).value = txt[1].replace(/^\s*/,'').replace(/\s*$/,'');
  75. // 아래 alert는 삭제 해도됨
  76. alert("성공적으로 거래가 등록 되었습니다.");
  77. PayUrl = decodeURIComponent( txt[2].replace(/^\s*/,'').replace(/\s*$/,'') );
  78. document.getElementById( "traceNo" ).value = txt[3].replace(/^\s*/,'').replace(/\s*$/,'');
  79. if( txt.length == 6 )
  80. document.getElementById( "PayUrl" ).value = txt[5].replace(/^\s*/,'').replace(/\s*$/,'');
  81. call_pay_form();
  82. } else {
  83. var res_msg = txt[2].replace(/^\s*/,'').replace(/\s*$/,'');
  84. ajax_flag=true;
  85. alert("실패 되었습니다.[" + res_msg + "]");
  86. }
  87. }
  88. function StateChangeForXML( req ) {
  89. var xmlDoc = ( new DOMParser() ).parseFromString( req.responseText.replace(/^\s*/,'').replace(/\s*$/,''), "text/xml" ).documentElement;
  90. var x = xmlDoc.getElementsByTagName( "data" );
  91. if( x[0].getElementsByTagName( "Code" )[0].childNodes[0].nodeValue == '0000' ) {
  92. document.getElementById( "approval" ).value = x[0].getElementsByTagName( "approvalKey" )[0].childNodes[0].nodeValue;
  93. // 아래 alert는 삭제 해도됨
  94. alert("성공적으로 거래가 등록 되었습니다.");
  95. PayUrl = x[0].getElementsByTagName( "PayUrl" )[0].childNodes[0].nodeValue;
  96. document.getElementById( "traceNo" ).value = x[0].getElementsByTagName( "traceNo" )[0].childNodes[0].nodeValue;
  97. try{
  98. document.getElementById( "PayUrl" ).value = x[0].getElementsByTagName( "request_URI" )[0].childNodes[0].nodeValue;
  99. }catch(e){}
  100. call_pay_form();
  101. } else {
  102. ajax_flag=true;
  103. alert("실패 되었습니다.[" + x[0].getElementsByTagName( "Message" )[0].childNodes[0].nodeValue + "]");
  104. }
  105. }
  106. function StateChangeForJSON( xmlHttpRequest ) {
  107. var json = eval('('+ xmlHttpRequest.responseText +')');
  108. if( json.Code == '0000' ) {
  109. document.getElementById( "approval" ).value = json.approvalKey;
  110. // 아래 alert는 삭제 해도됨
  111. alert("성공적으로 거래가 등록 되었습니다.");
  112. PayUrl = json.PayUrl;
  113. document.getElementById( "PayUrl" ).value = json.request_URI;
  114. document.getElementById( "traceNo" ).value = json.traceNo;
  115. call_pay_form();
  116. } else {
  117. ajax_flag=true;
  118. alert("실패 되었습니다.[" + json.Message + "]");
  119. }
  120. }
  121. /* kcp web 결제창 호츨 (변경불가) */
  122. function call_pay_form() {
  123. var v_frm = document.order_info;
  124. if(v_frm.encoding_trans == undefined) {
  125. v_frm.action = PayUrl;
  126. } else {
  127. if(v_frm.encoding_trans.value == "UTF-8") {
  128. v_frm.action = PayUrl.substring(0, PayUrl.lastIndexOf("/")) + "/jsp/encodingFilter/encodingFilter.jsp";
  129. v_frm.payUrl.value = PayUrl;
  130. } else {
  131. v_frm.action = PayUrl;
  132. }
  133. }
  134. if (v_frm.Ret_URL.value == "") {
  135. /* Ret_URL값은 현 페이지의 URL 입니다. */
  136. alert("연동시 Ret_URL을 반드시 설정하셔야 됩니다.");
  137. return false;
  138. } else {
  139. v_frm.submit();
  140. }
  141. }
  142. /* kcp 통신을 통해 받은 암호화 정보 체크 후 결제 요청 (변경불가) */
  143. function chk_pay() {
  144. self.name = "tar_opener";
  145. var pay_form = document.pay_form;
  146. if (pay_form.res_cd.value == "3001" ) {
  147. alert("사용자가 취소하였습니다.");
  148. pay_form.res_cd.value = "";
  149. }
  150. if (pay_form.enc_info.value)
  151. pay_form.submit();
  152. }
  153. var isMobile = {
  154. Android: function() {
  155. return navigator.userAgent.match(/Android/i);
  156. },
  157. BlackBerry: function() {
  158. return navigator.userAgent.match(/BlackBerry/i);
  159. },
  160. iOS: function() {
  161. return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  162. },
  163. Opera: function() {
  164. return navigator.userAgent.match(/Opera Mini/i);
  165. },
  166. Windows: function() {
  167. return navigator.userAgent.match(/IEMobile/i);
  168. },
  169. any: function() {
  170. return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
  171. }
  172. };
  173. /*if( isMobile.any() )
  174. document.getElementById("cssLink").setAttribute("href", controlCss);*/
  175. function jsf__chk_type() {
  176. if ( document.order_info.ActionResult.value == "card" ) {
  177. document.order_info.pay_method.value = "CARD";
  178. } else if ( document.order_info.ActionResult.value == "acnt" ) {
  179. document.order_info.pay_method.value = "BANK";
  180. } else if ( document.order_info.ActionResult.value == "vcnt" ) {
  181. document.order_info.pay_method.value = "VCNT";
  182. } else if ( document.order_info.ActionResult.value == "mobx" ) {
  183. document.order_info.pay_method.value = "MOBX";
  184. }
  185. }