나이스페이 결제수단 추가

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

2
shop/nicepay/_common.php Normal file
View File

@ -0,0 +1,2 @@
<?php
include_once('../../common.php');

View File

@ -0,0 +1,57 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
/*
****************************************************************************************
* <Cancel Request Parameter>
* The sample page only shows basic (required) parameters.
****************************************************************************************
*/
$merchantKey = $default['de_nicepay_key'];
$mid = $default['de_nicepay_mid'];
$moid = isset($od_id) ? $od_id : get_session('ss_order_id');
$cancelMsg = $cancel_msg;
$tid = $tno;
$partialCancelCode = isset($partialCancelCode) ? (int) $partialCancelCode : 0;
/*
****************************************************************************************
* <Hash encryption> (do not modify)
* SHA-256 hash encryption is a way to prevent forgery.
****************************************************************************************
*/
$ediDate = preg_replace('/[^0-9]/', '', G5_TIME_YMDHIS);
$signData = bin2hex(hash('sha256', $mid . $cancelAmt . $ediDate . $merchantKey, true));
try{
$data = Array(
'TID' => $tid,
'MID' => $mid,
'Moid' => $moid,
'CancelAmt' => $cancelAmt,
'CancelMsg' => iconv("UTF-8", "EUC-KR", $cancelMsg),
'PartialCancelCode' => $partialCancelCode,
'EdiDate' => $ediDate,
'SignData' => $signData,
'CharSet' => 'utf-8'
);
if (function_exists('add_log')) add_log($data);
/*
****************************************************************************************
* <Cancel Request>
****************************************************************************************
*/
$response = nicepay_reqPost($data, "https://pg-api.nicepay.co.kr/webapi/cancel_process.jsp"); //Cancel API call
$result = json_decode($response, true);
if (function_exists('add_log')) add_log(array('1'=>1));
if (function_exists('add_log')) add_log($result, true, 'cc');
}catch(Exception $e){
$e->getMessage();
$ResultCode = "9999";
$ResultMsg = "통신실패";
}

View File

@ -0,0 +1,26 @@
<?php
include_once('./_common.php');
include_once(G5_SHOP_PATH.'/settle_nicepay.inc.php');
$orderNumber = get_session('ss_order_id');
if (! $orderNumber) {
$orderNumber = get_session('ss_personalpay_id');
}
if (! ($default['de_pg_service'] == 'nicepay' && $orderNumber)){
die(json_encode(array('error'=>'올바른 방법으로 이용해 주십시오.')));
}
if (function_exists('add_log')) add_log($_POST, false, 'ajax');
$price = preg_replace('#[^0-9]#', '', $_POST['price']);
if (strlen($price) < 1) {
die(json_encode(array('error'=>'가격이 올바르지 않습니다.')));
}
$ediDate = preg_replace('/[^0-9]/', '', G5_TIME_YMDHIS);
$hashString = bin2hex(hash('sha256', $ediDate.$default['de_nicepay_mid'].$price.$default['de_nicepay_key'], true));
die(json_encode(array('error'=>'', 'ediDate'=>$ediDate, 'SignData'=>$hashString)));

View File

@ -0,0 +1,77 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if($od['od_pg'] != 'nicepay') return;
include_once(G5_SHOP_PATH.'/settle_nicepay.inc.php');
$mid = $default['de_nicepay_mid'];
$tid = $escrow_tno; // 거래 번호
$reqType = '03'; // 요청타입 (배송등록 03)
$deliveryCoNm = $escrow_corp; // 배송업체명
$buyerAddr = $od['od_b_addr1'].($od['od_b_addr2'] ? ' ' : '').$od['od_b_addr2']; // 배송지 주소
$invoiceNum = $escrow_numb; // 송장번호
$registerName = $default['de_admin_company_name']; // 등록자이름 (영카트 회사명으로 지정)
$confirmMail = 1; // 구매결정 메일발송 여부 (1은 발송, 2는 미발송)
$charSet = 'utf-8'; // 응답파라미터 인코딩 방식
$escrowRequestURL = "https://webapi.nicepay.co.kr/webapi/escrow_process.jsp"; //에스크로 요청 URL
/*
*******************************************************
* <해쉬암호화> (수정하지 마세요)
* SHA-256 해쉬암호화는 거래 위변조를 막기위한 방법입니다.
*******************************************************
*/
$ediDate = preg_replace('/[^0-9]/', '', G5_TIME_YMDHIS);
$signData = bin2hex(hash('sha256', $tid.$mid.$reqType.$ediDate.$default['de_nicepay_key'], true));
$response = "";
$data = array(
'MID' => $mid,
'TID' => $tid,
'EdiDate' => $ediDate,
'SignData' => $signData,
'ReqType' => $reqType,
'DeliveryCoNm' => $deliveryCoNm,
'BuyerAddr' => $buyerAddr,
'InvoiceNum' => $invoiceNum,
'RegisterName' => $registerName,
'ConfirmMail' => $confirmMail,
'CharSet' => $charSet
);
$response = nicepay_reqPost($data, $escrowRequestURL);
$nice_result = json_decode($response, true);
if (function_exists('add_log')) add_log($nice_result, true, 'es');
// 성공이면
if (isset($nice_result['ResultCode']) && $nice_result['ResultCode'] === 'C000') {
} else {
// C000 이 아니면 다 실패
/*
C002 에스크로 가맹점 아님
C003 에스크로 거래만 배송등록 가능
C004 에스크로결제 신청내역 미존재
C005 에스크로배송등록 불가상태
C006 거래내역이 존재하지 않음.
C007 취소된 거래는 배송등록 불가
*/
}
/**********************
* 4. 배송 등록 결과 *
**********************/
$resultCode = $nice_result['ResultCode']; // 결과코드 ("00"이면 지불 성공)
$resultMsg = $nice_result['ResultMsg']; // 결과내용 (지불결과에 대한 설명)
$dlv_date = $nice_result['ProcessDate'];
$dlv_time = $nice_result['ProcessTime'];
echo "에스크로배송";
exit;

0
shop/nicepay/index.php Normal file
View File

View File

@ -0,0 +1,204 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
// 나이스페이 공통 설정
require_once(G5_SHOP_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
$Signature = isset($_POST['Signature']) ? clean_xss_tags($_POST['Signature']) : ''; // 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);
}
// 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){
$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);
if (! $response) {
alert('응답이 없거나 잘못된 url 입니다.', G5_SHOP_URL);
}
$respArr = json_decode($response, true);
if (function_exists('add_log')) add_log($respArr);
$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,98 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
// kcp 전자결제를 사용할 때만 실행
if($default['de_iche_use'] || $default['de_vbank_use'] || $default['de_hp_use'] || $default['de_card_use'] || $default['de_easy_pay_use']) {
?>
<!-- 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(){
if(checkPlatform(window.navigator.userAgent) == "mobile"){
document.forderform.action = "https://web.nicepay.co.kr/v3/v3Payment.jsp";
document.forderform.acceptCharset="euc-kr";
document.forderform.submit();
}else{
goPay(document.forderform);
}
}
//[PC Only]When pc payment window is closed, nicepay-3.0.js call back nicepaySubmit() function <<'nicepaySubmit()' DO NOT CHANGE>>
function nicepaySubmit(){
document.forderform.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>
<?php }

View File

@ -0,0 +1,49 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
?>
<input type="hidden" name="PayMethod" value="">
<input type="hidden" name="GoodsName" value="<?php echo get_text($goods); ?>">
<?php /* 주문폼 자바스크립트 에러 방지를 위해 추가함 */ ?>
<input type="hidden" name="good_mny" value="<?php echo $tot_price; ?>">
<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와 네이버페이만 가능 -->
<?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 } ?>
<?php
/*
<input type="hidden" name="SelectQuota" value=""> <!-- 할부개월 제한, 일시불 : 00 으로 설정하며, 2 자리로 설정(ex:03) -->
*/
?>

View File

@ -0,0 +1,12 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
?>
<div id="display_pay_button" class="btn_confirm">
<input type="button" value="주문하기" onclick="forderform_check(this.form);" class="btn_submit">
<a href="javascript:history.go(-1);" class="btn01">취소</a>
</div>
<div id="display_pay_process" style="display:none">
<img src="<?php echo G5_URL; ?>/shop/img/loading.gif" alt="">
<span>주문완료 중입니다. 잠시만 기다려 주십시오.</span>
</div>

View File

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

View File

@ -0,0 +1,61 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if($od['od_pg'] != 'nicepay') return;
include_once(G5_SHOP_PATH.'/settle_nicepay.inc.php');
$od_id = $od['od_id'];
$tno = $od['od_tno'];
$partialCancelCode = 1;
$cancel_msg = $mod_memo; //취소사유
$cancelAmt = (int)$tax_mny + (int)$free_mny;
include G5_SHOP_PATH.'/nicepay/cancel_process.php';
$pg_res_cd = '';
$pg_res_msg = '';
$is_save_history = true;
if (isset($result['ResultCode'])) {
// nicepay 의 경우
if ($result['ResultCode'] === '2001' || $result['ResultCode'] === '2211') {
$add_memo_sql = '';
if ($is_save_history) {
// 환불금액기록
$mod_history = G5_TIME_YMDHIS.' '.$member['mb_id'].' 부분취소 ('.$cancelAmt.') 처리, 잔액 ('.$result['RemainAmt'].")\n";
$add_memo_sql = ", od_shop_memo = concat(od_shop_memo, \"$mod_history\") ";
}
$sql = " update {$g5['g5_shop_order_table']}
set od_refund_price = od_refund_price + '$cancelAmt'
$add_memo_sql
where od_id = '{$od['od_id']}'
and od_tno = '$tno' ";
sql_query($sql);
// 미수금 등의 정보 업데이트
$info = get_order_info($od_id);
$sql = " update {$g5['g5_shop_order_table']}
set od_misu = '{$info['od_misu']}',
od_tax_mny = '{$info['od_tax_mny']}',
od_vat_mny = '{$info['od_vat_mny']}',
od_free_mny = '{$info['od_free_mny']}'
where od_id = '$od_id' ";
sql_query($sql);
} else {
$pg_res_cd = $result['ResultCode'];
$pg_res_msg = $result['ResultMsg'];
}
} else {
$pg_res_cd = '';
$pg_res_msg = 'curl 로 데이터를 받지 못했습니다.';
}
if ($pg_res_msg) {
alert('결제 부분취소 요청이 실패하였습니다.\\n\\n'.$pg_res_cd.' : '.$pg_res_msg);
}

View File

@ -0,0 +1,203 @@
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
?>
<script>
// 현금영수증 MAIN FUNC
function jsf__pay_cash( form )
{
jsf__show_progress(true);
if ( jsf__chk_cash( form ) == false )
{
jsf__show_progress(false);
return;
}
form.submit();
}
// 진행 바
function jsf__show_progress( show )
{
if ( show == true )
{
window.show_pay_btn.style.display = "none";
window.show_progress.style.display = "inline";
}
else
{
window.show_pay_btn.style.display = "inline";
window.show_progress.style.display = "none";
}
}
// 포맷 체크
function jsf__chk_cash( form )
{
if ( form.tr_code[0].checked )
{
if ( form.id_info.value.length != 10 &&
form.id_info.value.length != 11 &&
form.id_info.value.length != 13 )
{
alert("주민번호 또는 휴대폰번호를 정확히 입력해 주시기 바랍니다.");
form.id_info.select();
form.id_info.focus();
return false;
}
}
else if ( form.tr_code[1].checked )
{
if ( form.id_info.value.length != 10 )
{
alert("사업자번호를 정확히 입력해 주시기 바랍니다.");
form.id_info.select();
form.id_info.focus();
return false;
}
}
return true;
}
function jsf__chk_tr_code( form )
{
var span_tr_code_0 = document.getElementById( "span_tr_code_0" );
var span_tr_code_1 = document.getElementById( "span_tr_code_1" );
if ( form.tr_code[0].checked )
{
span_tr_code_0.style.display = "inline";
span_tr_code_1.style.display = "none";
}
else if (form.tr_code[1].checked )
{
span_tr_code_0.style.display = "none";
span_tr_code_1.style.display = "inline";
}
}
</script>
<div id="scash" class="new_win">
<h1 id="win_title"><?php echo $g5['title']; ?></h1>
<section>
<h2>주문정보</h2>
<div class="tbl_head01 tbl_wrap">
<table>
<colgroup>
<col class="grid_3">
<col>
</colgroup>
<tbody>
<tr>
<th scope="row">주문 번호</th>
<td><?php echo $od_id; ?></td>
</tr>
<tr>
<th scope="row">상품 정보</th>
<td><?php echo $goods_name; ?></td>
</tr>
<tr>
<th scope="row">주문자 이름</th>
<td><?php echo $od_name; ?></td>
</tr>
<tr>
<th scope="row">주문자 E-Mail</th>
<td><?php echo $od_email; ?></td>
</tr>
<tr>
<th scope="row">주문자 전화번호</th>
<td><?php echo $od_tel; ?></td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2>현금영수증 발급 정보</h2>
<form method="post" action="<?php echo G5_SHOP_URL; ?>/nicepay/taxsave_result.php">
<input type="hidden" name="tx" value="<?php echo $tx; ?>">
<input type="hidden" name="od_id" value="<?php echo $od_id; ?>">
<div class="tbl_head01 tbl_wrap">
<table>
<colgroup>
<col class="grid_3">
<col>
</colgroup>
<tbody>
<tr>
<th scope="row">원 거래 시각</th>
<td><?php echo $trad_time; ?></td>
</tr>
<tr>
<th scope="row">발행 용도</th>
<td>
<input type="radio" name="tr_code" value="1" id="tr_code1" onClick="jsf__chk_tr_code( this.form )" checked>
<label for="tr_code1">개인 소득공제용</label>
<input type="radio" name="tr_code" value="2" id="tr_code2" onClick="jsf__chk_tr_code( this.form )">
<label for="tr_code2">사업자 지출증빙용</label>
</td>
</tr>
<tr>
<th scope="row">
<label for="id_info">
<span id="span_tr_code_0" style="display:inline">주민(휴대폰)번호</span>
<span id="span_tr_code_1" style="display:none">사업자번호</span>
</label>
</th>
<td>
<input type="text" name="id_info" id="id_info" class="frm_input" size="16" maxlength="13"> ("-" 생략)
</td>
</tr>
<tr>
<th scope="row"><label for="buyeremail">이메일</label></th>
<td><input type="text" name="buyeremail" id="buyeremail" value="<?php echo $od_email; ?>" required class="required frm_input" size="30"></td>
</tr>
<tr>
<th scope="row"><label for="buyertel">휴대폰</label></th>
<td><input type="text" name="buyertel" id="buyertel" value="" required class="required frm_input" size="20"></td>
</tr>
<tr>
<th scope="row">거래금액 총합</th>
<td><?php echo number_format($amt_tot); ?>원</td>
</tr>
<tr>
<th scope="row">공급가액</th>
<td><?php echo number_format($amt_sup); ?>원<!-- ((거래금액 총합 * 10) / 11) --></td>
</tr>
<tr>
<th scope="row">부가가치세</th>
<td><?php echo number_format($amt_tax); ?>원<!-- 거래금액 총합 - 공급가액 - 봉사료 --></td>
</tr>
<?php if ($amt_free) { ?>
<tr>
<th scope="row">비과세공급가액</th>
<td><?php echo number_format($amt_free); ?>원</td>
</tr>
<?php } ?>
<tr>
<th scope="row">봉사료</th>
<td><?php echo number_format($amt_svc); ?>원</td>
</tr>
</tbody>
</table>
</div>
<div id="scash_apply">
<span id="show_pay_btn">
<button type="button" onclick="jsf__pay_cash( this.form )">등록요청</button>
</span>
<span id="show_progress" style="display:none">
<b>등록 진행중입니다. 잠시만 기다려주십시오</b>
</span>
</div>
</form>
</section>
</div>

View File

@ -0,0 +1,185 @@
<?php
include_once('./_common.php');
include_once(G5_SHOP_PATH.'/settle_nicepay.inc.php');
/*
*
* 현금결제(실시간 은행계좌이체, 무통장입금)에 대한 현금결제 영수증 발행 요청한다.
*
*/
if($tx == 'personalpay') {
$od = sql_fetch(" select * from {$g5['g5_shop_personalpay_table']} where pp_id = '$od_id' ");
if (!$od)
die('<p id="scash_empty">개인결제 내역이 존재하지 않습니다.</p>');
if($od['pp_cash'] == 1)
alert('이미 등록된 현금영수증 입니다.');
$buyername = $od['pp_name'];
$goodname = $od['pp_name'].'님 개인결제';
$amt_tot = (int)$od['pp_receipt_price'];
$amt_sup = (int)round(($amt_tot * 10) / 11);
$amt_svc = 0;
$amt_tax = (int)($amt_tot - $amt_sup);
} else {
$od = sql_fetch(" select * from {$g5['g5_shop_order_table']} where od_id = '$od_id' ");
if (!$od)
die('<p id="scash_empty">주문서가 존재하지 않습니다.</p>');
if($od['od_cash'] == 1)
alert('이미 등록된 현금영수증 입니다.');
$buyername = $od['od_name'];
$goods = get_goods($od['od_id']);
$goodname = $goods['full_name'];
$amt_tot = (int)$od['od_tax_mny'] + (int)$od['od_vat_mny'] + (int)$od['od_free_mny'];
$amt_tax = (int)$od['od_vat_mny'];
$amt_svc = 0;
$amt_sup = (int)$od['od_tax_mny'];
$amt_free = (int)$od['od_free_mny'];
}
$reg_num = $id_info;
$useopt = $tr_code;
$currency = 'WON';
//step1. 요청을 위한 파라미터 설정
$goodName = $goodname; // 상품명
$crPrice = $amt_tot;// 총 현금결제 금액
$supPrice = $amt_sup;// 공급가액
$tax = $amt_tax;// 부가세
$srcvPrice = $amt_svc;// 봉사료
$buyerName = $buyername;// 구매자 성명
$buyerEmail = $buyeremail;// 구매자 이메일 주소
$buyerTel = $buyertel;// 구매자 전화번호
$useOpt = $useopt;// 현금영수증 발행용도 ("1" - 소비자 소득공제용, "2" - 사업자 지출증빙용)
$regNum = $reg_num;// 현금결제자 주민등록번호
$ediDate = preg_replace('/[^0-9]/', '', G5_TIME_YMDHIS);
// 04 (현금영수증), 01 (매체구분 일반), 시간정보 (12자리), 랜덤 4자리숫자
$tid = $default['de_nicepay_mid'].'04'.'01'.substr($ediDate, 2).rand(1000, 9999);
$signData = bin2hex(hash('sha256', $default['de_nicepay_mid'].$amt_tot.$ediDate.$od['od_id'].$default['de_nicepay_key'], true));
$data = array(
'MID' => $default['de_nicepay_mid'],
'TID' => $tid,
'EdiDate' => $ediDate,
'Moid' => $od['od_id'],
'SignData' => $signData,
'GoodsName' => iconv('utf-8', 'euc-kr', $goodName),
'ReceiptAmt' => $amt_tot,
'ReceiptType' => ($useopt > 1) ? 2 : 1,
'ReceiptTypeNo' => $regNum,
'ReceiptSupplyAmt' => $supPrice,
'ReceiptVAT' => $tax,
'ReceiptServiceAmt' => $srcvPrice,
'ReceiptTaxFreeAmt' => (int)$od['od_free_mny'],
'CharSet' => 'utf-8',
);
$response = nicepay_reqPost($data, "https://pg-api.nicepay.co.kr/webapi/cash_receipt.jsp");
$result = json_decode($response, true);
if (function_exists('add_log')) add_log($result, true, 'rr');
// 성공이면
if (isset($result['ResultCode']) && $result['ResultCode'] === '7001') {
// DB 반영
$cash_no = $result['AuthCode']; // 현금영수증 승인번호
$cash = array();
$cash['TID'] = $result['TID'];
$cash['ApplNum'] = $cash_no;
$cash['AuthDate'] = $result['AuthDate'];
$cash_info = serialize($cash);
if($tx == 'personalpay') {
$sql = " update {$g5['g5_shop_personalpay_table']}
set pp_cash = '1',
pp_cash_no = '$cash_no',
pp_cash_info = '$cash_info'
where pp_id = '$od_id' ";
} else {
$sql = " update {$g5['g5_shop_order_table']}
set od_cash = '1',
od_cash_no = '$cash_no',
od_cash_info = '$cash_info'
where od_id = '$od_id' ";
}
$sql_result = sql_query($sql, false);
} else {
//2)API 요청 실패 화면처리
$msg = '현금영수증 발급 요청처리가 정상적으로 완료되지 않았습니다.';
$msg .= '\\nTX Response_code = '.$result['ResultCode'];
$msg .= '\\nTX Response_msg = '.$result['ResultMsg'];
alert($msg);
}
$g5['title'] = '현금영수증 발급';
include_once(G5_PATH.'/head.sub.php');
?>
<script>
function showreceipt() // 현금 영수증 출력
{
var showreceiptUrl = "https://npg.nicepay.co.kr/issue/IssueLoader.do?type=1&TID=<?php echo($result['TID']); ?>";
window.open(showreceiptUrl,"showreceipt","width=430,height=700, scrollbars=no,resizable=no");
}
</script>
<div id="lg_req_tx" class="new_win">
<h1 id="win_title">현금영수증 - 나이스페이</h1>
<div class="tbl_head01 tbl_wrap">
<table>
<colgroup>
<col class="grid_4">
<col>
</colgroup>
<tbody>
<tr>
<th scope="row">결과코드</th>
<td><?php echo $result['ResultCode']; ?></td>
</tr>
<tr>
<th scope="row">결과 메세지</th>
<td><?php echo $result['ResultMsg']; ?></td>
</tr>
<tr>
<th scope="row">현금영수증 거래번호</th>
<td><?php echo $result['TID']; ?></td>
</tr>
<tr>
<th scope="row">현금영수증 승인번호</th>
<td><?php echo $result['AuthCode']; ?></td>
</tr>
<tr>
<th scope="row">승인시간</th>
<td><?php echo preg_replace("/([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $result['AuthDate']); ?></td>
</tr>
<tr>
<th scope="row">현금영수증 URL</th>
<td>
<button type="button" name="receiptView" class="btn_frmline" onClick="javascript:showreceipt();">영수증 확인</button>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
</tbody>
</table>
</div>
</div>
<?php
include_once(G5_PATH.'/tail.sub.php');