From 6703c0862adae88b8bb146cc3e65e4d1b1af0c7d Mon Sep 17 00:00:00 2001 From: chicpro Date: Mon, 25 Jul 2016 10:35:42 +0900 Subject: [PATCH] =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B2=84=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adm/shop_admin/configform.php | 76 ++++- adm/shop_admin/configformupdate.php | 6 + adm/shop_admin/itemform.php | 14 + adm/shop_admin/itemformupdate.php | 1 + css/default_shop.css | 4 + css/mobile_shop.css | 4 + install/gnuboard5shop.sql | 7 + lib/naverpay.lib.php | 299 ++++++++++++++++++ mobile/shop/cart.php | 12 + mobile/shop/item.php | 2 +- mobile/skin/shop/basic/item.form.skin.php | 66 +++- shop/cart.php | 13 + shop/item.php | 2 + shop/naverpay/_common.php | 4 + shop/naverpay/naverpay_item.php | 80 +++++ shop/naverpay/naverpay_order.php | 228 +++++++++++++ shop/naverpay/naverpay_wish.php | 112 +++++++ shop/settle_naverpay.inc.php | 149 +++++++++ skin/shop/basic/item.form.skin.php | 65 ++++ theme/basic/css/default_shop.css | 4 + theme/basic/css/mobile_shop.css | 4 + .../mobile/skin/shop/basic/item.form.skin.php | 66 +++- .../basic/skin/shop/basic/item.form.skin.php | 64 ++++ 23 files changed, 1278 insertions(+), 4 deletions(-) create mode 100644 lib/naverpay.lib.php create mode 100644 shop/naverpay/_common.php create mode 100644 shop/naverpay/naverpay_item.php create mode 100644 shop/naverpay/naverpay_order.php create mode 100644 shop/naverpay/naverpay_wish.php create mode 100644 shop/settle_naverpay.inc.php diff --git a/adm/shop_admin/configform.php b/adm/shop_admin/configform.php index dc9959b1e..ce3461b47 100644 --- a/adm/shop_admin/configform.php +++ b/adm/shop_admin/configform.php @@ -117,6 +117,17 @@ if(!isset($default['de_inicis_sign_key'])) { sql_query(" ALTER TABLE `{$g5['g5_shop_default_table']}` ADD `de_inicis_sign_key` varchar(255) NOT NULL DEFAULT '' AFTER `de_inicis_admin_key` ", true); } + +// 네이버페이 필드추가 +if(!isset($default['de_naverpay_mid'])) { + sql_query(" ALTER TABLE `{$g5['g5_shop_default_table']}` + ADD `de_naverpay_mid` varchar(255) NOT NULL DEFAULT '' AFTER `de_kakaopay_cancelpwd`, + ADD `de_naverpay_cert_key` varchar(255) NOT NULL DEFAULT '' AFTER `de_naverpay_mid`, + ADD `de_naverpay_button_key` varchar(255) NOT NULL DEFAULT '' AFTER `de_naverpay_cert_key`, + ADD `de_naverpay_test` tinyint(4) NOT NULL DEFAULT '0' AFTER `de_naverpay_button_key`, + ADD `de_naverpay_mb_id` varchar(255) NOT NULL DEFAULT '' AFTER `de_naverpay_test`, + ADD `de_naverpay_sendcost` varchar(255) NOT NULL DEFAULT '' AFTER `de_naverpay_mb_id`", true); +} ?>
@@ -708,7 +719,7 @@ if(!isset($default['de_inicis_sign_key'])) { - 카카오페이 서비스신청하기 + 카카오페이 서비스신청하기 @@ -743,6 +754,69 @@ if(!isset($default['de_inicis_sign_key'])) { + + + + 네이버페이 서비스신청하기 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 예로 설정해야 하며 최종 승인 후 아니오로 설정합니다."); ?> + + + + + + + + + + + + + + 네이버페이 상품정보 XML URL + + + /naverpay/naverpay_item.php + + + + + + + + 예) 제주도 3,000원 추가, 제주도 외 도서·산간 지역 5,000원 추가"); ?> + + + 에스크로 사용 diff --git a/adm/shop_admin/configformupdate.php b/adm/shop_admin/configformupdate.php index cdc951849..6f7aa6d23 100644 --- a/adm/shop_admin/configformupdate.php +++ b/adm/shop_admin/configformupdate.php @@ -188,6 +188,12 @@ $sql = " update {$g5['g5_shop_default_table']} de_kakaopay_enckey = '{$_POST['de_kakaopay_enckey']}', de_kakaopay_hashkey = '{$_POST['de_kakaopay_hashkey']}', de_kakaopay_cancelpwd = '{$_POST['de_kakaopay_cancelpwd']}', + de_naverpay_mid = '{$_POST['de_naverpay_mid']}', + de_naverpay_cert_key = '{$_POST['de_naverpay_cert_key']}', + de_naverpay_button_key = '{$_POST['de_naverpay_button_key']}', + de_naverpay_test = '{$_POST['de_naverpay_test']}', + de_naverpay_mb_id = '{$_POST['de_naverpay_mb_id']}', + de_naverpay_sendcost = '{$_POST['de_naverpay_sendcost']}', de_member_reg_coupon_use = '{$_POST['de_member_reg_coupon_use']}', de_member_reg_coupon_term = '{$_POST['de_member_reg_coupon_term']}', de_member_reg_coupon_price = '{$_POST['de_member_reg_coupon_price']}', diff --git a/adm/shop_admin/itemform.php b/adm/shop_admin/itemform.php index 7111c5e02..de781b0d0 100644 --- a/adm/shop_admin/itemform.php +++ b/adm/shop_admin/itemform.php @@ -109,6 +109,13 @@ if(!sql_query(" select it_shop_memo from {$g5['g5_shop_item_table']} limit 1 ", ADD `it_shop_memo` text NOT NULL AFTER `it_use_avg` ", true); } +// 지식쇼핑 PID 필드추가 +// 상품메모 필드 추가 +if(!sql_query(" select ec_mall_pid from {$g5['g5_shop_item_table']} limit 1 ", false)) { + sql_query(" ALTER TABLE `{$g5['g5_shop_item_table']}` + ADD `ec_mall_pid` varchar(255) NOT NULL AFTER `it_shop_memo` ", true); +} + $pg_anchor =' diff --git a/shop/naverpay/_common.php b/shop/naverpay/_common.php new file mode 100644 index 000000000..859215bc0 --- /dev/null +++ b/shop/naverpay/_common.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/shop/naverpay/naverpay_item.php b/shop/naverpay/naverpay_item.php new file mode 100644 index 000000000..0adea56c4 --- /dev/null +++ b/shop/naverpay/naverpay_item.php @@ -0,0 +1,80 @@ +'; +?> + + + + +]]> + +]]> + +]]> + + + + + +]]> +]]> +]]> + + + + +'); +?> \ No newline at end of file diff --git a/shop/naverpay/naverpay_order.php b/shop/naverpay/naverpay_order.php new file mode 100644 index 000000000..cb44fe323 --- /dev/null +++ b/shop/naverpay/naverpay_order.php @@ -0,0 +1,228 @@ + 0) + $items[] = $it_id; + } + + $_POST['it_id'] = $items; +} + +$count = count($_POST['it_id']); +if ($count < 1) + return_error2json('구매하실 상품을 선택하여 주십시오.'); + +$itm_ids = array(); +$sel_options = array(); +$sup_options = array(); + +if($_POST['naverpay_form'] == 'item.php') + $back_uri = '/item.php?it_id='.$_POST['it_id'][0]; +else if($_POST['naverpay_form'] == 'cart.php') + $back_uri = '/cart.php'; +else + $back_uri = ''; + +define('NAVERPAY_BACK_URL', G5_SHOP_URL.$back_uri); + +for($i=0; $i<$count; $i++) { + $it_id = $_POST['it_id'][$i]; + $opt_count = count($_POST['io_id'][$it_id]); + + if($opt_count && $_POST['io_type'][$it_id][0] != 0) + return_error2json('상품의 선택옵션을 선택해 주십시오.'); + + for($k=0; $k<$opt_count; $k++) { + if ($_POST['ct_qty'][$it_id][$k] < 1) + return_error2json('수량은 1 이상 입력해 주십시오.'); + } + + // 상품정보 + $sql = " select * from {$g5['g5_shop_item_table']} where it_id = '$it_id' "; + $it = sql_fetch($sql); + if(!$it['it_id']) + return_error2json('상품정보가 존재하지 않습니다.'); + + if(!$it['it_use'] || $it['it_soldout'] || $it['it_tel_inq']) + return_error2json($it['it_name'].' 는(은) 구매할 수 없는 상품입니다.'); + + // 최소, 최대 수량 체크 + if($it['it_buy_min_qty'] || $it['it_buy_max_qty']) { + $sum_qty = 0; + for($k=0; $k<$opt_count; $k++) { + if($_POST['io_type'][$it_id][$k] == 0) + $sum_qty += $_POST['ct_qty'][$it_id][$k]; + } + + if($it['it_buy_min_qty'] > 0 && $sum_qty < $it['it_buy_min_qty']) + return_error2json($it['it_name'].'의 선택옵션 개수 총합 '.number_format($it['it_buy_min_qty']).'개 이상 주문해 주십시오.'); + + if($it['it_buy_max_qty'] > 0 && $sum_qty > $it['it_buy_max_qty']) + return_error2json($it['it_name'].'의 선택옵션 개수 총합 '.number_format($it['it_buy_max_qty']).'개 이하로 주문해 주십시오.'); + } + + // 옵션정보를 얻어서 배열에 저장 + $opt_list = array(); + $sql = " select * from {$g5['g5_shop_item_option_table']} where it_id = '$it_id' order by io_no asc "; + $result = sql_query($sql); + $lst_count = 0; + for($k=0; $row=sql_fetch_array($result); $k++) { + $opt_list[$row['io_type']][$row['io_id']]['id'] = $row['io_id']; + $opt_list[$row['io_type']][$row['io_id']]['use'] = $row['io_use']; + $opt_list[$row['io_type']][$row['io_id']]['price'] = $row['io_price']; + $opt_list[$row['io_type']][$row['io_id']]['stock'] = $row['io_stock_qty']; + + // 선택옵션 개수 + if(!$row['io_type']) + $lst_count++; + } + + //-------------------------------------------------------- + // 재고 검사 + //-------------------------------------------------------- + for($k=0; $k<$opt_count; $k++) { + $io_id = $_POST['io_id'][$it_id][$k]; + $io_type = $_POST['io_type'][$it_id][$k]; + $io_value = $_POST['io_value'][$it_id][$k]; + + // 재고 구함 + $ct_qty = $_POST['ct_qty'][$it_id][$k]; + if(!$io_id) + $it_stock_qty = get_it_stock_qty($it_id); + else + $it_stock_qty = get_option_stock_qty($it_id, $io_id, $io_type); + + if ($ct_qty > $it_stock_qty) + { + return_error2json($io_value." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty) . " 개"); + } + } + //-------------------------------------------------------- + + $itm_ids[] = $it_id; + + for($k=0; $k<$opt_count; $k++) { + $io_id = $_POST['io_id'][$it_id][$k]; + $io_type = $_POST['io_type'][$it_id][$k]; + $io_value = $_POST['io_value'][$it_id][$k]; + + // 선택옵션정보가 존재하는데 선택된 옵션이 없으면 건너뜀 + if($lst_count && $io_id == '') + continue; + + // 구매할 수 없는 옵션은 건너뜀 + if($io_id && !$opt_list[$io_type][$io_id]['use']) + continue; + + $io_price = $opt_list[$io_type][$io_id]['price']; + $ct_qty = $_POST['ct_qty'][$it_id][$k]; + + $it_price = get_price($it); + + // 구매가격이 음수인지 체크 + if($io_type) { + if((int)$io_price <= 0) + return_error2json('구매금액이 음수 또는 0원인 상품은 구매할 수 없습니다.'); + } else { + if((int)$it_price + (int)$io_price <= 0) + return_error2json('구매금액이 음수 또는 0원인 상품은 구매할 수 없습니다.'); + } + + // 배송비결제 + if($it['it_sc_type'] == 1) + $ct_send_cost = 2; // 무료 + else if($it['it_sc_type'] > 1 && $it['it_sc_method'] == 1) + $ct_send_cost = 1; // 착불 + + // 옵션정보배열에 저장 + $options[$it_id][] = array( + 'option' => $io_value, + 'price' => $io_price, + 'qty' => $ct_qty, + 'send_cost' => $ct_send_cost, + 'type' => $io_type, + 'io_id' => $io_id + ); + } +} + +$order = new naverpay_register($options, $ct_send_cost); +$query = $order->query(); +$totalPrice = $order->total_price; + +//echo $query.'
'.PHP_EOL; + +$nc_sock = @fsockopen($req_addr, $req_port, $errno, $errstr); +if ($nc_sock) { + fwrite($nc_sock, $buy_req_url."\r\n" ); + fwrite($nc_sock, "Host: ".$req_host.":".$req_port."\r\n" ); + fwrite($nc_sock, "Content-type: application/x-www-form-urlencoded; charset=utf-8\r\n"); + fwrite($nc_sock, "Content-length: ".strlen($query)."\r\n"); + fwrite($nc_sock, "Accept: */*\r\n"); + fwrite($nc_sock, "\r\n"); + fwrite($nc_sock, $query."\r\n"); + fwrite($nc_sock, "\r\n"); + + // get header + while(!feof($nc_sock)) { + $header=fgets($nc_sock,4096); + if($header=="\r\n") { + break; + } else { + $headers .= $header; + } + } + // get body + while(!feof($nc_sock)) { + $bodys.=fgets($nc_sock,4096); + } + + fclose($nc_sock); + + $resultCode = substr($headers,9,3); + if ($resultCode == 200) { + // success + $orderId = $bodys; + } else { + // fail + return_error2json($bodys); + } +} else { + //echo "$errstr ($errno)
\n"; + return_error2json($errstr ($errno)); + exit(-1); + //에러처리 +} + +if($resultCode == 200) + die(json_encode(array('error'=>'', 'ORDER_ID'=>$orderId, 'SHOP_ID'=>$default['de_naverpay_mid'], 'TOTAL_PRICE'=>$totalPrice))); +?> \ No newline at end of file diff --git a/shop/naverpay/naverpay_wish.php b/shop/naverpay/naverpay_wish.php new file mode 100644 index 000000000..1d858a202 --- /dev/null +++ b/shop/naverpay/naverpay_wish.php @@ -0,0 +1,112 @@ +\n"; + exit(-1); + //에러처리 +} + +$count = count($itemIdList); + +if ($resultCode == 200) { +?> + + + + + + + + + + + + + \ No newline at end of file diff --git a/shop/settle_naverpay.inc.php b/shop/settle_naverpay.inc.php new file mode 100644 index 000000000..2d9174158 --- /dev/null +++ b/shop/settle_naverpay.inc.php @@ -0,0 +1,149 @@ + + '.PHP_EOL; +} else { + $naverpay_button_js = ' + '.PHP_EOL; +} + +$naverpay_button_js .= ''.PHP_EOL; + +if($default['de_naverpay_test'] || $default['de_card_test']) { + $req_addr = 'ssl://test-pay.naver.com'; + $buy_req_url = 'POST /customer/api/order.nhn HTTP/1.1'; + $wish_req_url = 'POST /customer/api/wishlist.nhn HTTP/1.1'; + $req_host = 'test-pay.naver.com'; + $req_port = 443; + if($is_mobile_order) { + $orderUrl = 'https://test-m.pay.naver.com/mobile/customer/order.nhn'; + $wishUrl = 'https://m.pay.naver.com/mobile/customer/wishList.nhn'; + } else { + $orderUrl = 'https://test-pay.naver.com/customer/order.nhn'; + $wishUrl = 'https://test-pay.naver.com/customer/wishlistPopup.nhn'; + } +} else { + $req_addr = 'ssl://pay.naver.com'; + $buy_req_url = 'POST /customer/api/order.nhn HTTP/1.1'; + $wish_req_url = 'POST /customer/api/wishlist.nhn HTTP/1.1'; + $req_host = 'pay.naver.com'; + $req_port = 443; + if($is_mobile_order) { + $orderUrl = 'https://m.pay.naver.com/mobile/customer/order.nhn'; + $wishUrl = 'https://m.pay.naver.com/mobile/customer/wishList.nhn'; + } else { + $orderUrl = 'https://pay.naver.com/customer/order.nhn'; + $wishUrl = 'https://pay.naver.com/customer/wishlistPopup.nhn'; + } +} + +define('SHIPPING_ADDITIONAL_PRICE', $default['de_naverpay_sendcost']); + +$naverpay_request_js = ''.PHP_EOL; +?> \ No newline at end of file diff --git a/skin/shop/basic/item.form.skin.php b/skin/shop/basic/item.form.skin.php index fd0de6be6..abbbd1206 100644 --- a/skin/shop/basic/item.form.skin.php +++ b/skin/shop/basic/item.form.skin.php @@ -297,6 +297,9 @@ add_stylesheet('', 0 위시리스트 추천하기 + +
+