나이스페이 결제 검증과 영수증 처리 보강
(cherry picked from commit 8bcd1bcbea25371bd0a5b196b71d2c1b4308479a)
This commit is contained in:
@@ -48,6 +48,14 @@ if ($Signature != $authSignData) {
|
||||
alert("유효성 검증이 틀려서 결제를 진행할수 없습니다.");
|
||||
}
|
||||
|
||||
if (! nicepay_is_allowed_api_url($nextAppURL, array('/webapi/pay_process.jsp'))) {
|
||||
alert("승인 요청 url이 올바르지 않습니다.", G5_SHOP_URL);
|
||||
}
|
||||
|
||||
if (! nicepay_is_allowed_api_url($netCancelURL, array('/webapi/cancel_process.jsp'))) {
|
||||
alert("망취소 요청 url이 올바르지 않습니다.", G5_SHOP_URL);
|
||||
}
|
||||
|
||||
// API CALL foreach example
|
||||
if (! function_exists('jsonRespDump')) {
|
||||
function jsonRespDump($resp){
|
||||
@@ -118,6 +126,8 @@ if($authResultCode === "0000"){
|
||||
$ResultMsg = nicepay_res('ResultMsg', $respArr);
|
||||
$tno = nicepay_res('TID', $respArr);
|
||||
$response_amt = nicepay_res('Amt', $respArr, 0);
|
||||
$response_mid = nicepay_res('MID', $respArr);
|
||||
$response_moid = nicepay_res('Moid', $respArr);
|
||||
$amount = (int) $response_amt;
|
||||
$app_time = nicepay_res('AuthDate', $respArr);
|
||||
$pay_method = nicepay_res('PayMethod', $respArr);
|
||||
@@ -137,6 +147,18 @@ if($authResultCode === "0000"){
|
||||
alert("승인 응답 유효성 검증이 틀려서 결제를 진행할수 없습니다.", G5_SHOP_URL);
|
||||
}
|
||||
|
||||
if ($response_mid != $mid || $response_moid != $moid) {
|
||||
if($amount > 0) {
|
||||
$od_id = $moid;
|
||||
$cancel_msg = '승인 응답 주문정보 불일치';
|
||||
$cancelAmt = $amount;
|
||||
$partialCancelCode = 0;
|
||||
include G5_SHOP_PATH.'/nicepay/cancel_process.php';
|
||||
}
|
||||
|
||||
alert("승인 응답 주문정보가 틀려서 결제를 진행할수 없습니다.", G5_SHOP_URL);
|
||||
}
|
||||
|
||||
if ($amount != $order_price) {
|
||||
if($amount > 0) {
|
||||
$od_id = $moid;
|
||||
|
||||
@@ -352,6 +352,13 @@ $order_price = $tot_od_price + $send_cost + $send_cost2 - $tot_sc_cp_price - $od
|
||||
$od_status = '주문';
|
||||
$od_tno = '';
|
||||
|
||||
// PG사의 가상계좌 또는 계좌이체의 자동 현금영수증 초기배열값
|
||||
$pg_receipt_infos = array(
|
||||
'od_cash' => 0,
|
||||
'od_cash_no' => '',
|
||||
'od_cash_info' => '',
|
||||
);
|
||||
|
||||
if (function_exists('check_payment_method')) {
|
||||
check_payment_method($od_settle_case);
|
||||
}
|
||||
@@ -699,6 +706,9 @@ $sql = " insert {$g5['g5_shop_order_table']}
|
||||
od_ip = '$REMOTE_ADDR',
|
||||
od_settle_case = '$od_settle_case',
|
||||
od_other_pay_type = '$od_other_pay_type',
|
||||
od_cash = '{$pg_receipt_infos['od_cash']}',
|
||||
od_cash_no = '{$pg_receipt_infos['od_cash_no']}',
|
||||
od_cash_info = '{$pg_receipt_infos['od_cash_info']}',
|
||||
od_test = '{$default['de_card_test']}'
|
||||
";
|
||||
$result = sql_query($sql, false);
|
||||
|
||||
@@ -438,13 +438,17 @@ if($od['od_pg'] == 'lg') {
|
||||
$cash_receipt_script = 'javascript:showCashReceipts(\''.$LGD_MID.'\',\''.$od['od_id'].'\',\''.$od['od_casseqno'].'\',\''.$trade_type.'\',\''.$CST_PLATFORM.'\');';
|
||||
} else if($od['od_pg'] == 'toss') {
|
||||
$cash_receipt_script = 'window.open(\'https://dashboard.tosspayments.com/receipt/mids/si_'.$config['cf_lg_mid'].'/orders/'.$od['od_id'].'/cash-receipt?ref=dashboard\',\'receipt\',\'width=430,height=700\');';
|
||||
} else if($od['od_pg'] == 'inicis') {
|
||||
$cash = unserialize($od['od_cash_info']);
|
||||
$cash_receipt_script = 'window.open(\'https://iniweb.inicis.com/DefaultWebApp/mall/cr/cm/Cash_mCmReceipt.jsp?noTid='.$cash['TID'].'&clpaymethod=22\',\'showreceipt\',\'width=380,height=540,scrollbars=no,resizable=no\');';
|
||||
} else if($od['od_pg'] == 'nicepay') {
|
||||
$cash_receipt_script = 'window.open(\'https://npg.nicepay.co.kr/issue/IssueLoader.do?type=1&TID='.$od['od_tno'].'&noMethod=1\',\'receipt\',\'width=430,height=700\');';
|
||||
} else {
|
||||
require_once G5_SHOP_PATH.'/settle_kcp.inc.php';
|
||||
} else if($od['od_pg'] == 'inicis') {
|
||||
$cash = unserialize($od['od_cash_info']);
|
||||
$cash_receipt_script = 'window.open(\'https://iniweb.inicis.com/DefaultWebApp/mall/cr/cm/Cash_mCmReceipt.jsp?noTid='.$cash['TID'].'&clpaymethod=22\',\'showreceipt\',\'width=380,height=540,scrollbars=no,resizable=no\');';
|
||||
} else if($od['od_pg'] == 'nicepay') {
|
||||
$cash = $od['od_cash_info'] ? unserialize($od['od_cash_info']) : array();
|
||||
if(!is_array($cash))
|
||||
$cash = array();
|
||||
$cash_tid = isset($cash['TID']) && $cash['TID'] ? $cash['TID'] : $od['od_tno'];
|
||||
$cash_receipt_script = 'window.open(\'https://npg.nicepay.co.kr/issue/IssueLoader.do?type=1&TID='.$cash_tid.'&noMethod=1\',\'receipt\',\'width=430,height=700\');';
|
||||
} else {
|
||||
require_once G5_SHOP_PATH.'/settle_kcp.inc.php';
|
||||
|
||||
$cash = unserialize($od['od_cash_info']);
|
||||
$cash_receipt_script = 'window.open(\''.G5_CASH_RECEIPT_URL.$default['de_kcp_mid'].'&orderid='.$od_id.'&bill_yn=Y&authno='.$cash['receipt_no'].'\', \'taxsave_receipt\', \'width=360,height=647,scrollbars=0,menus=0\');';
|
||||
|
||||
@@ -232,7 +232,11 @@ if($pp['pp_pg'] == 'lg') {
|
||||
$cash = unserialize($pp['pp_cash_info']);
|
||||
$cash_receipt_script = 'window.open(\'https://iniweb.inicis.com/DefaultWebApp/mall/cr/cm/Cash_mCmReceipt.jsp?noTid='.$cash['TID'].'&clpaymethod=22\',\'showreceipt\',\'width=380,height=540,scrollbars=no,resizable=no\');';
|
||||
} else if($pp['pp_pg'] == 'nicepay') {
|
||||
$cash_receipt_script = 'window.open(\'https://npg.nicepay.co.kr/issue/IssueLoader.do?type=1&TID='.$od['od_tno'].'&noMethod=1\',\'receipt\',\'width=430,height=700\');';
|
||||
$cash = $pp['pp_cash_info'] ? unserialize($pp['pp_cash_info']) : array();
|
||||
if(!is_array($cash))
|
||||
$cash = array();
|
||||
$cash_tid = isset($cash['TID']) && $cash['TID'] ? $cash['TID'] : $pp['pp_tno'];
|
||||
$cash_receipt_script = 'window.open(\'https://npg.nicepay.co.kr/issue/IssueLoader.do?type=1&TID='.$cash_tid.'&noMethod=1\',\'receipt\',\'width=430,height=700\');';
|
||||
} else {
|
||||
require_once G5_SHOP_PATH.'/settle_kcp.inc.php';
|
||||
|
||||
@@ -326,4 +330,4 @@ if($pp['pp_pg'] == 'lg') {
|
||||
<!-- } 개인결제상세내역 끝 -->
|
||||
|
||||
<?php
|
||||
include_once(G5_MSHOP_PATH.'/_tail.php');
|
||||
include_once(G5_MSHOP_PATH.'/_tail.php');
|
||||
|
||||
@@ -44,12 +44,20 @@ if ($order_price != $amt) {
|
||||
// hex(sha256(AuthToken+MID+Amt+MerchantKey)), 위변조 검증 데이터
|
||||
$signData = bin2hex(hash('sha256', $authToken. $default['de_nicepay_mid'] . $order_price . $default['de_nicepay_key'], true));
|
||||
|
||||
if ($Signature != $signData) {
|
||||
alert("유효성 검증이 틀려서 결제를 진행할수 없습니다.");
|
||||
}
|
||||
|
||||
// API CALL foreach example
|
||||
function jsonRespDump($resp){
|
||||
if ($Signature != $signData) {
|
||||
alert("유효성 검증이 틀려서 결제를 진행할수 없습니다.");
|
||||
}
|
||||
|
||||
if (! nicepay_is_allowed_api_url($nextAppURL, array('/webapi/pay_process.jsp'))) {
|
||||
alert("승인 요청 url이 올바르지 않습니다.", G5_SHOP_URL);
|
||||
}
|
||||
|
||||
if (! nicepay_is_allowed_api_url($netCancelURL, array('/webapi/cancel_process.jsp'))) {
|
||||
alert("망취소 요청 url이 올바르지 않습니다.", G5_SHOP_URL);
|
||||
}
|
||||
|
||||
// API CALL foreach example
|
||||
function jsonRespDump($resp){
|
||||
$respArr = json_decode($resp);
|
||||
foreach ( $respArr as $key => $value ){
|
||||
echo "$key=". $value."<br />";
|
||||
@@ -113,9 +121,11 @@ if($authResultCode === "0000"){
|
||||
$respArr = json_decode($response, true);
|
||||
|
||||
$ResultCode = nicepay_res('ResultCode', $respArr);
|
||||
$ResultMsg = nicepay_res('ResultMsg', $respArr);
|
||||
$ResultMsg = nicepay_res('ResultMsg', $respArr);
|
||||
$tno = nicepay_res('TID', $respArr);
|
||||
$response_amt = nicepay_res('Amt', $respArr, 0);
|
||||
$response_mid = nicepay_res('MID', $respArr);
|
||||
$response_moid = nicepay_res('Moid', $respArr);
|
||||
$amount = (int) $response_amt;
|
||||
$app_time = nicepay_res('AuthDate', $respArr);
|
||||
$pay_method = nicepay_res('PayMethod', $respArr);
|
||||
@@ -135,6 +145,18 @@ if($authResultCode === "0000"){
|
||||
alert("승인 응답 유효성 검증이 틀려서 결제를 진행할수 없습니다.", G5_SHOP_URL);
|
||||
}
|
||||
|
||||
if ($response_mid != $mid || $response_moid != $moid) {
|
||||
if($amount > 0) {
|
||||
$od_id = $moid;
|
||||
$cancel_msg = '승인 응답 주문정보 불일치';
|
||||
$cancelAmt = $amount;
|
||||
$partialCancelCode = 0;
|
||||
include G5_SHOP_PATH.'/nicepay/cancel_process.php';
|
||||
}
|
||||
|
||||
alert("승인 응답 주문정보가 틀려서 결제를 진행할수 없습니다.", G5_SHOP_URL);
|
||||
}
|
||||
|
||||
if ($amount != $order_price) {
|
||||
if($amount > 0) {
|
||||
$od_id = $moid;
|
||||
|
||||
@@ -437,13 +437,17 @@ if($od['od_pg'] == 'lg') {
|
||||
$cash_receipt_script = 'javascript:showCashReceipts(\''.$LGD_MID.'\',\''.$od['od_id'].'\',\''.$od['od_casseqno'].'\',\''.$trade_type.'\',\''.$CST_PLATFORM.'\');';
|
||||
} else if($od['od_pg'] == 'toss') {
|
||||
$cash_receipt_script = 'window.open(\'https://dashboard.tosspayments.com/receipt/mids/si_'.$config['cf_lg_mid'].'/orders/'.$od['od_id'].'/cash-receipt?ref=dashboard\',\'receipt\',\'width=430,height=700\');';
|
||||
} else if($od['od_pg'] == 'inicis') {
|
||||
$cash = unserialize($od['od_cash_info']);
|
||||
$cash_receipt_script = 'window.open(\'https://iniweb.inicis.com/DefaultWebApp/mall/cr/cm/Cash_mCmReceipt.jsp?noTid='.$cash['TID'].'&clpaymethod=22\',\'showreceipt\',\'width=380,height=540,scrollbars=no,resizable=no\');';
|
||||
} else if($od['od_pg'] == 'nicepay') {
|
||||
$cash_receipt_script = 'window.open(\'https://npg.nicepay.co.kr/issue/IssueLoader.do?type=1&TID='.$od['od_tno'].'&noMethod=1\',\'receipt\',\'width=430,height=700\');';
|
||||
} else {
|
||||
require_once G5_SHOP_PATH.'/settle_kcp.inc.php';
|
||||
} else if($od['od_pg'] == 'inicis') {
|
||||
$cash = unserialize($od['od_cash_info']);
|
||||
$cash_receipt_script = 'window.open(\'https://iniweb.inicis.com/DefaultWebApp/mall/cr/cm/Cash_mCmReceipt.jsp?noTid='.$cash['TID'].'&clpaymethod=22\',\'showreceipt\',\'width=380,height=540,scrollbars=no,resizable=no\');';
|
||||
} else if($od['od_pg'] == 'nicepay') {
|
||||
$cash = $od['od_cash_info'] ? unserialize($od['od_cash_info']) : array();
|
||||
if(!is_array($cash))
|
||||
$cash = array();
|
||||
$cash_tid = isset($cash['TID']) && $cash['TID'] ? $cash['TID'] : $od['od_tno'];
|
||||
$cash_receipt_script = 'window.open(\'https://npg.nicepay.co.kr/issue/IssueLoader.do?type=1&TID='.$cash_tid.'&noMethod=1\',\'receipt\',\'width=430,height=700\');';
|
||||
} else {
|
||||
require_once G5_SHOP_PATH.'/settle_kcp.inc.php';
|
||||
|
||||
$cash = unserialize($od['od_cash_info']);
|
||||
$cash_receipt_script = 'window.open(\''.G5_CASH_RECEIPT_URL.$default['de_kcp_mid'].'&orderid='.$od_id.'&bill_yn=Y&authno='.$cash['receipt_no'].'\', \'taxsave_receipt\', \'width=360,height=647,scrollbars=0,menus=0\');';
|
||||
|
||||
@@ -236,7 +236,11 @@ if($pp['pp_pg'] == 'lg') {
|
||||
$cash = unserialize($pp['pp_cash_info']);
|
||||
$cash_receipt_script = 'window.open(\'https://iniweb.inicis.com/DefaultWebApp/mall/cr/cm/Cash_mCmReceipt.jsp?noTid='.$cash['TID'].'&clpaymethod=22\',\'showreceipt\',\'width=380,height=540,scrollbars=no,resizable=no\');';
|
||||
} else if($pp['pp_pg'] == 'nicepay') {
|
||||
$cash_receipt_script = 'window.open(\'https://npg.nicepay.co.kr/issue/IssueLoader.do?type=1&TID='.$od['od_tno'].'&noMethod=1\',\'receipt\',\'width=430,height=700\');';
|
||||
$cash = $pp['pp_cash_info'] ? unserialize($pp['pp_cash_info']) : array();
|
||||
if(!is_array($cash))
|
||||
$cash = array();
|
||||
$cash_tid = isset($cash['TID']) && $cash['TID'] ? $cash['TID'] : $pp['pp_tno'];
|
||||
$cash_receipt_script = 'window.open(\'https://npg.nicepay.co.kr/issue/IssueLoader.do?type=1&TID='.$cash_tid.'&noMethod=1\',\'receipt\',\'width=430,height=700\');';
|
||||
} else {
|
||||
require_once G5_SHOP_PATH.'/settle_kcp.inc.php';
|
||||
|
||||
@@ -330,4 +334,4 @@ if($pp['pp_pg'] == 'lg') {
|
||||
<!-- } 개인결제상세내역 끝 -->
|
||||
|
||||
<?php
|
||||
include_once('./_tail.php');
|
||||
include_once('./_tail.php');
|
||||
|
||||
@@ -52,7 +52,7 @@ if (! function_exists('nicepay_reqPost')) {
|
||||
$url_data = parse_url($url);
|
||||
|
||||
// 나이스페이 url이 맞는지 체크하여 틀리면 false를 리턴합니다.
|
||||
if (! (isset($url_data['host']) && preg_match('#\.nicepay\.co\.kr$#i', $url_data['host']))) {
|
||||
if (! (isset($url_data['scheme']) && strtolower($url_data['scheme']) === 'https' && isset($url_data['host']) && preg_match('#\.nicepay\.co\.kr$#i', $url_data['host']))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,29 @@ if (! function_exists('nicepay_reqPost')) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //POST data
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('nicepay_is_allowed_api_url')) {
|
||||
function nicepay_is_allowed_api_url($url, $allowed_paths)
|
||||
{
|
||||
$url_data = parse_url($url);
|
||||
|
||||
if (! (isset($url_data['scheme']) && strtolower($url_data['scheme']) === 'https' && isset($url_data['host']) && isset($url_data['path']))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$host = strtolower($url_data['host']);
|
||||
$path = $url_data['path'];
|
||||
$allowed_hosts = array(
|
||||
'dc1-api.nicepay.co.kr',
|
||||
'dc2-api.nicepay.co.kr',
|
||||
'pg-api.nicepay.co.kr',
|
||||
'webapi.nicepay.co.kr'
|
||||
);
|
||||
|
||||
return in_array($host, $allowed_hosts) && in_array($path, $allowed_paths);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ if (in_array($_SERVER['REMOTE_ADDR'], $pg_allow_ips)) {
|
||||
// 입금통보 코드가 4110 성공이면
|
||||
if ($ResultCode === '4110') {
|
||||
// 입금결과 처리
|
||||
$sql = " select pp_id, od_id, pp_price, pp_receipt_price from {$g5['g5_shop_personalpay_table']} where pp_id = '$MOID' and pp_app_no = '$VbankNum' ";
|
||||
$sql = " select pp_id, od_id, pp_price, pp_receipt_price from {$g5['g5_shop_personalpay_table']} where pp_id = '$MOID' and pp_app_no = '$VbankNum' and pp_tno = '$TID' ";
|
||||
$row = sql_fetch($sql);
|
||||
|
||||
$result = false;
|
||||
@@ -97,20 +97,25 @@ if (in_array($_SERVER['REMOTE_ADDR'], $pg_allow_ips)) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$sql = " select od_id, od_misu
|
||||
$sql = " select od_id, od_misu, od_receipt_price
|
||||
from {$g5['g5_shop_order_table']}
|
||||
where od_id = '$MOID'
|
||||
and od_app_no = '$VbankNum' ";
|
||||
and od_app_no = '$VbankNum'
|
||||
and od_tno = '$TID' ";
|
||||
$od_row = sql_fetch($sql);
|
||||
|
||||
if(isset($od_row['od_id']) && $od_row['od_id'] && (int)$od_row['od_misu'] === $Amt) {
|
||||
// 주문서 UPDATE
|
||||
$sql = " update {$g5['g5_shop_order_table']}
|
||||
set od_receipt_price = '$Amt',
|
||||
od_receipt_time = '$receipt_time'
|
||||
where od_id = '$MOID'
|
||||
and od_app_no = '$VbankNum' ";
|
||||
$result = sql_query($sql, FALSE);
|
||||
if(isset($od_row['od_id']) && $od_row['od_id']) {
|
||||
if((int)$od_row['od_misu'] === $Amt) {
|
||||
// 주문서 UPDATE
|
||||
$sql = " update {$g5['g5_shop_order_table']}
|
||||
set od_receipt_price = '$Amt',
|
||||
od_receipt_time = '$receipt_time'
|
||||
where od_id = '$MOID'
|
||||
and od_app_no = '$VbankNum' ";
|
||||
$result = sql_query($sql, FALSE);
|
||||
} else if((int)$od_row['od_receipt_price'] === $Amt && (int)$od_row['od_misu'] === 0) {
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user