KG이니시스 INIpay PRO 결제 연동 및 결제 처리 현황 추가
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1f48f6bd80
commit
acdbcfd8ba
38 files changed
+4506
-87
No files matched your search
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
include_once('../../../common.php');
|
||||
|
||||
if (!defined('G5_USE_SHOP') || !G5_USE_SHOP)
|
||||
die('<p>쇼핑몰 설치 후 이용해 주십시오.</p>');
|
||||
|
||||
define('_SHOP_', true);
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// 웹 요청으로는 실행하지 않고 서버 작업 스케줄러의 PHP CLI에서만 실행한다.
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
if (!headers_sent())
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!defined('G5_SET_TIME_LIMIT'))
|
||||
define('G5_SET_TIME_LIMIT', 120);
|
||||
|
||||
$root_path = dirname(dirname(dirname(dirname(__FILE__))));
|
||||
$monitor_host = 'localhost';
|
||||
$monitor_https = false;
|
||||
$monitor_client_ip = '';
|
||||
$monitor_no_external = false;
|
||||
if (isset($argv) && is_array($argv)) {
|
||||
foreach ($argv as $argument) {
|
||||
if (preg_match('/^--host=([A-Za-z0-9.-]+)(:[0-9]+)?$/', $argument, $matches))
|
||||
$monitor_host = $matches[1].(isset($matches[2]) ? $matches[2] : '');
|
||||
elseif ($argument === '--https')
|
||||
$monitor_https = true;
|
||||
elseif (preg_match('/^--client-ip=([0-9.]+)$/', $argument, $matches) && ip2long($matches[1]) !== false)
|
||||
$monitor_client_ip = $matches[1];
|
||||
elseif ($argument === '--no-external')
|
||||
$monitor_no_external = true;
|
||||
}
|
||||
}
|
||||
$_SERVER['HTTP_HOST'] = $monitor_host;
|
||||
$_SERVER['SERVER_NAME'] = $monitor_host;
|
||||
$_SERVER['SERVER_PORT'] = $monitor_https ? '443' : '80';
|
||||
if ($monitor_https)
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
$_SERVER['REQUEST_URI'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
|
||||
$_SERVER['SCRIPT_NAME'] = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : '/shop/inicis/pro/monitor.php';
|
||||
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['SERVER_ADDR'] = $monitor_client_ip !== '' ? $monitor_client_ip : (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1');
|
||||
|
||||
chdir($root_path);
|
||||
include_once($root_path.'/common.php');
|
||||
include_once(G5_SHOP_PATH.'/inicis/pro/inicis_pro.lib.php');
|
||||
include_once(G5_ADMIN_PATH.'/shop_admin/admin.shop.lib.php');
|
||||
|
||||
if ($monitor_no_external) {
|
||||
$default['de_inicis_pro_reconcile_use'] = 0;
|
||||
$default['de_inicis_pro_alert_use'] = 0;
|
||||
}
|
||||
|
||||
if (!inicis_pro_is_enabled()) {
|
||||
echo "INIpay PRO is disabled.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$monitor_ran = check_order_inicis_pro_payments();
|
||||
if (!$monitor_ran) {
|
||||
echo "INIpay PRO monitor is already running.\n";
|
||||
exit;
|
||||
}
|
||||
$monitor = sql_fetch(" select de_inicis_pro_monitor_at, de_inicis_pro_monitor_message from {$g5['g5_shop_default_table']} limit 1 ", false);
|
||||
echo (!empty($monitor['de_inicis_pro_monitor_at']) ? $monitor['de_inicis_pro_monitor_at'].' ' : '').(!empty($monitor['de_inicis_pro_monitor_message']) ? $monitor['de_inicis_pro_monitor_message'] : 'monitor completed')."\n";
|
||||
@@ -0,0 +1,411 @@
|
||||
<?php
|
||||
include_once('./_common.php');
|
||||
include_once(G5_SHOP_PATH.'/inicis/pro/inicis_pro.lib.php');
|
||||
|
||||
@header('Content-Type: text/plain; charset=UTF-8');
|
||||
@header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
|
||||
if (!function_exists('inicis_pro_noti_result')) {
|
||||
function inicis_pro_noti_result($success, $lock_name)
|
||||
{
|
||||
inicis_pro_unlock($lock_name);
|
||||
echo $success ? 'OK' : 'FAIL';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('inicis_pro_noti_fail')) {
|
||||
function inicis_pro_noti_fail($code, $oid, $lock_name)
|
||||
{
|
||||
$oid = inicis_pro_clean_oid($oid);
|
||||
if ($oid !== '') {
|
||||
inicis_pro_audit_write($oid, 'notification', 'notification_failed', array(
|
||||
'event_only' => '1',
|
||||
'source' => 'server',
|
||||
'device' => 'SERVER',
|
||||
'remote_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '',
|
||||
'code' => $code,
|
||||
'message' => '가상계좌 통보 검증 실패'
|
||||
));
|
||||
}
|
||||
|
||||
inicis_pro_noti_result(false, $lock_name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('inicis_pro_noti_time')) {
|
||||
function inicis_pro_noti_time($auth_date)
|
||||
{
|
||||
$auth_date = preg_replace('/[^0-9]/', '', (string) $auth_date);
|
||||
if (strlen($auth_date) === 12)
|
||||
$auth_date = '20'.$auth_date;
|
||||
if (strlen($auth_date) !== 14)
|
||||
return '';
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('inicis_pro_noti_saved_device')) {
|
||||
function inicis_pro_noti_saved_device($noti, $pro_log, $pro_data)
|
||||
{
|
||||
if (!isset($pro_log['P_STATUS']) || $pro_log['P_STATUS'] !== '00'
|
||||
|| empty($pro_data['__pro']) || $pro_data['__pro'] !== '1'
|
||||
|| !isset($pro_data['P_NOTI']) || !inicis_pro_equals($pro_data['P_NOTI'], $noti))
|
||||
return '';
|
||||
|
||||
$device = isset($pro_data['__device']) ? strtoupper((string) $pro_data['__device']) : '';
|
||||
|
||||
return in_array($device, array('WEB', 'MOBILE'), true) ? $device : '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('inicis_pro_noti_approved_payment_exists')) {
|
||||
function inicis_pro_noti_approved_payment_exists($oid, $tid, $mid, $amount, $pay_type, $pro_log, $pro_data)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
if (!isset($pro_log['P_STATUS']) || $pro_log['P_STATUS'] !== '00'
|
||||
|| empty($pro_data['__pro']) || $pro_data['__pro'] !== '1'
|
||||
|| !isset($pro_data['P_MID']) || $pro_data['P_MID'] !== $mid
|
||||
|| !isset($pro_data['P_OID']) || $pro_data['P_OID'] !== $oid
|
||||
|| !isset($pro_data['P_AMT']) || (int) $pro_data['P_AMT'] !== $amount
|
||||
|| !isset($pro_data['P_TYPE']) || strtoupper($pro_data['P_TYPE']) !== $pay_type
|
||||
|| !isset($pro_data['P_APPL_TID']) || inicis_pro_clean_tid($pro_data['P_APPL_TID']) !== $tid
|
||||
|| $pro_data['P_APPL_TID'] !== $tid)
|
||||
return false;
|
||||
|
||||
$oid_sql = sql_escape_string($oid);
|
||||
$tid_sql = sql_escape_string($tid);
|
||||
$order = sql_fetch(" select od_id, od_receipt_price
|
||||
from {$g5['g5_shop_order_table']}
|
||||
where od_id = '$oid_sql'
|
||||
and od_tno = '$tid_sql'
|
||||
and od_pg = 'inicis' ");
|
||||
if (!empty($order['od_id']) && (int) $order['od_receipt_price'] === $amount)
|
||||
return true;
|
||||
|
||||
$personal = sql_fetch(" select pp_id, pp_receipt_price
|
||||
from {$g5['g5_shop_personalpay_table']}
|
||||
where pp_id = '$oid_sql'
|
||||
and pp_tno = '$tid_sql'
|
||||
and pp_pg = 'inicis'
|
||||
and pp_use = '1' ");
|
||||
|
||||
return !empty($personal['pp_id']) && (int) $personal['pp_receipt_price'] === $amount;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('inicis_pro_noti_save_audit')) {
|
||||
function inicis_pro_noti_save_audit($oid, $status, $auth_date, $remote_ip, $payment_status, $payment_message)
|
||||
{
|
||||
$log = inicis_pro_get_log($oid);
|
||||
$data = isset($log['pro_data']) && is_array($log['pro_data']) ? $log['pro_data'] : array();
|
||||
if (empty($data['__pro']) || $data['__pro'] !== '1')
|
||||
return false;
|
||||
|
||||
$data['__noti_status'] = $status;
|
||||
$data['__noti_auth_dt'] = preg_replace('/[^0-9]/', '', (string) $auth_date);
|
||||
$data['__noti_received_at'] = G5_TIME_YMDHIS;
|
||||
$data['__noti_ip'] = $remote_ip;
|
||||
if (!empty($_POST['P_IN_TID']))
|
||||
$data['P_IN_TID'] = inicis_pro_clean_tid($_POST['P_IN_TID']);
|
||||
|
||||
$saved = inicis_pro_save_log($data);
|
||||
$audit_saved = false;
|
||||
if ($saved) {
|
||||
$audit_saved = inicis_pro_audit_write($oid, 'notification', $payment_status, array(
|
||||
'tid' => isset($data['P_APPL_TID']) ? $data['P_APPL_TID'] : '',
|
||||
'auth_tid' => isset($data['P_AUTH_TID']) ? $data['P_AUTH_TID'] : '',
|
||||
'mid' => isset($data['P_MID']) ? $data['P_MID'] : '',
|
||||
'amount' => isset($data['P_AMT']) ? (int) $data['P_AMT'] : 0,
|
||||
'pay_type' => 'VBANK',
|
||||
'device' => 'SERVER',
|
||||
'source' => 'server',
|
||||
'remote_ip' => $remote_ip,
|
||||
'code' => $status,
|
||||
'refund_required' => $payment_status === 'paid_after_cancel' ? '1' : '',
|
||||
'message' => $payment_message
|
||||
));
|
||||
}
|
||||
|
||||
return $saved && $audit_saved;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'POST')
|
||||
inicis_pro_noti_result(false, '');
|
||||
|
||||
$remote_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
|
||||
$allowed_ips = inicis_pro_noti_allowed_ips();
|
||||
if (!in_array($remote_ip, $allowed_ips, true))
|
||||
inicis_pro_noti_result(false, '');
|
||||
|
||||
$status = isset($_POST['P_STATUS']) ? trim((string) $_POST['P_STATUS']) : '';
|
||||
$mid = isset($_POST['P_MID']) ? trim((string) $_POST['P_MID']) : '';
|
||||
$oid_raw = isset($_POST['P_OID']) ? trim((string) $_POST['P_OID']) : '';
|
||||
$oid = inicis_pro_clean_oid($oid_raw);
|
||||
$tid_raw = isset($_POST['P_TID']) ? trim((string) $_POST['P_TID']) : '';
|
||||
$tid = inicis_pro_clean_tid($tid_raw);
|
||||
$amount_raw = isset($_POST['P_AMT']) ? trim((string) $_POST['P_AMT']) : '';
|
||||
$pay_type = isset($_POST['P_TYPE']) ? strtoupper(trim((string) $_POST['P_TYPE'])) : '';
|
||||
$noti = isset($_POST['P_NOTI']) ? trim((string) $_POST['P_NOTI']) : '';
|
||||
$auth_date = isset($_POST['P_AUTH_DT']) ? $_POST['P_AUTH_DT'] : '';
|
||||
$hashkey = inicis_pro_get_hashkey($pay_type);
|
||||
$amount = preg_match('/^[0-9]+$/', $amount_raw) ? (int) $amount_raw : 0;
|
||||
$pro_log = array();
|
||||
$pro_data = array();
|
||||
if ($oid !== '' && $oid === $oid_raw) {
|
||||
$pro_log = inicis_pro_get_log($oid);
|
||||
$pro_data = isset($pro_log['pro_data']) && is_array($pro_log['pro_data']) ? $pro_log['pro_data'] : array();
|
||||
}
|
||||
|
||||
$expected_mid = inicis_pro_get_mid($pay_type);
|
||||
if (isset($pro_log['P_STATUS']) && $pro_log['P_STATUS'] === '00'
|
||||
&& !empty($pro_data['__pro']) && $pro_data['__pro'] === '1' && !empty($pro_data['P_MID']))
|
||||
$expected_mid = trim((string) $pro_data['P_MID']);
|
||||
|
||||
if ($mid === '')
|
||||
inicis_pro_noti_fail('MID_EMPTY', $oid, '');
|
||||
if ($mid !== $expected_mid)
|
||||
inicis_pro_noti_fail('MID_MISMATCH', $oid, '');
|
||||
if ($oid === '' || $oid !== $oid_raw)
|
||||
inicis_pro_noti_fail('OID_INVALID', $oid, '');
|
||||
if ($tid === '' || $tid !== $tid_raw)
|
||||
inicis_pro_noti_fail('TID_INVALID', $oid, '');
|
||||
if ($amount <= 0)
|
||||
inicis_pro_noti_fail('AMOUNT_INVALID', $oid, '');
|
||||
if ($pay_type === '' || !preg_match('/^[A-Z0-9_]+$/', $pay_type))
|
||||
inicis_pro_noti_fail('TYPE_INVALID', $oid, '');
|
||||
|
||||
$device = inicis_pro_noti_saved_device($noti, $pro_log, $pro_data);
|
||||
if ($device === '' && $hashkey !== '')
|
||||
$device = inicis_pro_check_noti($noti, $oid, $amount, $hashkey);
|
||||
if ($device === '' && $hashkey === '')
|
||||
inicis_pro_noti_fail('HASHKEY_EMPTY', $oid, '');
|
||||
if ($device === '')
|
||||
inicis_pro_noti_fail('NOTI_SIGNATURE_INVALID', $oid, '');
|
||||
|
||||
// 과거 요청에서 모든 결제수단에 통보 URL을 전달한 경우 카드 등 승인 통보도
|
||||
// 이 URL로 재전송된다. 이미 승인과 주문 저장이 끝난 동일 거래는 변경 없이 확인한다.
|
||||
if ($pay_type !== 'VBANK') {
|
||||
if ($status !== '00')
|
||||
inicis_pro_noti_fail('NON_VBANK_STATUS_INVALID', $oid, '');
|
||||
if (!inicis_pro_noti_approved_payment_exists($oid, $tid, $mid, $amount, $pay_type, $pro_log, $pro_data))
|
||||
inicis_pro_noti_fail('NON_VBANK_ORDER_MISMATCH', $oid, '');
|
||||
|
||||
inicis_pro_audit_write($oid, 'notification', 'notification_acknowledged', array(
|
||||
'event_only' => '1',
|
||||
'tid' => $tid,
|
||||
'mid' => $mid,
|
||||
'amount' => $amount,
|
||||
'pay_type' => $pay_type,
|
||||
'device' => 'SERVER',
|
||||
'source' => 'server',
|
||||
'remote_ip' => $remote_ip,
|
||||
'code' => $status,
|
||||
'message' => '이미 처리된 결제의 서버 통보 확인'
|
||||
));
|
||||
inicis_pro_noti_result(true, '');
|
||||
}
|
||||
|
||||
// 가상계좌 채번 통보는 브라우저 승인 처리와 경쟁시키지 않고 확인 응답만 한다.
|
||||
if ($status === '00') {
|
||||
$issued_saved = inicis_pro_audit_write($oid, 'notification', 'vbank_issued', array(
|
||||
'tid' => $tid,
|
||||
'mid' => $mid,
|
||||
'amount' => $amount,
|
||||
'pay_type' => 'VBANK',
|
||||
'device' => 'SERVER',
|
||||
'source' => 'server',
|
||||
'remote_ip' => $remote_ip,
|
||||
'code' => $status,
|
||||
'vbank_due_at' => !empty($pro_data['P_VACT_DATE'])
|
||||
? substr($pro_data['P_VACT_DATE'], 0, 4).'-'.substr($pro_data['P_VACT_DATE'], 4, 2).'-'.substr($pro_data['P_VACT_DATE'], 6, 2).' '
|
||||
.(!empty($pro_data['P_VACT_TIME']) ? substr($pro_data['P_VACT_TIME'].'000000', 0, 2).':'.substr($pro_data['P_VACT_TIME'].'000000', 2, 2).':'.substr($pro_data['P_VACT_TIME'].'000000', 4, 2) : '23:59:00')
|
||||
: '',
|
||||
'message' => '가상계좌 발급 통보 수신'
|
||||
));
|
||||
inicis_pro_noti_result($issued_saved, '');
|
||||
}
|
||||
if ($status !== '02')
|
||||
inicis_pro_noti_fail('STATUS_UNSUPPORTED', $oid, '');
|
||||
|
||||
$in_tid_raw = isset($_POST['P_IN_TID']) ? trim((string) $_POST['P_IN_TID']) : '';
|
||||
$in_tid = inicis_pro_clean_tid($in_tid_raw);
|
||||
// 상점관리자의 입금통보 테스트 등에서는 P_IN_TID가 빈 값으로 올 수 있다.
|
||||
// 주문 식별에는 채번 TID(P_TID)를 사용하고, 입금 TID는 전달된 경우에만 형식을 검증한다.
|
||||
if ($in_tid_raw !== '' && ($in_tid === '' || $in_tid !== $in_tid_raw))
|
||||
inicis_pro_noti_fail('IN_TID_FORMAT_INVALID', $oid, '');
|
||||
|
||||
$receipt_time = inicis_pro_noti_time($auth_date);
|
||||
if ($receipt_time === '')
|
||||
inicis_pro_noti_fail('AUTH_TIME_INVALID', $oid, '');
|
||||
|
||||
$lock_name = inicis_pro_lock($oid);
|
||||
if ($lock_name === '')
|
||||
inicis_pro_noti_fail('LOCK_BUSY', $oid, '');
|
||||
|
||||
$approved_tid = isset($pro_data['P_APPL_TID']) ? inicis_pro_clean_tid($pro_data['P_APPL_TID']) : '';
|
||||
if (empty($pro_data['__pro']) || $pro_data['__pro'] !== '1')
|
||||
inicis_pro_noti_fail('APPROVAL_LOG_INVALID', $oid, $lock_name);
|
||||
if (!isset($pro_log['P_STATUS']) || $pro_log['P_STATUS'] !== '00')
|
||||
inicis_pro_noti_fail('APPROVAL_STATUS_INVALID', $oid, $lock_name);
|
||||
if (!isset($pro_data['P_MID']) || $pro_data['P_MID'] !== $mid)
|
||||
inicis_pro_noti_fail('APPROVAL_MID_MISMATCH', $oid, $lock_name);
|
||||
if (!isset($pro_data['P_OID']) || $pro_data['P_OID'] !== $oid)
|
||||
inicis_pro_noti_fail('APPROVAL_OID_MISMATCH', $oid, $lock_name);
|
||||
if (!isset($pro_data['P_AMT']) || (int) $pro_data['P_AMT'] !== $amount)
|
||||
inicis_pro_noti_fail('APPROVAL_AMOUNT_MISMATCH', $oid, $lock_name);
|
||||
if (!isset($pro_data['P_TYPE']) || strtoupper($pro_data['P_TYPE']) !== 'VBANK')
|
||||
inicis_pro_noti_fail('APPROVAL_TYPE_MISMATCH', $oid, $lock_name);
|
||||
if ($approved_tid !== $tid)
|
||||
inicis_pro_noti_fail('APPROVAL_TID_MISMATCH', $oid, $lock_name);
|
||||
|
||||
// 환불 완료 후 동일 입금통보가 재전송되면 환불 필요 상태를 다시 만들지 않는다.
|
||||
$audit_tables = inicis_pro_audit_tables();
|
||||
$completed_refund = sql_fetch(" select ip_status, ip_refund_required, ip_tid, ip_amount
|
||||
from `{$audit_tables['summary']}`
|
||||
where ip_oid = '".sql_escape_string($oid)."' ", false);
|
||||
if (!empty($completed_refund['ip_status']) && $completed_refund['ip_status'] === 'refund_completed'
|
||||
&& empty($completed_refund['ip_refund_required'])
|
||||
&& $completed_refund['ip_tid'] === $tid && (int) $completed_refund['ip_amount'] === $amount) {
|
||||
$acknowledged = inicis_pro_audit_write($oid, 'notification', 'notification_acknowledged', array(
|
||||
'event_only' => '1',
|
||||
'tid' => $tid,
|
||||
'mid' => $mid,
|
||||
'amount' => $amount,
|
||||
'pay_type' => 'VBANK',
|
||||
'device' => 'SERVER',
|
||||
'source' => 'server',
|
||||
'remote_ip' => $remote_ip,
|
||||
'code' => $status,
|
||||
'message' => '환불 완료 거래의 중복 입금 통보 확인'
|
||||
));
|
||||
inicis_pro_noti_result($acknowledged, $lock_name);
|
||||
}
|
||||
|
||||
$received_saved = inicis_pro_audit_write($oid, 'notification', 'notification_received', array(
|
||||
'tid' => $tid,
|
||||
'auth_tid' => isset($pro_data['P_AUTH_TID']) ? $pro_data['P_AUTH_TID'] : '',
|
||||
'mid' => $mid,
|
||||
'amount' => $amount,
|
||||
'pay_type' => 'VBANK',
|
||||
'device' => 'SERVER',
|
||||
'order_type' => !empty($pro_data['__order_type']) ? $pro_data['__order_type'] : '',
|
||||
'source' => 'server',
|
||||
'remote_ip' => $remote_ip,
|
||||
'code' => $status,
|
||||
'message' => '가상계좌 입금 통보 수신'
|
||||
));
|
||||
if (!$received_saved)
|
||||
inicis_pro_noti_fail('AUDIT_SUMMARY_FAILED', $oid, $lock_name);
|
||||
|
||||
$oid_sql = sql_escape_string($oid);
|
||||
$tid_sql = sql_escape_string($tid);
|
||||
$time_sql = sql_escape_string($receipt_time);
|
||||
$personal = sql_fetch(" select * from {$g5['g5_shop_personalpay_table']}
|
||||
where pp_id = '$oid_sql'
|
||||
and pp_tno = '$tid_sql'
|
||||
and pp_pg = 'inicis'
|
||||
and pp_settle_case = '가상계좌'
|
||||
and pp_use = '1' ");
|
||||
|
||||
if (!empty($personal['pp_id'])) {
|
||||
if ((int) $personal['pp_price'] !== $amount
|
||||
|| ((int) $personal['pp_receipt_price'] !== 0 && (int) $personal['pp_receipt_price'] !== $amount))
|
||||
inicis_pro_noti_fail('PERSONAL_AMOUNT_MISMATCH', $oid, $lock_name);
|
||||
|
||||
// 연결 주문은 메모의 고유 표식으로 중복 가산을 막는다.
|
||||
if (!empty($personal['od_id'])) {
|
||||
$linked_id = inicis_pro_clean_oid($personal['od_id']);
|
||||
$linked = sql_fetch(" select od_id, od_status, od_cancel_price, od_shop_memo from {$g5['g5_shop_order_table']} where od_id = '".sql_escape_string($linked_id)."' ");
|
||||
if (empty($linked['od_id']))
|
||||
inicis_pro_noti_fail('LINKED_ORDER_MISSING', $oid, $lock_name);
|
||||
if ($linked['od_status'] === '취소' || (int) $linked['od_cancel_price'] > 0) {
|
||||
$processed = inicis_pro_noti_save_audit($oid, $status, $auth_date, $remote_ip, 'paid_after_cancel', '취소된 연결 주문에 가상계좌 입금 확인 - 환불 필요');
|
||||
inicis_pro_noti_result($processed, $lock_name);
|
||||
}
|
||||
|
||||
$marker = '[INIpay PRO personalpay '.$oid.']';
|
||||
if (strpos($linked['od_shop_memo'], $marker) === false) {
|
||||
$memo = "\n".$marker.' 입금완료 - '.$receipt_time;
|
||||
$update_linked = " update {$g5['g5_shop_order_table']}
|
||||
set od_receipt_price = od_receipt_price + '$amount',
|
||||
od_receipt_time = '$time_sql',
|
||||
od_shop_memo = concat(od_shop_memo, '".sql_escape_string($memo)."')
|
||||
where od_id = '".sql_escape_string($linked_id)."' ";
|
||||
if (!sql_query($update_linked, false))
|
||||
inicis_pro_noti_fail('LINKED_ORDER_RECEIPT_UPDATE_FAILED', $oid, $lock_name);
|
||||
}
|
||||
|
||||
$linked_info = get_order_info($linked_id);
|
||||
$linked_status_sql = " update {$g5['g5_shop_order_table']} set od_misu = '".(int) $linked_info['od_misu']."' ";
|
||||
if ((int) $linked_info['od_misu'] === 0)
|
||||
$linked_status_sql .= ", od_status = '입금' ";
|
||||
$linked_status_sql .= " where od_id = '".sql_escape_string($linked_id)."' ";
|
||||
if (!sql_query($linked_status_sql, false))
|
||||
inicis_pro_noti_fail('LINKED_ORDER_STATUS_UPDATE_FAILED', $oid, $lock_name);
|
||||
|
||||
if ((int) $linked_info['od_misu'] === 0
|
||||
&& !sql_query(" update {$g5['g5_shop_cart_table']} set ct_status = '입금' where od_id = '".sql_escape_string($linked_id)."' ", false))
|
||||
inicis_pro_noti_fail('LINKED_CART_STATUS_UPDATE_FAILED', $oid, $lock_name);
|
||||
}
|
||||
|
||||
if (!sql_query(" update {$g5['g5_shop_personalpay_table']}
|
||||
set pp_receipt_price = '$amount',
|
||||
pp_receipt_time = '$time_sql'
|
||||
where pp_id = '$oid_sql'
|
||||
and pp_tno = '$tid_sql' ", false))
|
||||
inicis_pro_noti_fail('PERSONAL_RECEIPT_UPDATE_FAILED', $oid, $lock_name);
|
||||
|
||||
$check_personal = sql_fetch(" select pp_receipt_price from {$g5['g5_shop_personalpay_table']} where pp_id = '$oid_sql' and pp_tno = '$tid_sql' ");
|
||||
$processed = isset($check_personal['pp_receipt_price']) && (int) $check_personal['pp_receipt_price'] === $amount;
|
||||
if ($processed)
|
||||
$processed = inicis_pro_noti_save_audit($oid, $status, $auth_date, $remote_ip, 'paid', '가상계좌 입금 통보 처리 완료');
|
||||
else
|
||||
inicis_pro_noti_fail('PERSONAL_RECEIPT_VERIFY_FAILED', $oid, $lock_name);
|
||||
inicis_pro_noti_result($processed, $lock_name);
|
||||
}
|
||||
|
||||
$order = sql_fetch(" select * from {$g5['g5_shop_order_table']}
|
||||
where od_id = '$oid_sql'
|
||||
and od_tno = '$tid_sql'
|
||||
and od_pg = 'inicis'
|
||||
and od_settle_case = '가상계좌' ");
|
||||
if (empty($order['od_id']))
|
||||
inicis_pro_noti_fail('ORDER_MISSING', $oid, $lock_name);
|
||||
if ($order['od_status'] === '취소' || (int) $order['od_cancel_price'] > 0) {
|
||||
$processed = inicis_pro_noti_save_audit($oid, $status, $auth_date, $remote_ip, 'paid_after_cancel', '취소 주문에 가상계좌 입금 확인 - 환불 필요');
|
||||
inicis_pro_noti_result($processed, $lock_name);
|
||||
}
|
||||
if ((int) $order['od_receipt_price'] !== 0 && (int) $order['od_receipt_price'] !== $amount)
|
||||
inicis_pro_noti_fail('ORDER_RECEIPT_MISMATCH', $oid, $lock_name);
|
||||
|
||||
if (!sql_query(" update {$g5['g5_shop_order_table']}
|
||||
set od_receipt_price = '$amount',
|
||||
od_receipt_time = '$time_sql'
|
||||
where od_id = '$oid_sql'
|
||||
and od_tno = '$tid_sql' ", false))
|
||||
inicis_pro_noti_fail('ORDER_RECEIPT_UPDATE_FAILED', $oid, $lock_name);
|
||||
|
||||
$order_info = get_order_info($oid);
|
||||
$status_sql = " update {$g5['g5_shop_order_table']} set od_misu = '".(int) $order_info['od_misu']."' ";
|
||||
if ((int) $order_info['od_misu'] === 0)
|
||||
$status_sql .= ", od_status = '입금' ";
|
||||
$status_sql .= " where od_id = '$oid_sql' and od_tno = '$tid_sql' ";
|
||||
if (!sql_query($status_sql, false))
|
||||
inicis_pro_noti_fail('ORDER_STATUS_UPDATE_FAILED', $oid, $lock_name);
|
||||
|
||||
if ((int) $order_info['od_misu'] === 0
|
||||
&& !sql_query(" update {$g5['g5_shop_cart_table']} set ct_status = '입금' where od_id = '$oid_sql' ", false))
|
||||
inicis_pro_noti_fail('CART_STATUS_UPDATE_FAILED', $oid, $lock_name);
|
||||
|
||||
$check_order = sql_fetch(" select od_receipt_price, od_misu from {$g5['g5_shop_order_table']} where od_id = '$oid_sql' and od_tno = '$tid_sql' ");
|
||||
$processed = isset($check_order['od_receipt_price']) && (int) $check_order['od_receipt_price'] === $amount;
|
||||
if ($processed)
|
||||
$processed = inicis_pro_noti_save_audit($oid, $status, $auth_date, $remote_ip, 'paid', '가상계좌 입금 통보 처리 완료');
|
||||
else
|
||||
inicis_pro_noti_fail('ORDER_RECEIPT_VERIFY_FAILED', $oid, $lock_name);
|
||||
inicis_pro_noti_result($processed, $lock_name);
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
add_javascript('<script src="https://paypro.inicis.com/std/payment/js/INIPayPro_v2.js" charset="UTF-8"></script>', 10);
|
||||
|
||||
if (G5_IS_MOBILE) {
|
||||
?>
|
||||
<form name="sm_form" method="post" action="">
|
||||
<input type="hidden" name="good_mny" value="<?php echo isset($tot_price) ? (int) $tot_price : 0; ?>">
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function inicis_pro_pay(oid, deviceType)
|
||||
{
|
||||
var requestData = null;
|
||||
var errorMessage = '';
|
||||
|
||||
jQuery.ajax({
|
||||
type: 'POST',
|
||||
url: g5_url + '/shop/inicis/pro/request.php',
|
||||
data: {oid: oid, device_type: deviceType},
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
async: false,
|
||||
success: function(data) {
|
||||
if (data && data.success) {
|
||||
requestData = data.request;
|
||||
} else {
|
||||
errorMessage = data && data.message ? data.message : '결제 요청 정보를 생성하지 못했습니다.';
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
errorMessage = '결제 요청 정보를 확인하는 중 통신 오류가 발생했습니다.';
|
||||
}
|
||||
});
|
||||
|
||||
if (!requestData) {
|
||||
alert(errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof INIPayPro === 'undefined' || typeof INIPayPro.requestPayment !== 'function') {
|
||||
alert('KG이니시스 결제창을 불러오지 못했습니다. 잠시 후 다시 시도해 주십시오.');
|
||||
return false;
|
||||
}
|
||||
|
||||
INIPayPro.requestPayment(requestData);
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
include_once(G5_SHOP_PATH.'/inicis/pro/inicis_pro.lib.php');
|
||||
|
||||
// === INIpay PRO 승인 실행 위치: 주문 저장 직전 (return.php에서 이관) ===
|
||||
$inicis_pro_ctx = (isset($GLOBALS['inicis_pro_approval_ctx']) && is_array($GLOBALS['inicis_pro_approval_ctx'])) ? $GLOBALS['inicis_pro_approval_ctx'] : array();
|
||||
if ($inicis_pro_ctx) {
|
||||
unset($GLOBALS['inicis_pro_approval_ctx']);
|
||||
$oid = isset($inicis_pro_ctx['oid']) ? $inicis_pro_ctx['oid'] : '';
|
||||
$auth_tid = isset($inicis_pro_ctx['auth_tid']) ? $inicis_pro_ctx['auth_tid'] : '';
|
||||
$idc = isset($inicis_pro_ctx['idc']) ? $inicis_pro_ctx['idc'] : '';
|
||||
$expected_mid = isset($inicis_pro_ctx['expected_mid']) ? $inicis_pro_ctx['expected_mid'] : '';
|
||||
$expected_amount = isset($inicis_pro_ctx['expected_amount']) ? $inicis_pro_ctx['expected_amount'] : 0;
|
||||
$pay_type = isset($inicis_pro_ctx['pay_type']) ? $inicis_pro_ctx['pay_type'] : '';
|
||||
$result_type = isset($inicis_pro_ctx['result_type']) ? $inicis_pro_ctx['result_type'] : '';
|
||||
$noti = isset($inicis_pro_ctx['noti']) ? $inicis_pro_ctx['noti'] : '';
|
||||
$device = isset($inicis_pro_ctx['device']) ? $inicis_pro_ctx['device'] : '';
|
||||
$settle_case = isset($inicis_pro_ctx['settle_case']) ? $inicis_pro_ctx['settle_case'] : '';
|
||||
$is_personal = !empty($inicis_pro_ctx['is_personal']);
|
||||
$lock_name = isset($inicis_pro_ctx['lock_name']) ? $inicis_pro_ctx['lock_name'] : '';
|
||||
$page_return_url = isset($inicis_pro_ctx['page_return_url']) ? $inicis_pro_ctx['page_return_url'] : G5_SHOP_URL;
|
||||
$audit_values = (isset($inicis_pro_ctx['audit_values']) && is_array($inicis_pro_ctx['audit_values'])) ? $inicis_pro_ctx['audit_values'] : array();
|
||||
|
||||
$approval = array();
|
||||
$old_log = inicis_pro_get_log($oid);
|
||||
$old_data = isset($old_log['pro_data']) && is_array($old_log['pro_data']) ? $old_log['pro_data'] : array();
|
||||
$old_is_pro = isset($old_data['__pro']) && $old_data['__pro'] === '1';
|
||||
$old_auth_tid = isset($old_data['P_AUTH_TID']) ? $old_data['P_AUTH_TID'] : '';
|
||||
|
||||
if ($old_is_pro && isset($old_log['P_STATUS']) && $old_log['P_STATUS'] === '00') {
|
||||
if ($old_auth_tid !== $auth_tid) {
|
||||
$duplicate_cancel = inicis_pro_net_cancel($idc, $expected_mid, $auth_tid, $expected_amount, $oid, 'duplicate authorization', $pay_type);
|
||||
$audit_values['event_only'] = '1';
|
||||
inicis_pro_return_error('이미 처리된 주문과 다른 승인정보가 확인되어 새 결제를 중단했습니다.', $page_return_url, $lock_name, $oid, 'cancel', !empty($duplicate_cancel['success']) ? 'canceled' : 'cancel_failed', 'DUPLICATE_AUTH', $audit_values);
|
||||
}
|
||||
$approval = $old_data;
|
||||
} elseif ($old_is_pro && isset($old_log['P_STATUS']) && $old_log['P_STATUS'] === 'processing' && $old_auth_tid === $auth_tid) {
|
||||
$cancel_result = inicis_pro_net_cancel($idc, $expected_mid, $auth_tid, $expected_amount, $oid, 'interrupted approval', $pay_type);
|
||||
if (!empty($cancel_result['success']))
|
||||
sql_query(" update {$g5['g5_shop_inicis_log_table']} set P_STATUS = 'cancel', P_RMESG1 = 'interrupted approval net-cancel' where oid = '".sql_escape_string($oid)."' ", false);
|
||||
inicis_pro_return_error('이전 승인 처리가 중단된 기록이 있어 안전을 위해 결제를 취소했습니다. 주문내역을 확인한 후 다시 시도해 주십시오.', $page_return_url, $lock_name, $oid, 'cancel', !empty($cancel_result['success']) ? 'canceled' : 'cancel_failed', 'INTERRUPTED_APPROVAL', $audit_values);
|
||||
} elseif ($old_is_pro && isset($old_log['P_STATUS']) && $old_log['P_STATUS'] === 'processing') {
|
||||
$old_idc = isset($old_data['P_IDCNAME']) ? strtolower($old_data['P_IDCNAME']) : '';
|
||||
$old_amount = isset($old_data['P_AMT']) ? (int) $old_data['P_AMT'] : 0;
|
||||
$old_cancel_ok = true;
|
||||
if ($old_auth_tid !== '' && $old_amount > 0) {
|
||||
$old_cancel = inicis_pro_net_cancel($old_idc, $expected_mid, $old_auth_tid, $old_amount, $oid, 'stale authorization', $pay_type);
|
||||
$old_cancel_ok = !empty($old_cancel['success']);
|
||||
}
|
||||
$new_cancel = inicis_pro_net_cancel($idc, $expected_mid, $auth_tid, $expected_amount, $oid, 'duplicate authorization', $pay_type);
|
||||
inicis_pro_return_error('동일 주문의 다른 승인 처리가 확인되어 안전을 위해 결제를 중단했습니다.', $page_return_url, $lock_name, $oid, 'cancel', $old_cancel_ok && !empty($new_cancel['success']) ? 'canceled' : 'cancel_failed', 'CONCURRENT_AUTH', $audit_values);
|
||||
}
|
||||
|
||||
if (empty($approval)) {
|
||||
inicis_pro_audit_write($oid, 'approval', 'approval_started', $audit_values);
|
||||
$processing = array(
|
||||
'P_STATUS' => 'processing',
|
||||
'P_RMESG' => 'approval request started',
|
||||
'P_MID' => $expected_mid,
|
||||
'P_OID' => $oid,
|
||||
'P_AUTH_TID' => $auth_tid,
|
||||
'P_AMT' => (string) $expected_amount,
|
||||
'P_TYPE' => $result_type,
|
||||
'P_NOTI' => $noti,
|
||||
'P_IDCNAME' => $idc,
|
||||
'__pro' => '1',
|
||||
'__device' => $device,
|
||||
'__environment' => inicis_pro_environment(),
|
||||
'__easy_pay' => inicis_pro_easypay_name($settle_case),
|
||||
'__order_type' => $is_personal ? 'personal' : 'order'
|
||||
);
|
||||
if (!inicis_pro_save_log($processing))
|
||||
inicis_pro_return_error('결제 승인 준비정보를 저장하지 못했습니다.', $page_return_url, $lock_name, $oid, 'approval', 'approval_failed', 'APPROVAL_LOG_FAILED', $audit_values);
|
||||
|
||||
$approval_response = inicis_pro_http_post(
|
||||
'https://'.inicis_pro_idc_host($idc).'/payment/v1/rest/payAppl.ini',
|
||||
array(
|
||||
'P_MID' => $expected_mid,
|
||||
'P_AUTH_TID' => $auth_tid,
|
||||
'P_AMT' => (string) $expected_amount,
|
||||
'P_CHARSET' => 'UTF-8'
|
||||
)
|
||||
);
|
||||
if (!$approval_response['success']) {
|
||||
$communication_cancel = inicis_pro_net_cancel($idc, $expected_mid, $auth_tid, $expected_amount, $oid, 'approval communication failure', $pay_type);
|
||||
$communication_status = !empty($communication_cancel['success']) ? 'cancel' : 'fail';
|
||||
sql_query(" update {$g5['g5_shop_inicis_log_table']} set P_STATUS = '$communication_status', P_RMESG1 = 'approval communication failure' where oid = '".sql_escape_string($oid)."' ", false);
|
||||
inicis_pro_return_error('KG이니시스 승인 서버와 통신하지 못했습니다. 결제 여부를 관리자에게 문의해 주십시오.', $page_return_url, $lock_name, $oid, 'approval', !empty($communication_cancel['success']) ? 'canceled' : 'communication_failed', 'APPROVAL_COMMUNICATION', $audit_values);
|
||||
}
|
||||
|
||||
$approval = inicis_pro_parse_nvp($approval_response['body']);
|
||||
$approval_message = isset($approval['P_RMESG']) ? inicis_pro_cut($approval['P_RMESG'], 150) : '';
|
||||
if (!isset($approval['P_STATUS']) || $approval['P_STATUS'] !== '00') {
|
||||
$processing['P_STATUS'] = isset($approval['P_STATUS']) ? $approval['P_STATUS'] : 'fail';
|
||||
$processing['P_RMESG'] = $approval_message !== '' ? $approval_message : 'approval failed';
|
||||
inicis_pro_save_log($processing);
|
||||
inicis_pro_return_error('결제 승인 실패: '.$processing['P_RMESG'], $page_return_url, $lock_name, $oid, 'approval', 'approval_failed', $processing['P_STATUS'], $audit_values);
|
||||
}
|
||||
|
||||
$approved_tid = isset($approval['P_APPL_TID']) ? inicis_pro_clean_tid($approval['P_APPL_TID']) : '';
|
||||
$approved_type = isset($approval['P_TYPE']) ? strtoupper($approval['P_TYPE']) : '';
|
||||
$approved_amount = isset($approval['P_AMT']) ? $approval['P_AMT'] : '';
|
||||
$approved_oid = isset($approval['P_OID']) ? inicis_pro_clean_oid($approval['P_OID']) : '';
|
||||
$approved_auth_tid = isset($approval['P_AUTH_TID']) ? inicis_pro_clean_tid($approval['P_AUTH_TID']) : '';
|
||||
$approval_valid = isset($approval['P_MID']) && $approval['P_MID'] === $expected_mid
|
||||
&& $approved_oid === $oid && isset($approval['P_OID']) && $approval['P_OID'] === $approved_oid
|
||||
&& preg_match('/^[0-9]+$/', $approved_amount) && (int) $approved_amount === (int) $expected_amount
|
||||
&& $approved_auth_tid === $auth_tid && isset($approval['P_AUTH_TID']) && $approval['P_AUTH_TID'] === $approved_auth_tid
|
||||
&& $approved_tid !== '' && isset($approval['P_APPL_TID']) && $approval['P_APPL_TID'] === $approved_tid
|
||||
&& inicis_pro_result_type_matches($settle_case, $approved_type);
|
||||
|
||||
if (!$approval_valid) {
|
||||
$mismatch_cancel = inicis_pro_net_cancel($idc, $expected_mid, $auth_tid, $expected_amount, $oid, 'approval result mismatch', $pay_type);
|
||||
$processing['P_STATUS'] = !empty($mismatch_cancel['success']) ? 'cancel' : 'mismatch';
|
||||
$processing['P_RMESG'] = 'approval result mismatch';
|
||||
inicis_pro_save_log($processing);
|
||||
inicis_pro_return_error('승인 결과가 결제요청 정보와 일치하지 않아 주문을 중단했습니다. 취소 여부는 관리자에게 문의해 주십시오.', $page_return_url, $lock_name, $oid, 'validation', !empty($mismatch_cancel['success']) ? 'canceled' : 'cancel_failed', 'APPROVAL_RESULT_MISMATCH', $audit_values);
|
||||
}
|
||||
|
||||
$approval['P_NOTI'] = $noti;
|
||||
$approval['P_IDCNAME'] = $idc;
|
||||
$approval['__pro'] = '1';
|
||||
$approval['__device'] = $device;
|
||||
$approval['__environment'] = inicis_pro_environment();
|
||||
$approval['__easy_pay'] = inicis_pro_easypay_name($settle_case);
|
||||
$approval['__order_type'] = $is_personal ? 'personal' : 'order';
|
||||
if (!inicis_pro_save_log($approval)) {
|
||||
$approval_log_cancel = inicis_pro_net_cancel($idc, $expected_mid, $auth_tid, $expected_amount, $oid, 'approval log failure', $pay_type);
|
||||
inicis_pro_return_error('승인정보를 저장하지 못해 결제를 취소했습니다.', $page_return_url, $lock_name, $oid, 'cancel', !empty($approval_log_cancel['success']) ? 'canceled' : 'cancel_failed', 'APPROVAL_LOG_FAILED', $audit_values);
|
||||
}
|
||||
}
|
||||
|
||||
$audit_values['tid'] = isset($approval['P_APPL_TID']) ? $approval['P_APPL_TID'] : '';
|
||||
$audit_values['pay_type'] = isset($approval['P_TYPE']) ? $approval['P_TYPE'] : $audit_values['pay_type'];
|
||||
$audit_values['code'] = isset($approval['P_STATUS']) ? $approval['P_STATUS'] : '';
|
||||
$audit_values['message'] = isset($approval['P_RMESG']) ? $approval['P_RMESG'] : 'KG이니시스 승인 완료';
|
||||
|
||||
$final_tid = isset($approval['P_APPL_TID']) ? inicis_pro_clean_tid($approval['P_APPL_TID']) : '';
|
||||
if ($final_tid === '' || !isset($approval['P_APPL_TID']) || $approval['P_APPL_TID'] !== $final_tid
|
||||
|| !isset($approval['P_STATUS']) || $approval['P_STATUS'] !== '00'
|
||||
|| !isset($approval['P_MID']) || $approval['P_MID'] !== $expected_mid
|
||||
|| !isset($approval['P_OID']) || $approval['P_OID'] !== $oid
|
||||
|| !isset($approval['P_AMT']) || (int) $approval['P_AMT'] !== (int) $expected_amount
|
||||
|| !isset($approval['P_AUTH_TID']) || $approval['P_AUTH_TID'] !== $auth_tid
|
||||
|| !isset($approval['P_NOTI']) || !inicis_pro_equals($approval['P_NOTI'], $noti)
|
||||
|| !isset($approval['P_IDCNAME']) || $approval['P_IDCNAME'] !== $idc
|
||||
|| !isset($approval['__device']) || $approval['__device'] !== $device
|
||||
|| !isset($approval['P_TYPE']) || !inicis_pro_result_type_matches($settle_case, $approval['P_TYPE'])) {
|
||||
inicis_pro_return_error('저장된 승인정보를 검증하지 못했습니다.', $page_return_url, $lock_name, $oid, 'validation', 'validation_failed', 'SAVED_APPROVAL_INVALID', $audit_values);
|
||||
}
|
||||
|
||||
inicis_pro_audit_write($oid, 'approval', 'approved', $audit_values);
|
||||
|
||||
$_POST['P_TYPE'] = isset($approval['P_TYPE']) ? $approval['P_TYPE'] : '';
|
||||
$_POST['P_AUTH_DT'] = (isset($approval['P_APPL_DT']) ? $approval['P_APPL_DT'] : '').(isset($approval['P_APPL_TM']) ? $approval['P_APPL_TM'] : '');
|
||||
$_POST['P_AUTH_NO'] = isset($approval['P_APPL_NO']) ? $approval['P_APPL_NO'] : '';
|
||||
$_POST['P_HASH'] = md5($final_tid.$expected_mid.$expected_amount);
|
||||
|
||||
set_session('P_TID', $final_tid);
|
||||
set_session('P_AMT', (string) $expected_amount);
|
||||
set_session('P_HASH', $_POST['P_HASH']);
|
||||
set_session('ss_inicis_pro_oid', $oid);
|
||||
}
|
||||
|
||||
|
||||
$pro_oid = isset($_POST['inicis_pro_oid']) ? inicis_pro_clean_oid($_POST['inicis_pro_oid']) : '';
|
||||
$pro_log = inicis_pro_get_log($pro_oid);
|
||||
$pro_data = isset($pro_log['pro_data']) && is_array($pro_log['pro_data']) ? $pro_log['pro_data'] : array();
|
||||
|
||||
if ($pro_oid === '' || empty($pro_data['__pro']) || $pro_data['__pro'] !== '1' || !isset($pro_log['P_STATUS']) || $pro_log['P_STATUS'] !== '00')
|
||||
alert('승인된 INIpay PRO 결제정보를 확인할 수 없습니다.');
|
||||
|
||||
$pro_tid = isset($pro_data['P_APPL_TID']) ? inicis_pro_clean_tid($pro_data['P_APPL_TID']) : '';
|
||||
$pro_mid = isset($pro_data['P_MID']) ? $pro_data['P_MID'] : '';
|
||||
$pro_amount = isset($pro_data['P_AMT']) ? (int) $pro_data['P_AMT'] : 0;
|
||||
$pro_hash = md5($pro_tid.$pro_mid.$pro_amount);
|
||||
$post_hash = isset($_POST['P_HASH']) ? (string) $_POST['P_HASH'] : '';
|
||||
|
||||
if ($pro_tid === '' || $pro_mid !== inicis_pro_get_mid(isset($pro_data['P_TYPE']) ? $pro_data['P_TYPE'] : null) || !isset($pro_data['P_OID']) || $pro_data['P_OID'] !== $pro_oid
|
||||
|| !inicis_pro_equals($pro_hash, $post_hash) || !inicis_pro_equals($pro_hash, (string) get_session('P_HASH'))
|
||||
|| (string) get_session('P_TID') !== $pro_tid || (int) get_session('P_AMT') !== $pro_amount
|
||||
|| (string) get_session('ss_inicis_pro_oid') !== $pro_oid)
|
||||
alert('INIpay PRO 승인정보가 주문정보와 일치하지 않습니다.');
|
||||
|
||||
$tno = $pro_tid;
|
||||
$amount = $pro_amount;
|
||||
$app_time = (isset($pro_data['P_APPL_DT']) ? preg_replace('/[^0-9]/', '', $pro_data['P_APPL_DT']) : '')
|
||||
.(isset($pro_data['P_APPL_TM']) ? preg_replace('/[^0-9]/', '', $pro_data['P_APPL_TM']) : '');
|
||||
$pay_method = isset($pro_data['P_TYPE']) ? strtoupper($pro_data['P_TYPE']) : '';
|
||||
$pay_type = '';
|
||||
switch ($pay_method) {
|
||||
case 'CARD':
|
||||
$pay_type = '신용카드';
|
||||
break;
|
||||
case 'BANK':
|
||||
$pay_type = '계좌이체';
|
||||
break;
|
||||
case 'VBANK':
|
||||
$pay_type = '가상계좌';
|
||||
break;
|
||||
case 'HPP':
|
||||
case 'MOBILE':
|
||||
$pay_type = '휴대폰';
|
||||
break;
|
||||
}
|
||||
|
||||
$depositor = isset($pro_data['P_VACT_NAME']) ? $pro_data['P_VACT_NAME'] : (isset($pro_data['P_UNAME']) ? $pro_data['P_UNAME'] : '');
|
||||
$commid = isset($pro_data['P_HPP_CORP']) ? $pro_data['P_HPP_CORP'] : (isset($pro_data['P_FN_NM']) ? $pro_data['P_FN_NM'] : '');
|
||||
$mobile_no = isset($pro_data['P_HPP_NUM']) ? $pro_data['P_HPP_NUM'] : (isset($pro_data['P_APPL_NUM']) ? $pro_data['P_APPL_NUM'] : '');
|
||||
$app_no = isset($pro_data['P_APPL_NO']) ? $pro_data['P_APPL_NO'] : '';
|
||||
$card_name = isset($pro_data['P_CARD_ISSUER_NAME']) && $pro_data['P_CARD_ISSUER_NAME'] !== '' ? $pro_data['P_CARD_ISSUER_NAME'] : (isset($pro_data['P_FN_NM']) ? $pro_data['P_FN_NM'] : '');
|
||||
$bank_name = isset($pro_data['P_FN_NM']) ? $pro_data['P_FN_NM'] : '';
|
||||
$bankname = $bank_name;
|
||||
$account = isset($pro_data['P_VACT_NUM']) ? $pro_data['P_VACT_NUM'] : '';
|
||||
if (!empty($pro_data['P_VACT_NAME']))
|
||||
$account .= ' '.$pro_data['P_VACT_NAME'];
|
||||
if ($pay_method === 'VBANK' && !empty($pro_data['P_VACT_NUM']))
|
||||
$app_no = $pro_data['P_VACT_NUM'];
|
||||
|
||||
if (!empty($default['de_escrow_use']) && ($pay_method === 'BANK' || $pay_method === 'VBANK'))
|
||||
$escw_yn = 'Y';
|
||||
|
||||
set_session('P_TID', '');
|
||||
set_session('P_AMT', '');
|
||||
set_session('P_HASH', '');
|
||||
set_session('ss_inicis_pro_oid', '');
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
include_once('./_common.php');
|
||||
include_once(G5_SHOP_PATH.'/inicis/pro/inicis_pro.lib.php');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST')
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '올바른 요청이 아닙니다.'));
|
||||
|
||||
if (function_exists('check_request_origin'))
|
||||
check_request_origin(G5_SHOP_URL);
|
||||
|
||||
if (!inicis_pro_is_enabled())
|
||||
inicis_pro_json_response(array('success' => false, 'message' => 'INIpay PRO 결제가 활성화되어 있지 않습니다.'));
|
||||
|
||||
$oid = isset($_POST['oid']) ? inicis_pro_clean_oid($_POST['oid']) : '';
|
||||
$device = isset($_POST['device_type']) ? strtoupper(preg_replace('/[^A-Z]/i', '', $_POST['device_type'])) : '';
|
||||
if ($oid === '' || ($device !== 'WEB' && $device !== 'MOBILE'))
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '결제 요청 정보가 올바르지 않습니다.'));
|
||||
|
||||
$sql = " select * from {$g5['g5_shop_order_data_table']}
|
||||
where od_id = '".sql_escape_string($oid)."'
|
||||
and dt_pg = 'inicis'
|
||||
order by dt_time desc
|
||||
limit 1 ";
|
||||
$temp_row = sql_fetch($sql);
|
||||
if (empty($temp_row['od_id']))
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '임시 주문정보가 저장되지 않았습니다.'));
|
||||
|
||||
$order_data = @unserialize(base64_decode($temp_row['dt_data']));
|
||||
if (!is_array($order_data))
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '임시 주문정보를 확인할 수 없습니다.'));
|
||||
|
||||
$is_personal = !empty($order_data['pp_id']);
|
||||
if ($is_personal) {
|
||||
if ((string) get_session('ss_personalpay_id') !== (string) $oid)
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '개인결제 세션이 일치하지 않습니다.'));
|
||||
} else {
|
||||
if ((string) get_session('ss_order_id') !== (string) $oid)
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '주문 세션이 일치하지 않습니다.'));
|
||||
|
||||
$session_member_id = isset($member['mb_id']) ? (string) $member['mb_id'] : '';
|
||||
if ((string) $temp_row['mb_id'] !== $session_member_id)
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '주문 회원정보가 일치하지 않습니다.'));
|
||||
|
||||
$cart_id = preg_replace('/[^0-9]/', '', (string) $temp_row['cart_id']);
|
||||
if ($cart_id === '' || get_cart_count($cart_id) === 0)
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '결제할 장바구니 상품이 없습니다.'));
|
||||
if (function_exists('before_check_cart_price') && !before_check_cart_price($cart_id))
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '상품 가격이 변경되었습니다. 장바구니를 다시 확인해 주십시오.'));
|
||||
}
|
||||
|
||||
$settle_case_key = $is_personal ? 'pp_settle_case' : 'od_settle_case';
|
||||
$settle_case = isset($order_data[$settle_case_key]) ? $order_data[$settle_case_key] : '';
|
||||
$pay_type = inicis_pro_pay_type($settle_case);
|
||||
$easypay_code = inicis_pro_easypay_code($settle_case);
|
||||
$easypay_name = inicis_pro_easypay_name($settle_case);
|
||||
$amount = inicis_pro_expected_amount($order_data, $temp_row);
|
||||
$mid = inicis_pro_get_mid($pay_type);
|
||||
$hashkey = inicis_pro_get_hashkey($pay_type);
|
||||
|
||||
if ($pay_type === '' || $amount <= 0 || $amount > 999999999)
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '결제수단 또는 결제금액이 올바르지 않습니다.'));
|
||||
if ($easypay_code !== '' && !inicis_pro_easypay_is_enabled($settle_case))
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '선택한 간편결제는 현재 사용할 수 없습니다.'));
|
||||
if ($mid === '' || $hashkey === '')
|
||||
inicis_pro_json_response(array('success' => false, 'message' => 'KG이니시스 MID 또는 HashKey가 설정되지 않았습니다.'));
|
||||
if (!function_exists('hash') || !in_array('sha512', hash_algos()))
|
||||
inicis_pro_json_response(array('success' => false, 'message' => '서버에서 SHA-512 해시를 지원하지 않습니다.'));
|
||||
|
||||
$timestamp = inicis_pro_timestamp();
|
||||
$buyer_name = $is_personal ? (isset($order_data['pp_name']) ? $order_data['pp_name'] : '') : (isset($order_data['od_name']) ? $order_data['od_name'] : '');
|
||||
$buyer_email = $is_personal ? (isset($order_data['pp_email']) ? $order_data['pp_email'] : '') : (isset($order_data['od_email']) ? $order_data['od_email'] : '');
|
||||
$buyer_phone = $is_personal ? (isset($order_data['pp_hp']) ? $order_data['pp_hp'] : '') : (!empty($order_data['od_hp']) ? $order_data['od_hp'] : (isset($order_data['od_tel']) ? $order_data['od_tel'] : ''));
|
||||
|
||||
$reserved = array(
|
||||
'email' => inicis_pro_cut($buyer_email, 60),
|
||||
'phonenum' => preg_replace('/[^0-9]/', '', $buyer_phone)
|
||||
);
|
||||
if ($pay_type === 'CARD') {
|
||||
$reserved['quotabase'] = '01:02:03:04:05:06:07:08:09:10:11:12';
|
||||
if ($easypay_code !== '')
|
||||
$reserved['d_easypay'] = $easypay_code;
|
||||
}
|
||||
if ($pay_type === 'BANK')
|
||||
$reserved['bank_receipt'] = 'N';
|
||||
if ($pay_type === 'VBANK') {
|
||||
$reserved['vbank_receipt'] = 'N';
|
||||
$reserved['vbank_dt'] = date('Ymd', G5_SERVER_TIME + (86400 * 3));
|
||||
$reserved['vbank_tm'] = '2359';
|
||||
}
|
||||
if (!empty($default['de_escrow_use']) && ($pay_type === 'BANK' || $pay_type === 'VBANK'))
|
||||
$reserved['useescrow'] = 'Y';
|
||||
|
||||
$base_url = defined('G5_HTTPS_SHOP_URL') && G5_HTTPS_SHOP_URL ? G5_HTTPS_SHOP_URL : G5_SHOP_URL;
|
||||
$noti = inicis_pro_make_noti($oid, $amount, $device, $hashkey);
|
||||
|
||||
$request = array(
|
||||
'P_MID' => $mid,
|
||||
'P_OID' => $oid,
|
||||
'P_PAY_TYPE' => $pay_type,
|
||||
'P_DEVICE_TYPE' => $device,
|
||||
'P_IDCCODE' => 'Y',
|
||||
'P_AMT' => (string) $amount,
|
||||
'P_GOODS' => inicis_pro_goods_name($order_data, $temp_row),
|
||||
'P_UNAME' => inicis_pro_cut($buyer_name, 30),
|
||||
'P_NEXT_URL' => $base_url.'/inicis/pro/return.php',
|
||||
'P_CHARSET' => 'UTF-8',
|
||||
'P_NOTI' => $noti,
|
||||
'P_TIMESTAMP' => $timestamp,
|
||||
'P_CHKFAKE' => inicis_pro_hash($amount, $oid, $timestamp, $hashkey),
|
||||
'P_RESERVED' => inicis_pro_json_encode($reserved)
|
||||
);
|
||||
|
||||
if ($pay_type === 'VBANK')
|
||||
$request['P_NOTI_URL'] = $base_url.'/inicis/pro/noti.php';
|
||||
|
||||
// PC 결제창은 iframe 모달이므로 닫기 URL을 전달하면 주문서 전체가 다시
|
||||
// 로드된다. 모바일은 현재 창에서 결제가 진행되므로 돌아갈 URL을 유지한다.
|
||||
if ($device === 'MOBILE') {
|
||||
if ($is_personal)
|
||||
$request['P_CLOSE_URL'] = G5_SHOP_URL.'/personalpayform.php?pp_id='.$oid;
|
||||
elseif (!empty($order_data['sw_direct']))
|
||||
$request['P_CLOSE_URL'] = G5_SHOP_URL.'/orderform.php?sw_direct=1';
|
||||
else
|
||||
$request['P_CLOSE_URL'] = G5_SHOP_URL.'/orderform.php';
|
||||
}
|
||||
|
||||
if ($pay_type === 'HPP')
|
||||
$request['P_HPP_METHOD'] = '2';
|
||||
if (!empty($default['de_tax_flag_use'])) {
|
||||
$request['P_TAX'] = isset($order_data['comm_vat_mny']) ? (string) (int) $order_data['comm_vat_mny'] : '0';
|
||||
$request['P_TAXFREE'] = isset($order_data['comm_free_mny']) ? (string) (int) $order_data['comm_free_mny'] : '0';
|
||||
}
|
||||
|
||||
inicis_pro_audit_write($oid, 'request', 'request_ready', array(
|
||||
'mid' => $mid,
|
||||
'environment' => inicis_pro_environment(),
|
||||
'member_id' => isset($temp_row['mb_id']) ? $temp_row['mb_id'] : '',
|
||||
'amount' => $amount,
|
||||
'pay_type' => $pay_type,
|
||||
'easy_pay' => $easypay_name,
|
||||
'device' => $device,
|
||||
'order_type' => $is_personal ? 'personal' : 'order',
|
||||
'source' => $device === 'MOBILE' ? 'mobile' : 'web',
|
||||
'vbank_due_at' => $pay_type === 'VBANK' ? date('Y-m-d 23:59:00', G5_SERVER_TIME + (86400 * 3)) : '',
|
||||
'message' => $easypay_code !== '' ? $settle_case.' 결제창 요청정보 생성 완료' : '결제창 요청정보 생성 완료'
|
||||
));
|
||||
|
||||
inicis_pro_json_response(array('success' => true, 'request' => $request));
|
||||
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
include_once('./_common.php');
|
||||
include_once(G5_SHOP_PATH.'/inicis/pro/inicis_pro.lib.php');
|
||||
|
||||
@header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
|
||||
if (!function_exists('inicis_pro_return_error')) {
|
||||
function inicis_pro_return_error($message, $return_url, $lock_name, $oid = '', $stage = 'validation', $status = 'validation_failed', $code = '', $values = array())
|
||||
{
|
||||
if (!is_array($values))
|
||||
$values = array();
|
||||
$values['message'] = $message;
|
||||
if ($code !== '')
|
||||
$values['code'] = $code;
|
||||
inicis_pro_audit_write($oid, $stage, $status, $values);
|
||||
inicis_pro_unlock($lock_name);
|
||||
alert($message, $return_url);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('inicis_pro_restore_order_value')) {
|
||||
function inicis_pro_restore_order_value($value, $memo)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$result = array();
|
||||
foreach ($value as $key => $item) {
|
||||
if (!is_scalar($key))
|
||||
continue;
|
||||
$result[$key] = inicis_pro_restore_order_value($item, false);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!is_scalar($value))
|
||||
return '';
|
||||
|
||||
$value = stripslashes((string) $value);
|
||||
if ($memo)
|
||||
return clean_xss_tags(strip_tags($value), 0, 0, 0, 0);
|
||||
|
||||
return clean_xss_tags(strip_tags($value));
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'POST')
|
||||
alert('올바른 결제 결과 요청이 아닙니다.', G5_SHOP_URL);
|
||||
|
||||
if (!inicis_pro_is_enabled())
|
||||
alert('INIpay PRO 결제가 활성화되어 있지 않습니다.', G5_SHOP_URL);
|
||||
|
||||
$status = isset($_POST['P_STATUS']) ? trim((string) $_POST['P_STATUS']) : '';
|
||||
$message = isset($_POST['P_RMESG']) ? inicis_pro_cut($_POST['P_RMESG'], 150) : '';
|
||||
$oid_raw = isset($_POST['P_OID']) ? trim((string) $_POST['P_OID']) : '';
|
||||
$oid = inicis_pro_clean_oid($oid_raw);
|
||||
$mid = isset($_POST['P_MID']) ? trim((string) $_POST['P_MID']) : '';
|
||||
$auth_tid_raw = isset($_POST['P_AUTH_TID']) ? trim((string) $_POST['P_AUTH_TID']) : '';
|
||||
$auth_tid = inicis_pro_clean_tid($auth_tid_raw);
|
||||
$amount_raw = isset($_POST['P_AMT']) ? trim((string) $_POST['P_AMT']) : '';
|
||||
$result_type = isset($_POST['P_TYPE']) ? strtoupper(trim((string) $_POST['P_TYPE'])) : '';
|
||||
$noti = isset($_POST['P_NOTI']) ? trim((string) $_POST['P_NOTI']) : '';
|
||||
$idc = isset($_POST['P_IDCNAME']) ? strtolower(trim((string) $_POST['P_IDCNAME'])) : '';
|
||||
$page_return_url = G5_SHOP_URL.'/orderform.php';
|
||||
$lock_name = '';
|
||||
$session_order_oid = inicis_pro_clean_oid(get_session('ss_order_id'));
|
||||
$session_personal_oid = inicis_pro_clean_oid(get_session('ss_personalpay_id'));
|
||||
$session_matches_oid = $oid !== '' && ($session_order_oid === $oid || $session_personal_oid === $oid);
|
||||
|
||||
// 인증 실패 응답은 주문번호 등 일부 필드가 누락될 수 있으므로 결과코드를 먼저 처리한다.
|
||||
if ($status !== '00') {
|
||||
$error_text = $message !== '' ? $message : '결제 인증에 실패했습니다.';
|
||||
$error_code = substr(preg_replace('/[^A-Za-z0-9_-]/', '', $status), 0, 12);
|
||||
if ($error_code === '')
|
||||
$error_code = '확인불가';
|
||||
|
||||
$failure_return_url = $page_return_url;
|
||||
$session_personal_id = inicis_pro_clean_oid(get_session('ss_personalpay_id'));
|
||||
if ($session_personal_id !== '')
|
||||
$failure_return_url = G5_SHOP_URL.'/personalpayform.php?pp_id='.$session_personal_id;
|
||||
elseif (get_session('ss_direct'))
|
||||
$failure_return_url .= '?sw_direct=1';
|
||||
|
||||
inicis_pro_return_error('결제 인증 실패: '.$error_text.' (코드 '.$error_code.')', $failure_return_url, '', $session_matches_oid ? $oid : '', 'authentication', 'authentication_failed', $error_code, array(
|
||||
'mid' => $mid,
|
||||
'auth_tid' => $auth_tid,
|
||||
'amount' => preg_match('/^[0-9]+$/', $amount_raw) ? (int) $amount_raw : 0,
|
||||
'pay_type' => $result_type,
|
||||
'device' => defined('G5_IS_MOBILE') && G5_IS_MOBILE ? 'MOBILE' : 'WEB',
|
||||
'source' => defined('G5_IS_MOBILE') && G5_IS_MOBILE ? 'mobile' : 'web'
|
||||
));
|
||||
}
|
||||
|
||||
if ($oid === '' || $oid !== $oid_raw)
|
||||
alert('결제 주문번호가 올바르지 않습니다.', G5_SHOP_URL);
|
||||
|
||||
$temp_row = sql_fetch(" select * from {$g5['g5_shop_order_data_table']}
|
||||
where od_id = '".sql_escape_string($oid)."'
|
||||
and dt_pg = 'inicis'
|
||||
order by dt_time desc
|
||||
limit 1 ");
|
||||
if (empty($temp_row['od_id'])) {
|
||||
$exists_order = get_shop_order_data($oid);
|
||||
if (!empty($exists_order['od_tno'])) {
|
||||
inicis_pro_audit_order_saved($oid, $exists_order['od_tno'], 'order', 'system');
|
||||
set_session('ss_order_id', $oid);
|
||||
exists_inicis_shop_order($oid, array(), $exists_order['od_time'], $exists_order['od_ip']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$exists_personal = get_shop_order_data($oid, 'personal');
|
||||
if (!empty($exists_personal['pp_tno'])) {
|
||||
inicis_pro_audit_order_saved($oid, $exists_personal['pp_tno'], 'personal', 'system');
|
||||
set_session('ss_personalpay_id', $oid);
|
||||
set_session('ss_personalpay_hash', md5($exists_personal['pp_id'].$exists_personal['pp_price'].$exists_personal['pp_time']));
|
||||
exists_inicis_shop_order($oid, $exists_personal, $exists_personal['pp_time'], $exists_personal['pp_ip']);
|
||||
exit;
|
||||
}
|
||||
|
||||
inicis_pro_return_error('임시 주문정보가 없어서 결제를 승인할 수 없습니다.', G5_SHOP_URL, '', $oid, 'validation', 'validation_failed', 'TEMP_ORDER_MISSING', array('source' => 'web'));
|
||||
}
|
||||
|
||||
$order_data = @unserialize(base64_decode($temp_row['dt_data']));
|
||||
if (!is_array($order_data))
|
||||
inicis_pro_return_error('임시 주문정보를 확인할 수 없습니다.', G5_SHOP_URL, '', $oid, 'validation', 'validation_failed', 'TEMP_ORDER_INVALID', array('source' => 'web'));
|
||||
|
||||
$is_personal = !empty($order_data['pp_id']);
|
||||
if ($is_personal)
|
||||
$page_return_url = G5_SHOP_URL.'/personalpayform.php?pp_id='.$oid;
|
||||
elseif (!empty($order_data['sw_direct']))
|
||||
$page_return_url .= '?sw_direct=1';
|
||||
|
||||
$settle_key = $is_personal ? 'pp_settle_case' : 'od_settle_case';
|
||||
$settle_case = isset($order_data[$settle_key]) ? $order_data[$settle_key] : '';
|
||||
// MID·HashKey는 PG가 생략할 수 있는 P_TYPE 대신 주문의 결제수단으로 확정해
|
||||
// 결제요청 시점의 서명과 일치시킨다.
|
||||
$pay_type = inicis_pro_pay_type($settle_case);
|
||||
$expected_mid = inicis_pro_get_mid($pay_type);
|
||||
$hashkey = inicis_pro_get_hashkey($pay_type);
|
||||
$expected_amount = inicis_pro_expected_amount($order_data, $temp_row);
|
||||
$device = inicis_pro_check_noti($noti, $oid, $expected_amount, $hashkey);
|
||||
$audit_source = $device === 'MOBILE' ? 'mobile' : 'web';
|
||||
$audit_values = array(
|
||||
'mid' => $mid,
|
||||
'auth_tid' => $auth_tid,
|
||||
'member_id' => isset($temp_row['mb_id']) ? $temp_row['mb_id'] : '',
|
||||
'amount' => $expected_amount,
|
||||
'pay_type' => $result_type !== '' ? $result_type : inicis_pro_pay_type($settle_case),
|
||||
'environment' => inicis_pro_environment(),
|
||||
'easy_pay' => inicis_pro_easypay_name($settle_case),
|
||||
'device' => $device,
|
||||
'order_type' => $is_personal ? 'personal' : 'order',
|
||||
'source' => $audit_source
|
||||
);
|
||||
$validation_audit_oid = ($device !== '' || $session_matches_oid) ? $oid : '';
|
||||
|
||||
if ($expected_mid === '' || $hashkey === '' || $mid !== $expected_mid)
|
||||
inicis_pro_return_error('가맹점 결제정보가 일치하지 않아 주문을 중단했습니다.', $page_return_url, '', $validation_audit_oid, 'validation', 'validation_failed', 'MID_MISMATCH', $audit_values);
|
||||
if ($expected_amount <= 0 || !preg_match('/^[0-9]+$/', $amount_raw) || (int) $amount_raw !== (int) $expected_amount)
|
||||
inicis_pro_return_error('결제금액이 주문정보와 일치하지 않아 주문을 중단했습니다.', $page_return_url, '', $validation_audit_oid, 'validation', 'validation_failed', 'AMOUNT_MISMATCH', $audit_values);
|
||||
if ($auth_tid === '' || $auth_tid !== $auth_tid_raw || inicis_pro_idc_host($idc) === '')
|
||||
inicis_pro_return_error('결제 승인 정보가 올바르지 않아 주문을 중단했습니다.', $page_return_url, '', $validation_audit_oid, 'validation', 'validation_failed', 'AUTH_INFO_INVALID', $audit_values);
|
||||
if ($device === '')
|
||||
inicis_pro_return_error('주문 검증정보가 일치하지 않아 주문을 중단했습니다.', $page_return_url, '', $validation_audit_oid, 'validation', 'validation_failed', 'ORDER_SIGNATURE_MISMATCH', $audit_values);
|
||||
// 일반 인증결과에서는 P_TYPE이 생략될 수 있으며 최종 결제수단은 승인결과에서 검증한다.
|
||||
if ($result_type !== '' && !inicis_pro_result_type_matches($settle_case, $result_type))
|
||||
inicis_pro_return_error('결제수단이 주문정보와 일치하지 않아 주문을 중단했습니다.', $page_return_url, '', $validation_audit_oid, 'validation', 'validation_failed', 'PAY_TYPE_MISMATCH', $audit_values);
|
||||
|
||||
inicis_pro_audit_write($oid, 'authentication', 'authentication_received', $audit_values);
|
||||
|
||||
$lock_name = inicis_pro_lock($oid);
|
||||
if ($lock_name === '')
|
||||
inicis_pro_return_error('주문 처리가 진행 중입니다. 잠시 후 주문내역을 확인해 주십시오.', $page_return_url, '', $oid, 'order', 'order_saving', 'ORDER_LOCK_BUSY', $audit_values);
|
||||
|
||||
$exists_order = get_shop_order_data($oid);
|
||||
if (!empty($exists_order['od_tno'])) {
|
||||
inicis_pro_audit_order_saved($oid, $exists_order['od_tno'], 'order', 'system');
|
||||
inicis_pro_unlock($lock_name);
|
||||
set_session('ss_order_id', $oid);
|
||||
exists_inicis_shop_order($oid, array(), $exists_order['od_time'], $exists_order['od_ip']);
|
||||
exit;
|
||||
}
|
||||
$exists_personal = get_shop_order_data($oid, 'personal');
|
||||
if (!empty($exists_personal['pp_tno'])) {
|
||||
inicis_pro_audit_order_saved($oid, $exists_personal['pp_tno'], 'personal', 'system');
|
||||
inicis_pro_unlock($lock_name);
|
||||
set_session('ss_personalpay_id', $oid);
|
||||
set_session('ss_personalpay_hash', md5($exists_personal['pp_id'].$exists_personal['pp_price'].$exists_personal['pp_time']));
|
||||
exists_inicis_shop_order($oid, $exists_personal, $exists_personal['pp_time'], $exists_personal['pp_ip']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$_POST = array();
|
||||
foreach ($order_data as $key => $value) {
|
||||
if (!is_string($key) || !preg_match('/^[A-Za-z0-9_]+$/', $key))
|
||||
continue;
|
||||
$_POST[$key] = inicis_pro_restore_order_value($value, $key === 'od_memo');
|
||||
}
|
||||
|
||||
$_POST['inicis_pro'] = '1';
|
||||
$_POST['inicis_pro_oid'] = $oid;
|
||||
$_POST['res_cd'] = '00';
|
||||
// 모바일 주문/개인결제의 결제등록 완료 확인(P_HASH 존재 여부)을 PRO 흐름에서도 통과시킨다.
|
||||
// 실제 서명값은 승인 완료 후 pay_result.php에서 다시 채워 넣는다.
|
||||
$_POST['P_HASH'] = '1';
|
||||
|
||||
if ($is_personal) {
|
||||
$pp_row = get_shop_order_data($oid, 'personal');
|
||||
if (empty($pp_row['pp_id']))
|
||||
inicis_pro_return_error('개인결제 정보를 확인할 수 없습니다.', $page_return_url, $lock_name, $oid, 'validation', 'validation_failed', 'PERSONALPAY_MISSING', $audit_values);
|
||||
|
||||
set_session('ss_personalpay_id', $oid);
|
||||
set_session('ss_personalpay_hash', md5($pp_row['pp_id'].$pp_row['pp_price'].$pp_row['pp_time']));
|
||||
set_session('ss_order_id', $oid);
|
||||
} else {
|
||||
set_session('ss_order_id', $oid);
|
||||
set_session('ss_order_inicis_id', $oid);
|
||||
set_session('ss_direct', !empty($order_data['sw_direct']) ? 1 : 0);
|
||||
if (!empty($order_data['sw_direct']))
|
||||
set_session('ss_cart_direct', $temp_row['cart_id']);
|
||||
else
|
||||
set_session('ss_cart_id', $temp_row['cart_id']);
|
||||
}
|
||||
|
||||
if (!empty($temp_row['mb_id'])) {
|
||||
$member = get_member($temp_row['mb_id']);
|
||||
$is_member = !empty($member['mb_id']);
|
||||
if (!$is_member)
|
||||
inicis_pro_return_error('주문 회원정보를 확인할 수 없습니다.', $page_return_url, $lock_name, $oid, 'validation', 'validation_failed', 'MEMBER_MISSING', $audit_values);
|
||||
} else {
|
||||
if (!is_array($member))
|
||||
$member = array();
|
||||
$member['mb_id'] = '';
|
||||
$is_member = false;
|
||||
}
|
||||
|
||||
$field_names = shop_order_data_fields($is_personal ? 1 : 0);
|
||||
foreach ($field_names as $field_name)
|
||||
$$field_name = isset($_POST[$field_name]) ? $_POST[$field_name] : '';
|
||||
|
||||
// 승인은 주문 저장 직전(inicis/pro/pay_result.php)에서 실행하도록 필요한 값을 넘긴다.
|
||||
$GLOBALS['inicis_pro_approval_ctx'] = array(
|
||||
'oid' => $oid,
|
||||
'auth_tid' => $auth_tid,
|
||||
'idc' => $idc,
|
||||
'expected_mid' => $expected_mid,
|
||||
'expected_amount' => $expected_amount,
|
||||
'pay_type' => $pay_type,
|
||||
'result_type' => $result_type,
|
||||
'noti' => $noti,
|
||||
'device' => $device,
|
||||
'settle_case' => $settle_case,
|
||||
'is_personal' => $is_personal,
|
||||
'lock_name' => $lock_name,
|
||||
'page_return_url' => $page_return_url,
|
||||
'audit_values' => $audit_values
|
||||
);
|
||||
|
||||
inicis_pro_audit_write($oid, 'order', 'order_saving', $audit_values);
|
||||
|
||||
if ($is_personal) {
|
||||
$pp_id = $oid;
|
||||
$good_mny = $expected_amount;
|
||||
$_POST['pp_id'] = $oid;
|
||||
$_POST['good_mny'] = $expected_amount;
|
||||
if ($device === 'MOBILE')
|
||||
include G5_MSHOP_PATH.'/personalpayformupdate.php';
|
||||
else
|
||||
include G5_SHOP_PATH.'/personalpayformupdate.php';
|
||||
} else {
|
||||
$od_send_cost = isset($_POST['od_send_cost']) ? (int) $_POST['od_send_cost'] : 0;
|
||||
$od_send_cost2 = isset($_POST['od_send_cost2']) ? (int) $_POST['od_send_cost2'] : 0;
|
||||
if ($device === 'MOBILE')
|
||||
include G5_MSHOP_PATH.'/orderformupdate.php';
|
||||
else
|
||||
include G5_SHOP_PATH.'/orderformupdate.php';
|
||||
}
|
||||
|
||||
inicis_pro_unlock($lock_name);
|
||||
exit;
|
||||
Reference in new issue
Block a user