diff --git a/adm/shop_admin/orderform.php b/adm/shop_admin/orderform.php
index 78282f211..72df6964e 100644
--- a/adm/shop_admin/orderform.php
+++ b/adm/shop_admin/orderform.php
@@ -113,6 +113,111 @@ if ($od['od_pg'] === 'nicepay' && $od['od_settle_case'] === '가상계좌' && $o
$print_od_deposit_name .= '_NICE';
}
+if (!function_exists('shop_admin_get_nicepay_status')) {
+ function shop_admin_get_nicepay_status($tid, $default)
+ {
+ $result = array(
+ 'data' => array(),
+ 'error' => ''
+ );
+
+ if (!function_exists('curl_init')) {
+ $result['error'] = 'cURL 모듈이 설치되어 있지 않아 나이스페이 거래 상태를 조회할 수 없습니다.';
+ return $result;
+ }
+
+ $tid = preg_replace('/[^0-9a-zA-Z]/', '', (string) $tid);
+ if ($tid === '') {
+ $result['error'] = '거래 ID가 없어 나이스페이 거래 상태를 조회할 수 없습니다.';
+ return $result;
+ }
+
+ if (!empty($default['de_card_test'])) {
+ $mid = 'nicepay00m';
+ $merchantKey = 'EYzu8jGGMfqaDEp76gSckuvnaHHu+bC4opsSN6lHv3b2lurNYkVXrZ7Z1AoqQnXI3eLuaUFyoRNC6FkrzVjceg==';
+ } else {
+ $mid = 'SR'.$default['de_nicepay_mid'];
+ $merchantKey = $default['de_nicepay_key'];
+ }
+
+ if ($mid === 'SR' || $merchantKey === '') {
+ $result['error'] = '나이스페이 MID 또는 KEY가 설정되어 있지 않아 거래 상태를 조회할 수 없습니다.';
+ return $result;
+ }
+
+ $ediDate = preg_replace('/[^0-9]/', '', G5_TIME_YMDHIS);
+ $signData = bin2hex(hash('sha256', $tid.$mid.$ediDate.$merchantKey, true));
+ $postUrl = 'https://webapi.nicepay.co.kr/webapi/inquery/trans_status.jsp';
+ $data = array(
+ 'TID' => $tid,
+ 'MID' => $mid,
+ 'EdiDate' => $ediDate,
+ 'SignData' => $signData,
+ 'CharSet' => 'utf-8',
+ 'EdiType' => 'JSON'
+ );
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $postUrl);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 25);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+ curl_setopt($ch, CURLOPT_POST, true);
+ $response = curl_exec($ch);
+ $curl_error = curl_error($ch);
+ curl_close($ch);
+
+ if ($response === false || $response === '') {
+ $result['error'] = '나이스페이 거래 상태 조회 응답이 없습니다.'.($curl_error ? ' '.$curl_error : '');
+ return $result;
+ }
+
+ $responseData = json_decode($response, true);
+ if (!is_array($responseData)) {
+ $utf8_response = @iconv('EUC-KR', 'UTF-8//IGNORE', $response);
+ if ($utf8_response) {
+ $responseData = json_decode($utf8_response, true);
+ }
+ }
+
+ if (!is_array($responseData)) {
+ $result['error'] = '나이스페이 거래 상태 조회 응답을 해석할 수 없습니다.';
+ return $result;
+ }
+
+ $result['data'] = $responseData;
+ return $result;
+ }
+}
+
+if (!function_exists('shop_admin_format_nicepay_auth_date')) {
+ function shop_admin_format_nicepay_auth_date($auth_date)
+ {
+ $auth_date = preg_replace('/[^0-9]/', '', (string) $auth_date);
+
+ if (strlen($auth_date) === 12) {
+ return '20'.substr($auth_date, 0, 2).'-'.substr($auth_date, 2, 2).'-'.substr($auth_date, 4, 2).' '.substr($auth_date, 6, 2).':'.substr($auth_date, 8, 2).':'.substr($auth_date, 10, 2);
+ }
+
+ if (strlen($auth_date) === 14) {
+ return substr($auth_date, 0, 4).'-'.substr($auth_date, 4, 2).'-'.substr($auth_date, 6, 2).' '.substr($auth_date, 8, 2).':'.substr($auth_date, 10, 2).':'.substr($auth_date, 12, 2);
+ }
+
+ return $auth_date;
+ }
+}
+
+$nicepay_status_result = array();
+$nicepay_status_error = '';
+if ($od['od_pg'] === 'nicepay') {
+ $nicepay_status = shop_admin_get_nicepay_status($od['od_tno'], $default);
+ $nicepay_status_result = $nicepay_status['data'];
+ $nicepay_status_error = $nicepay_status['error'];
+}
+
// add_javascript('js 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_javascript(G5_POSTCODE_JS, 0); //다음 주소 js
?>
@@ -311,6 +416,52 @@ add_javascript(G5_POSTCODE_JS, 0); //다음 주소 js
} //end if
?>
+
+
+ 나이스페이 결제 조회
+
+
+ '승인 상태',
+ '1' => '취소 상태',
+ '9' => '승인 거래 없음'
+ );
+ $nicepay_status_code = isset($nicepay_status_result['Status']) ? (string) $nicepay_status_result['Status'] : '';
+ $nicepay_status_text = isset($nicepay_status_map[$nicepay_status_code]) ? $nicepay_status_map[$nicepay_status_code] : '';
+ $nicepay_auth_date = isset($nicepay_status_result['AuthDate']) ? shop_admin_format_nicepay_auth_date($nicepay_status_result['AuthDate']) : '';
+ ?>
+
+
+ 나이스페이 결제 조회
+
+
+ | 결과코드 |
+ 결과 메시지 |
+ 거래 ID |
+ 거래 상태 |
+ 승인번호 |
+ 승인일시 |
+
+
+
+
+ |
+ |
+ |
+ |
+ |
+ |
+
+
+
+
+
+
+
+