function successful_request_std($posted) { global $woocommerce, $inicis_payment; if (!file_exists($inicis_payment->plugin_path() . "/lib/inistd/INIStdPayUtil.php")) { $this->inicis_print_log(__('에러 : INIStdPayUtil.php 파일이 없습니다. 사이트 관리자에게 문의하여 주십시오.', 'inicis_payment'), 'INIStd'); wc_add_notice(__('에러 : INIStdPayUtil.php 파일이 없습니다. 사이트 관리자에게 문의하여 주십시오.', 'inicis_payment'), 'error'); die('<span style="color:red;font-weight:bold;">' . __('에러 : INIStdPayUtil.php 파일이 없습니다. 사이트 관리자에게 문의하여 주십시오.', 'inicis_payment') . '</span>'); } if (!file_exists($inicis_payment->plugin_path() . "/lib/inistd/HttpClient.php")) { $this->inicis_print_log(__('에러 : HttpClient.php 파일이 없습니다. 사이트 관리자에게 문의하여 주십시오.', 'inicis_payment'), 'INIStd'); wc_add_notice(__('에러 : HttpClient.php 파일이 없습니다. 사이트 관리자에게 문의하여 주십시오.', 'inicis_payment'), 'error'); die('<span style="color:red;font-weight:bold;">' . __('에러 : HttpClient.php 파일이 없습니다. 사이트 관리자에게 문의하여 주십시오.', 'inicis_payment') . '</span>'); } require_once $inicis_payment->plugin_path() . '/lib/inistd/INIStdPayUtil.php'; require_once $inicis_payment->plugin_path() . '/lib/inistd/HttpClient.php'; $util = new INIStdPayUtil(); $this->inicis_print_log(print_r($_REQUEST, true), 'INIStd'); if (isset($_REQUEST['resultCode'])) { switch ($_REQUEST['resultCode']) { case "V016": $this->inicis_print_log(__('Signkey 가 정확하지 않습니다. 관리자에게 문의하여 주세요. (invalid signkey detected)', 'inicis_payment'), 'INIStd'); wc_add_notice(__('Signkey 가 정확하지 않습니다. 관리자에게 문의하여 주세요. (invalid signkey detected)', 'inicis_payment'), 'error'); return; break; case "V013": $this->inicis_print_log(__('존재하지 않는 상점아이디 입니다. 관리자에게 문의하여 주세요. (invalid mid detected)', 'inicis_payment'), 'INIStd'); wc_add_notice(__('존재하지 않는 상점아이디 입니다. 관리자에게 문의하여 주세요. (invalid mid detected)', 'inicis_payment'), 'error'); return; break; } } if (!isset($_REQUEST['orderNumber'])) { $this->inicis_print_log(__('유효하지않은 주문입니다. 주문번호가 없습니다. (invalid notification)', 'inicis_payment'), 'INIStd'); wc_add_notice(__('유효하지않은 주문입니다. 주문번호가 없습니다. (invalid notification)', 'inicis_payment'), 'error'); return; } if (!isset($_REQUEST['merchantData'])) { $this->inicis_print_log(__('유효하지않은 주문입니다. 해시 데이터가 없습니다. (invalid notification)', 'inicis_payment'), 'INIStd'); wc_add_notice(__('유효하지않은 주문입니다. 해시 데이터가 없습니다. (invalid notification)', 'inicis_payment'), 'error'); return; } $merchantData = $_REQUEST["merchantData"]; $notification = $this->decrypt_notification($merchantData); if (empty($notification)) { $this->inicis_print_log(__('유효하지않은 주문입니다.(01xf1)', 'inicis_payment'), 'INIStd'); wc_add_notice(__('유효하지않은 주문입니다.(01xf1)', 'inicis_payment'), 'error'); return; } $txnid = $notification->txnid; $hash = $notification->hash; if (empty($txnid)) { $this->inicis_print_log(__('유효하지않은 주문입니다.(01xf2)', 'inicis_payment'), 'INIStd'); wc_add_notice(__('유효하지않은 주문입니다.(01xf2)', 'inicis_payment'), 'error'); return; } $userid = get_current_user_id(); $orderid = explode('_', $txnid); $orderid = (int) $orderid[0]; $order = new WC_Order($orderid); try { if (strcmp("0000", $_REQUEST["resultCode"]) == 0) { //성공시 이니시스로 결제 성공 전달 $mid = $_REQUEST["mid"]; $signKey = $this->settings['signkey']; $timestamp = $util->getTimestamp(); $charset = "UTF-8"; $format = "JSON"; $authToken = $_REQUEST["authToken"]; $authUrl = $_REQUEST["authUrl"]; $netCancel = $_REQUEST["netCancel"]; $ackUrl = $_REQUEST["checkAckUrl"]; $signParam["authToken"] = $authToken; // 필수 $signParam["timestamp"] = $timestamp; // 필수 $signature = $util->makeSignature($signParam); $authMap["mid"] = $mid; // 필수 $authMap["authToken"] = $authToken; // 필수 $authMap["signature"] = $signature; // 필수 $authMap["timestamp"] = $timestamp; // 필수 $authMap["charset"] = $charset; $authMap["format"] = $format; try { $httpUtil = new HttpClient(); $authResultString = ""; if ($httpUtil->processHTTP($authUrl, $authMap)) { $authResultString = $httpUtil->body; } else { $this->inicis_print_log(__('거래 서버와 통신 실패(02xf1)', 'inicis_payment'), 'INIStd'); wc_add_notice(__('거래 서버와 통신 실패(02xf1)', 'inicis_payment') . ', Error : ' . $httpUtil->errormsg, 'error'); $order->add_order_note(sprintf(__('<font color="red">거래 서버와 통신 실패(02xf1)</font>', 'inicis_payment'))); return; } $resultMap = json_decode($authResultString, true); if (strcmp("0000", $resultMap["resultCode"]) == 0) { //우커머스 내부 결제 처리 로직 시작 if (empty($order) || !is_numeric($orderid) || $order->get_order($orderid) == false) { $this->inicis_print_log(__('유효하지않은 주문입니다.(01xf3)', 'inicis_payment'), 'INIStd'); wc_add_notice(__('유효하지않은 주문입니다.(01xf3)', 'inicis_payment'), 'error'); return; } $productinfo = $this->make_product_info($order); $order_total = $this->inicis_get_order_total($order); if ($order->get_status() != 'on-hold' && $order->get_status() != 'pending' && $order->get_status() != 'failed') { $paid_result = get_post_meta($order->id, '_paid_date', true); $postmeta_txnid = get_post_meta($order->id, 'txnid', true); $postmeta_paymethod = get_post_meta($order->id, 'inicis_paymethod', true); $postmeta_tid = get_post_meta($order->id, 'inicis_paymethod_tid', true); if (empty($paid_result)) { $this->inicis_print_log(sprintf(__('<font color="red">주문요청(%s)에 대한 상태(%s)가 유효하지 않습니다.</font>', 'inicis_payment'), $txnid, __($order->get_status(), 'woocommerce')), 'INIStd'); wc_add_notice(__('주문에 따른 결제대기 시간 초과로 결제가 완료되지 않았습니다. 다시 주문을 시도 해 주세요.', 'inicis_payment'), 'error'); $order->add_order_note(sprintf(__('<font color="red">주문요청(%s)에 대한 상태(%s)가 유효하지 않습니다.</font>', 'inicis_payment'), $txnid, __($order->get_status(), 'woocommerce'))); $order->add_order_note(__('결제 승인 요청 에러 : 유효하지않은 주문입니다.', 'inicis_payment')); $order->update_status('failed'); return; } else { $this->inicis_print_log(__('이미 결제된 주문입니다.', 'inicis_payment'), 'INIStd'); wc_add_notice(__('이미 결제된 주문입니다.', 'inicis_payment'), 'error'); $order->add_order_note(sprintf(__('<font color="blue">이미 결제된 주문(%s)에 주문 요청이 접수되었습니다. 현재 주문상태 : %s</font>', 'inicis_payment'), $postmeta_txnid, __($order->get_status(), 'woocommerce'))); $order->add_order_note(sprintf(__('이미 주문이 완료되었습니다. 결제방법 : %s, 이니시스 거래번호(TID) : <a href="https://iniweb.inicis.com/app/publication/apReceipt.jsp?noMethod=1&noTid=%s" target=_blank>[영수증 확인]</a>, 몰 고유 주문번호 : %s', 'inicis_payment'), $postmeta_paymethod, $postmeta_tid, $postmeta_txnid)); return; } } if ($this->validate_txnid($order, $txnid) == false) { $this->inicis_print_log(sprintf(__('유효하지 않은 주문번호(%s) 입니다.', 'inicis_payment'), $txnid), 'INIStd'); wc_add_notice(sprintf(__('유효하지 않은 주문번호(%s) 입니다.', 'inicis_payment'), $txnid), 'error'); $order->add_order_note(sprintf(__('<font color="red">유효하지 않은 주문번호(%s) 입니다.</font>', 'inicis_payment'), $txnid)); $order->update_status('failed'); throw new Exception(sprintf(__('유효하지 않은 주문번호(%s) 입니다.', 'inicis_payment'), $txnid)); return; } $checkhash = hash('sha512', "{$this->merchant_id}|{$txnid}|{$userid}|{$order_total}|{$productinfo}|{$order->billing_first_name}|{$order->billing_email}|||||||||||"); if ($hash != $checkhash) { $this->inicis_print_log(sprintf(__('주문요청(%s)에 대한 위변조 검사 오류입니다.', 'inicis_payment'), $txnid), 'INIStd'); wc_add_notice(sprintf(__('주문요청(%s)에 대한 위변조 검사 오류입니다.', 'inicis_payment'), $txnid), 'error'); $order->add_order_note(sprintf(__('<font color="red">주문요청(%s)에 대한 위변조 검사 오류입니다.</font>', 'inicis_payment'), $txnid)); $order->update_status('failed'); throw new Exception(sprintf(__('주문요청(%s)에 대한 위변조 검사 오류입니다.', 'inicis_payment'), $txnid)); return; } //이니시스로 결제 처리 완료 통보 시작 $checkMap["mid"] = $mid; $checkMap["tid"] = $resultMap["tid"]; $checkMap["applDate"] = $resultMap["applDate"]; $checkMap["applTime"] = $resultMap["applTime"]; $checkMap["price"] = $resultMap["TotPrice"]; $checkMap["goodsName"] = $resultMap["goodsname"]; $checkMap["charset"] = $charset; $checkMap["format"] = $format; $ackResultString = ""; if ($httpUtil->processHTTP($ackUrl, $checkMap)) { $ackResultString = $httpUtil->body; } else { $this->inicis_print_log(sprintf(__('거래 서버와 통신 실패(02xf2)', 'inicis_payment'), $txnid), 'INIStd'); wc_add_notice(__('거래 서버와 통신 실패(02xf2)', 'inicis_payment') . ', Error : ' . $httpUtil->errormsg, 'error'); $order->add_order_note(sprintf(__('<font color="red">거래 서버와 통신 실패(02xf2)</font>', 'inicis_payment'))); return; } //이니시스로 결제 처리 완료 통보 종료 $ackMap = json_decode($ackResultString); //거래 성공시 //우커머스 내부 결제 처리 로직 시작 if ($resultMap["resultCode"] != "0000") { $this->inicis_print_log(sprintf(__('결제 승인 요청 과정에서 오류가 발생했습니다. 관리자에게 문의해주세요. 오류코드(%s), 오류메시지(%s)', 'inicis_payment'), esc_attr($resultMap["resultCode"]), esc_attr($resultMap["resultMsg"])), 'INIStd'); wc_add_notice(sprintf(__('결제 승인 요청 과정에서 오류가 발생했습니다. 관리자에게 문의해주세요. 오류코드(%s), 오류메시지(%s)', 'inicis_payment'), esc_attr($resultMap["resultCode"]), esc_attr($resultMap["resultMsg"])), 'error'); $order->add_order_note(sprintf(__('<font color="red">결제 승인 요청 과정에서 오류가 발생했습니다. 오류코드(%s), 오류메시지(%s)</font>', 'inicis_payment'), esc_attr($resultMap["resultCode"]), esc_attr($resultMap["resultMsg"]))); $order->update_status('failed'); return; } $inistd_txnid = $resultMap['MOID']; $inistd_orderid = explode('_', $inistd_txnid); $inistd_orderid = (int) $inistd_orderid[0]; if ($txnid != $inistd_txnid || $orderid != $inistd_orderid) { $this->inicis_print_log(sprintf(__('주문요청(%s, %s, %s, %s)에 대한 위변조 검사 오류입니다. 결재는 처리되었으나, 결재요청에 오류가 있습니다. 이니시스 결재내역을 확인하신 후, 고객에게 연락을 해주시기 바랍니다.', 'inicis_payment'), $txnid, $inistd_txnid, $orderid, $inistd_orderid), 'INIStd'); wc_add_notice(__('주문요청에 대한 위변조 검사 오류입니다. 관리자에게 문의해주세요.', 'inicis_payment'), 'error'); $order->add_order_note(sprintf(__('<font color="red">주문요청(%s, %s, %s, %s)에 대한 위변조 검사 오류입니다. 결재는 처리되었으나, 결재요청에 오류가 있습니다. 이니시스 결재내역을 확인하신 후, 고객에게 연락을 해주시기 바랍니다.</font>', 'inicis_payment'), $txnid, $inistd_txnid, $orderid, $inistd_orderid)); $order->update_status('failed'); return; } add_post_meta($orderid, "inicis_paymethod", $resultMap['payMethod']); add_post_meta($orderid, "inicis_paymethod_tid", $resultMap['tid']); $this->inicis_print_log(sprintf(__('주문이 완료되었습니다. 결제방법 : [웹표준결제] %s, 이니시스 거래번호(TID) : %s, 몰 고유 주문번호 : %s', 'inicis_payment'), $resultMap['payMethod'], $resultMap['tid'], $resultMap['MOID']), 'INIStd'); $order->add_order_note(sprintf(__('주문이 완료되었습니다. 결제방법 : [웹표준결제] %s, 이니시스 거래번호(TID) : <a href="https://iniweb.inicis.com/app/publication/apReceipt.jsp?noMethod=1&noTid=%s" target=_blank>[영수증 확인]</a>, 몰 고유 주문번호 : %s', 'inicis_payment'), $resultMap['payMethod'], $resultMap['tid'], $resultMap['MOID'])); $order->payment_complete(); $woocommerce->cart->empty_cart(); //우커머스 내부 결제 처리 로직 종료 } else { //거래 실패시 $this->inicis_print_log(sprintf(__('결제 승인 요청 과정에서 오류가 발생했습니다. 관리자에게 문의해주세요. 오류코드(%s), 오류메시지(%s)', 'inicis_payment'), esc_attr($resultMap["resultCode"]), esc_attr($resultMap["resultMsg"])), 'INIStd'); wc_add_notice(sprintf(__('결제 승인 요청 과정에서 오류가 발생했습니다. 관리자에게 문의해주세요. 오류코드(%s), 오류메시지(%s)', 'inicis_payment'), esc_attr($resultMap["resultCode"]), esc_attr($resultMap["resultMsg"])), 'error'); $order->add_order_note(sprintf(__('<font color="red">결제 승인 요청 과정에서 오류가 발생했습니다. 오류코드(%s), 오류메시지(%s)</font>', 'inicis_payment'), esc_attr($resultMap["resultCode"]), esc_attr($resultMap["resultMsg"]))); $order->update_status('failed'); return; } } catch (Exception $e) { $msg = "Error"; $this->inicis_print_log(sprintf(__('결제 승인 요청 에러 : 예외처리 에러 ( %s )', 'inicis_payment'), $e->getMessage()), 'INIStd'); $order->add_order_note(sprintf(__('결제 승인 요청 에러 : 예외처리 에러 ( %s )', 'inicis_payment'), $e->getMessage())); $order->update_status('failed'); //망취소 처리 $netcancelResultString = ""; if ($httpUtil->processHTTP($netCancel, $authMap)) { $netcancelResultString = $httpUtil->body; } else { $this->inicis_print_log(__('거래 서버와 통신 실패(02xf3)', 'inicis_payment') . ', Error : ' . $httpUtil->errormsg, 'INIStd'); wc_add_notice(__('거래 서버와 통신 실패(02xf3)', 'inicis_payment') . ', Error : ' . $httpUtil->errormsg, 'error'); $order->add_order_note(sprintf(__('<font color="red">거래 서버와 통신 실패(02xf3)</font>', 'inicis_payment'))); return; } $netcancelResultString = str_replace("<", "<", ${$netcancelResultString}); $netcancelResultString = str_replace(">", ">", ${$netcancelResultString}); $resultMap = json_decode($netcancelResultString, true); $this->inicis_print_log(sprintf(__('망취소 처리 결과 : %s', 'inicis_payment'), print_r($resultMap, true)), 'INIStd'); $order->add_order_note(sprintf(__('망취소 처리 결과 : %s', 'inicis_payment'), print_r($resultMap, true))); } } else { //실패시 $this->inicis_print_log(sprintf(__('결제 승인 요청 과정에서 오류가 발생했습니다. 관리자에게 문의해주세요. 오류코드(%s), 오류메시지(%s)', 'inicis_payment'), esc_attr($_REQUEST["resultCode"]), esc_attr($_REQUEST["resultMsg"])), 'INIStd'); wc_add_notice(sprintf(__('결제 승인 요청 과정에서 오류가 발생했습니다. 관리자에게 문의해주세요. 오류코드(%s), 오류메시지(%s)', 'inicis_payment'), esc_attr($_REQUEST["resultCode"]), esc_attr($_REQUEST["resultMsg"])), 'error'); $order->add_order_note(sprintf(__('<font color="red">결제 승인 요청 과정에서 오류가 발생했습니다. 오류코드(%s), 오류메시지(%s)</font>', 'inicis_payment'), esc_attr($_REQUEST["resultCode"]), esc_attr($_REQUEST["resultMsg"]))); $order->update_status('failed'); return; } } catch (Exception $e) { $msg = "Error"; $this->inicis_print_log(sprintf(__('결제 승인 요청 에러 : 예외처리 에러 ( %s )', 'inicis_payment'), $e->getMessage()), 'INIStd'); $order->add_order_note(sprintf(__('결제 승인 요청 에러 : 예외처리 에러 ( %s )', 'inicis_payment'), $e->getMessage())); $order->update_status('failed'); } }
/** *@brief 결제 처리 **/ function procInipaystandardDoIt() { if (!$_SESSION['inipaystandard']['transaction_srl']) { return new Object(-1, 'msg_invalid_request'); } $vars = Context::getRequestVars(); $oEpayController = getController('epay'); //결제 실패시 if (strcmp("0000", $vars->resultCode) !== 0) { /* $payArgs = new Object(-1, $resultMap["resultMsg"]); $payArgs->add('transaction_srl', $_SESSION['inipaystandard']['transaction_srl']); $payArgs->add('state', '3'); $payArgs->add('result_code', $vars->resultCode); $payArgs->add('result_message', $vars->resultMsg); $output = $oEpayController->afterPayment($payArgs); if(!$output->toBool()) return $output; */ return new Object(-1, '결제가 취소되었습니다.'); /* $return_url = substr(Context::getRequestUri() , 0, -1) . $_SESSION['inipaystandard']['error_return_url']; unset($_SESSION['inipaystandard']); header('location:' . $return_url); */ } else { if (!$vars->authUrl || !$vars->authToken) { return new Object(-1, 'msg_invalid_request'); } } $vars->transaction_srl = $_SESSION['inipaystandard']['transaction_srl']; $output = $oEpayController->beforePayment($vars); if (!$output->toBool()) { return $output; } require_once 'libs/INIStdPayUtil.php'; require_once 'libs/HttpClient.php'; $util = new INIStdPayUtil(); $httpUtil = new HttpClient(); $timestamp = $util->getTimestamp(); $signParam = array(); $signParam["authToken"] = $vars->authToken; $signParam["timestamp"] = $timestamp; $signature = $util->makeSignature($signParam); $authMap = array(); $authMap["mid"] = $this->module_info->inipay_mid; $authMap["authToken"] = $vars->authToken; $authMap["signature"] = $signature; $authMap["timestamp"] = $timestamp; $authMap["charset"] = 'UTF-8'; $authMap["format"] = 'JSON'; $authMap["price"] = $_SESSION['inipaystandard']['price']; //결제 인증 $authResultString = ''; if ($httpUtil->processHTTP($vars->authUrl, $authMap)) { $authResultString = $httpUtil->body; } else { echo "Http Connect Error\n"; echo $httpUtil->errormsg; throw new Exception("Http Connect Error"); } //인증 결과 $resultMap = json_decode($authResultString, true); //성공 if (strcmp("0000", $resultMap["resultCode"]) == 0) { $payArgs = new Object(0, $resultMap["resultMsg"]); //가상계좌 if ($this->getPaymethod($resultMap["payMethod"]) == 'VA') { $payArgs->add('state', '1'); } else { $payArgs->add('state', '2'); } } else { $payArgs = new Object(-1, $resultMap["resultMsg"]); $payArgs->add('state', '3'); } $payArgs->add('transaction_srl', $_SESSION['inipaystandard']['transaction_srl']); $payArgs->add('payment_method', $this->getPaymethod($resultMap["payMethod"])); $payArgs->add('payment_amount', $resultMap["TotPrice"]); $payArgs->add('result_code', $resultMap["resultCode"]); $payArgs->add('result_message', $resultMap["resultMsg"]); $payArgs->add('pg_tid', $resultMap["tid"]); //가상계좌 if ($this->getPaymethod($resultMap["payMethod"]) == 'VA') { $payArgs->add('vact_num', $resultMap["VACT_Num"]); $payArgs->add('vact_bankname', $this->getBankName($resultMap["VACT_BankCode"])); $payArgs->add('vact_bankcode', $resultMap["VACT_BankCode"]); $payArgs->add('vact_name', $resultMap["VACT_Name"]); $payArgs->add('vact_inputname', $resultMap["VACT_InputName"]); $payArgs->add('vact_date', $resultMap["VACT_Date"]); $payArgs->add('vact_time', $resultMap["VACT_Time"]); } $output = $oEpayController->afterPayment($payArgs); if (!$output->toBool()) { //DB 에러시 결제 취소 if (!$httpUtil->processHTTP($vars->netCancel, $authMap)) { echo "Http Connect Error\n"; echo $httpUtil->errormsg; throw new Exception("Http Connect Error"); } return $output; } $return_url = $output->get('return_url'); if ($return_url) { $this->setRedirectUrl($return_url); } unset($_SESSION['inipaystandard']); }
$authMap["charset"] = $charset; // default=UTF-8 $authMap["format"] = $format; // default=XML $authMap["price"] = $price; // 필수 (가격위변조체크기능) //if(null != notiUrl && notiUrl.length() > 0){ // authMap.put("notiUrl" ,notiUrl); //} try { $httpUtil = new HttpClient(); //##################### // 4.API 통신 시작 //##################### $authResultString = ""; if ($httpUtil->processHTTP($authUrl, $authMap)) { $authResultString = $httpUtil->body; } else { echo "Http Connect Error\n"; echo $httpUtil->errormsg; throw new Exception("Http Connect Error"); } //############################################################ //5.API 통신결과 처리(***가맹점 개발수정***) //############################################################ echo "## 승인 API 결과 ##"; $resultMap = json_decode($authResultString, true); if (strcmp("0000", $resultMap["resultCode"]) == 0) { /* * *************************************************************************** * 여기에 가맹점 내부 DB에 결제 결과를 반영하는 관련 프로그램 코드를 구현한다.