나이스페이 결제수단 추가

This commit is contained in:
thisgun
2024-04-03 10:42:04 +09:00
parent baa114c471
commit 84669cb47f
53 changed files with 2403 additions and 65 deletions

View File

@ -0,0 +1,6 @@
<?php
include_once('../../../common.php');
if (!defined('G5_USE_SHOP') || !G5_USE_SHOP)
die('<p>쇼핑몰 설치 후 이용해 주십시오.</p>');
define('_SHOP_', true);

View File

@ -0,0 +1,2 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

View File

@ -0,0 +1,192 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
// 나이스페이 공통 설정
require_once(G5_MSHOP_PATH.'/settle_nicepay.inc.php');
if (function_exists('add_log')) add_log($_POST);
/*
****************************************************************************************
* <Authentication Result Parameter>
****************************************************************************************
*/
$authResultCode = isset($_POST['AuthResultCode']) ? clean_xss_tags($_POST['AuthResultCode']) : ''; // authentication result code 0000:success
$authResultMsg = isset($_POST['AuthResultMsg']) ? clean_xss_tags($_POST['AuthResultMsg']) : ''; // authentication result message
$nextAppURL = isset($_POST['NextAppURL']) ? clean_xss_tags($_POST['NextAppURL']) : ''; // authorization request URL
$txTid = isset($_POST['TxTid']) ? clean_xss_tags($_POST['TxTid']) : ''; // transaction ID
$authToken = isset($_POST['AuthToken']) ? clean_xss_tags($_POST['AuthToken']) : ''; // authentication TOKEN
$payMethod = isset($_POST['PayMethod']) ? clean_xss_tags($_POST['PayMethod']) : ''; // payment method
$mid = isset($_POST['MID']) ? clean_xss_tags($_POST['MID']) : ''; // merchant id
$moid = isset($_POST['Moid']) ? clean_xss_tags($_POST['Moid']) : ''; // order number
$amt = isset($_POST['Amt']) ? (int) preg_replace('/[^0-9]/', '', $_POST['Amt']) : 0; // Amount of payment
$reqReserved = isset($_POST['ReqReserved']) ? clean_xss_tags($_POST['ReqReserved']) : ''; // mall custom field
$netCancelURL = isset($_POST['NetCancelURL']) ? clean_xss_tags($_POST['NetCancelURL']) : ''; // netCancelURL
if (isset($pp['pp_id']) && $pp['pp_id']) { //개인결제
$session_order_id = get_session('ss_personalpay_id');
$order_price = (int) $pp['pp_price'];
} else {
$session_order_id = get_session('ss_order_id'); // 쇼핑몰 일반결제
}
if ($session_order_id != $moid){
alert("요청한 주문번호가 틀려서 결제를 진행할수 없습니다.\\n다시 장바구니에서 시도해 주세요.", G5_SHOP_URL);
}
if ($default['de_nicepay_mid'] != $mid) {
alert("요청한 상점 mid와 설정된 mid가 틀리므로 결제를 진행할수 없습니다.", G5_SHOP_URL);
}
if ($order_price != $amt) {
alert("요청한 결제금액이 틀리므로 결제를 진행할수 없습니다.", G5_SHOP_URL);
}
// API CALL foreach example
if (! function_exists('jsonRespDump')) {
function jsonRespDump($resp){
$respArr = json_decode($resp);
foreach ( $respArr as $key => $value ){
echo "$key=". $value."<br />";
}
}
}
if (! function_exists('nicepay_res')) {
function nicepay_res($key, $data, $default_val='') {
$response_val = isset($data[$key]) ? $data[$key] : $default_val;
return ($response_val ? $response_val : $default_val);
}
}
/*
****************************************************************************************
* <authorization parameters init>
****************************************************************************************
*/
$response = "";
if($authResultCode === "0000"){
/*
****************************************************************************************
* <Hash encryption> (do not modify)
****************************************************************************************
*/
$ediDate = preg_replace('/[^0-9]/', '', G5_TIME_YMDHIS);
$merchantKey = $default['de_nicepay_key']; // 상점키
$signData = bin2hex(hash('sha256', $authToken . $mid . $amt . $ediDate . $merchantKey, true));
try{
$data = Array(
'TID' => $txTid,
'AuthToken' => $authToken,
'MID' => $mid,
'Amt' => $amt,
'EdiDate' => $ediDate,
'SignData' => $signData,
'CharSet' => 'utf-8'
);
/*
****************************************************************************************
* <authorization request>
* authorization through server to server communication.
****************************************************************************************
// 3001 : 신용카드 성공코드
// 4000 : 계좌이체 성공코드
// 4100 : 가상계좌 발급 성공코드
// A000 : 휴대폰 소액결제 성공코드
// 7001 : 현금영수증
// https://developers.nicepay.co.kr/manual-auth.php
*/
$response = nicepay_reqPost($data, $nextAppURL);
$respArr = json_decode($response, true);
$ResultCode = nicepay_res('ResultCode', $respArr);
$ResultMsg = nicepay_res('ResultMsg', $respArr);
$tno = nicepay_res('TID', $respArr);
$amount = (int) nicepay_res('Amt', $respArr, 0);
$app_time = nicepay_res('AuthDate', $respArr);
$pay_method = nicepay_res('PayMethod', $respArr);
$od_app_no = $app_no = nicepay_res('AuthCode', $respArr); // 승인 번호 (신용카드, 계좌이체, 휴대폰)
$pay_type = $NICEPAY_METHOD[$pay_method];
// 승인된 코드가 아니면 결제가 되지 않게 합니다.
if (! in_array($ResultCode, array('3001', '4000', '4100', 'A000', '7001'))) {
alert($ResultMsg.' 코드 : '.$ResultCode, G5_SHOP_URL);
die();
}
if ($ResultCode == '3001') { // 신용카드
$card_cd = nicepay_res('CardCode', $respArr); // 카드사 코드
$card_name = nicepay_res('CardName', $respArr); // 카드 종류
} else if ($ResultCode == '4100') { // 가상계좌
$bank_name = $bankname = nicepay_res('VbankBankName', $respArr);
$account = nicepay_res('VbankNum', $respArr);
$va_date = nicepay_res('VbankExpDate', $respArr).' '.nicepay_res('VbankExpTime', $respArr); // 가상계좌 입금마감시간
$app_no = nicepay_res('VbankNum', $respArr);
if ($default['de_escrow_use'] == 1)
$escw_yn = 'Y';
} else if ($ResultCode == '4000') { // 계좌이체
$bank_name = $bankname = nicepay_res('BankName', $respArr);
$bank_code = nicepay_res('BankCode', $respArr);
$RcptType = nicepay_res('RcptType', $respArr); // 현금영수증타입 (0:발행안함,1:소득공제,2:지출증빙)
$RcptTID = nicepay_res('RcptTID', $respArr); // 현금영수증 TID, 현금영수증 거래인 경우 리턴
$RcptAuthCode = nicepay_res('RcptAuthCode', $respArr); // 현금영수증 승인번호, 현금영수증 거래인 경우 리턴
$AuthDate = nicepay_res('AuthDate', $respArr); // 현금영수증 승인번호, 현금영수증 거래인 경우 리턴
// 현금영수증 발급시 1 또는 2 이면
if ($RcptType) {
$pg_receipt_infos['od_cash'] = 1; // 현금영수증 발급인것으로 처리
$pg_receipt_infos['od_cash_no'] = $RcptAuthCode; // 현금영수증 승인번호
$pg_receipt_infos['od_cash_info'] = serialize(array('TID'=>$RcptTID, 'ApplNum'=>$RcptAuthCode, 'AuthDate'=>$AuthDate));
}
if ($default['de_escrow_use'] == 1)
$escw_yn = 'Y';
}
$depositor = ''; // 입금할 계좌 예금주 (나이스페이 경우 가상계좌의 예금주명을 리턴받지 못합니다. )
$account = nicepay_res('VbankNum', $respArr);
$commid = ''; // 통신사 코드
$mobile_no = ''; // 휴대폰결제시 휴대폰번호 (나이스페이 경우 결제한 휴대폰번호를 리턴받지 못합니다.)
$card_name = nicepay_res('CardName', $respArr);
} catch(Exception $e) {
$e->getMessage();
$data = Array(
'TID' => $txTid,
'AuthToken' => $authToken,
'MID' => $mid,
'Amt' => $amt,
'EdiDate' => $ediDate,
'SignData' => $signData,
'NetCancel' => '1',
'CharSet' => 'utf-8'
);
/*
*************************************************************************************
* <NET CANCEL>
* If an exception occurs during communication, cancelation is recommended
*************************************************************************************
*/
$response = nicepay_reqPost($data, $netCancelURL);
// jsonRespDump($response);
alert("결제 오류로 더 이상 진행할수 없습니다.");
}
} else {
//When authentication fail
$ResultCode = $authResultCode;
$ResultMsg = $authResultMsg;
alert($ResultMsg.' 실패 코드 : '.$ResultCode);
}

View File

@ -0,0 +1,140 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
?>
<!-- PC payment window only (not required for mobile payment window)-->
<script src="https://web.nicepay.co.kr/v3/webstd/js/nicepay-3.0.js" type="text/javascript"></script>
<script type="text/javascript">
//It is executed when call payment window.
function nicepayStart(f){
if(checkPlatform(window.navigator.userAgent) == "mobile"){
document.sm_form.action = "https://web.nicepay.co.kr/v3/v3Payment.jsp";
document.sm_form.acceptCharset="euc-kr";
document.sm_form.submit();
}else{
goPay(document.sm_form);
}
}
//[PC Only]When pc payment window is closed, nicepay-3.0.js call back nicepaySubmit() function <<'nicepaySubmit()' DO NOT CHANGE>>
function nicepaySubmit(){
document.sm_form.submit();
}
//[PC Only]payment window close function <<'nicepayClose()' DO NOT CHANGE>>
function nicepayClose(){
alert("payment window is closed");
}
//pc, mobile chack script (sample code)
function checkPlatform(ua) {
if(ua === undefined) {
ua = window.navigator.userAgent;
}
ua = ua.toLowerCase();
var platform = {};
var matched = {};
var userPlatform = "pc";
var platform_match = /(ipad)/.exec(ua) || /(ipod)/.exec(ua)
|| /(windows phone)/.exec(ua) || /(iphone)/.exec(ua)
|| /(kindle)/.exec(ua) || /(silk)/.exec(ua) || /(android)/.exec(ua)
|| /(win)/.exec(ua) || /(mac)/.exec(ua) || /(linux)/.exec(ua)
|| /(cros)/.exec(ua) || /(playbook)/.exec(ua)
|| /(bb)/.exec(ua) || /(blackberry)/.exec(ua)
|| [];
matched.platform = platform_match[0] || "";
if(matched.platform) {
platform[matched.platform] = true;
}
if(platform.android || platform.bb || platform.blackberry
|| platform.ipad || platform.iphone
|| platform.ipod || platform.kindle
|| platform.playbook || platform.silk
|| platform["windows phone"]) {
userPlatform = "mobile";
}
if(platform.cros || platform.mac || platform.linux || platform.win) {
userPlatform = "pc";
}
return userPlatform;
}
function nicepay_create_signdata(frm)
{
// 데이터 암호화 처리
var result = true;
$.ajax({
url: g5_url+"/shop/nicepay/createsigndata.php",
type: "POST",
data: {
price : frm.good_mny.value
},
dataType: "json",
async: false,
cache: false,
success: function(data) {
if(data.error == "") {
frm.EdiDate.value = data.ediDate;
frm.SignData.value = data.SignData;
} else {
alert(data.error);
result = false;
}
}
});
return result;
}
</script>
<form name="sm_form" method="post" action="" accept-charset="euc-kr">
<input type="hidden" name="PayMethod" value="CARD">
<input type="hidden" name="GoodsName" value="<?php echo get_text($goods); ?>">
<input type="hidden" name="Amt" value="<?php echo $tot_price; ?>">
<input type="hidden" name="MID" value="<?php echo $default['de_nicepay_mid']; ?>">
<input type="hidden" name="Moid" value="<?php echo $od_id; ?>">
<input type="hidden" name="BuyerName" value="">
<input type="hidden" name="BuyerEmail" value="">
<input type="hidden" name="BuyerTel" value="">
<input type="hidden" name="ReturnURL" value="<?php echo $nicepay_returnURL; ?>">
<input type="hidden" name="VbankExpDate" value="">
<input type="hidden" name="NpLang" value="KO"> <!-- EN:English, CN:Chinese, KO:Korean -->
<input type="hidden" name="GoodsCl" value="1"> <!-- products(1), contents(0)) -->
<input type="hidden" name="TransType" value="<?php echo $default['de_escrow_use'] ? '1' : '0';?>"> <!-- USE escrow false(0)/true(1) -->
<input type="hidden" name="CharSet" value="utf-8"> <!-- Return CharSet -->
<input type="hidden" name="ReqReserved" value=""> <!-- mall custom field -->
<input type="hidden" name="EdiDate" value=""> <!-- YYYYMMDDHHMISS -->
<input type="hidden" name="SignData" value=""> <!-- EncryptData -->
<input type="hidden" name="DirectShowOpt" value="">
<input type="hidden" name="SelectCardCode" value=""> <!-- 카드사 노출 제한, 카드코드 값(ex 비씨:01, 삼성:04) -->
<input type="hidden" name="NicepayReserved" value=""> <!-- 간편결제 (카카오페이에 사용됨) -->
<input type="hidden" name="DirectEasyPay"> <!-- 간편결제 요청 값 (네이버페이에 사용됨) -->
<input type="hidden" name="EasyPayMethod"> <!-- 간편결제 (네이버페이에 사용됨) -->
<input type="hidden" name="EasyPayCardCode"> <!-- 간편결제 카드 코드 -->
<input type="hidden" name="EasyPayQuota"> <!-- 간편결제 할부개월 (3개월일 경우 03 으로 설정) -->
<input type="hidden" name="MultiEasyPayQuota"> <!-- 간편결제 할부개월 다중 설정 옵션 PAYCO와 네이버페이만 가능 -->
<input type="hidden" name="good_mny" value="<?php echo $tot_price; ?>" >
<?php if ($default['de_tax_flag_use']) { ?>
<!-- 필드명:SupplyAmt / 사이즈:12 / 설명:공급가 액 -->
<input type="hidden" name="SupplyAmt" value="<?php echo $comm_tax_mny; ?>"> <!-- 과세금액 -->
<!-- 필드명:GoodsVat / 사이즈:12 / 설명:부가가 치세 -->
<input type="hidden" name="GoodsVat" value="<?php echo $comm_vat_mny; ?>"> <!-- 부가세 -->
<!-- 필드명:ServiceAmt / 사이즈:12 / 설명:봉사료 -->
<input type="hidden" name="ServiceAmt" value="0">
<!-- 필드명:TaxFreeAmt / 사이즈:12 / 설명:면세 금액 -->
<input type="hidden" name="TaxFreeAmt" value="<?php echo $comm_free_mny; ?>">
<input type="hidden" name="comm_tax_mny" value="<?php echo $comm_tax_mny; ?>"> <!-- 과세금액 -->
<input type="hidden" name="comm_vat_mny" value="<?php echo $comm_vat_mny; ?>"> <!-- 부가세 -->
<input type="hidden" name="comm_free_mny" value="<?php echo $comm_free_mny; ?>"> <!-- 비과세 금액 -->
<?php } ?>
</form>

View File

@ -0,0 +1,17 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
?>
<input type="hidden" name="good_mny" value="<?php echo $tot_price ?>" >
<?php if($default['de_tax_flag_use']) { ?>
<input type="hidden" name="comm_tax_mny" value="<?php echo $comm_tax_mny; ?>"> <!-- 과세금액 -->
<input type="hidden" name="comm_vat_mny" value="<?php echo $comm_vat_mny; ?>"> <!-- 부가세 -->
<input type="hidden" name="comm_free_mny" value="<?php echo $comm_free_mny; ?>"> <!-- 비과세 금액 -->
<?php } ?>
<div id="display_pay_button" class="btn_confirm">
<span id="show_req_btn"><input type="button" name="submitChecked" onClick="pay_approval();" value="결제등록" class="btn_submit"></span>
<span id="show_pay_btn" style="display:none;"><input type="button" onClick="forderform_check();" value="주문하기" class="btn_submit"></span>
<a href="<?php echo G5_SHOP_URL; ?>" class="btn_cancel">취소</a>
</div>

View File

@ -0,0 +1,2 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가;

View File

@ -0,0 +1,89 @@
<?php
include_once('./_common.php');
include_once(G5_MSHOP_PATH.'/settle_nicepay.inc.php');
if (function_exists('add_log')) add_log($_POST);
$authResultCode = isset($_POST['AuthResultCode']) ? clean_xss_tags($_POST['AuthResultCode']) : ''; // authentication result code 0000:success
$authResultMsg = isset($_POST['AuthResultMsg']) ? clean_xss_tags($_POST['AuthResultMsg']) : ''; // authentication result message
$mid = isset($_POST['MID']) ? clean_xss_tags($_POST['MID']) : ''; // merchant id
$moid = isset($_POST['Moid']) ? clean_xss_tags($_POST['Moid']) : ''; // order number
$sql = " select * from {$g5['g5_shop_order_data_table']} where od_id = '$moid' ";
$row = sql_fetch($sql);
if (empty($row)) {
die('');
}
$data = unserialize(base64_decode($row['dt_data']));
if(isset($data['pp_id']) && $data['pp_id']) {
$order_action_url = G5_HTTPS_MSHOP_URL.'/personalpayformupdate.php';
$page_return_url = G5_SHOP_URL.'/personalpayform.php?pp_id='.$data['pp_id'];
} else {
$order_action_url = G5_HTTPS_MSHOP_URL.'/orderformupdate.php';
$page_return_url = G5_SHOP_URL.'/orderform.php';
if($_SESSION['ss_direct'])
$page_return_url .= '?sw_direct=1';
}
$params = array();
$var_datas = array();
foreach($data as $key=>$value) {
if(is_array($value)) {
foreach($value as $k=>$v) {
$_POST[$key][$k] = $params[$key][$k] = clean_xss_tags(strip_tags($v));
}
} else {
if(in_array($key, array('od_memo'))){
$_POST[$key] = $params[$key] = clean_xss_tags(strip_tags($value), 0, 0, 0, 0);
} else {
$_POST[$key] = $params[$key] = clean_xss_tags(strip_tags($value));
}
}
}
// 성공했다면
if ($authResultCode === '0000') {
if(isset($data['pp_id']) && $data['pp_id']) { //개인결제
foreach($params as $key=>$value){
if( in_array($key, shop_order_data_fields(1)) ){
$var_datas[$key] = $value;
$$key = $value;
}
}
include_once(G5_MSHOP_PATH.'/personalpayformupdate.php');
} else { //상점주문
foreach($params as $key=>$value){
if( in_array($key, shop_order_data_fields()) ){
$var_datas[$key] = $value;
$$key = $value;
}
}
$od_send_cost = (int) $_POST['od_send_cost'];
$od_send_cost2 = (int) $_POST['od_send_cost2'];
include_once(G5_MSHOP_PATH.'/orderformupdate.php');
}
} else {
// 실패시
alert('오류 : '.$authResultMsg.' 코드 : '.$authResultCode, $page_return_url);
}