From 7c86e4170129d9979d932d39cc4ae730cbb923f7 Mon Sep 17 00:00:00 2001 From: chicpro Date: Tue, 15 Sep 2015 18:05:29 +0900 Subject: [PATCH] =?UTF-8?q?PC=20=EC=B9=B4=EC=B9=B4=EC=98=A4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adm/shop_admin/configform.php | 49 ++- adm/shop_admin/configformupdate.php | 5 + install/gnuboard5shop.sql | 5 + shop/kakaopay/_common.php | 3 + shop/kakaopay/getTxnId.php | 141 +++++++++ shop/kakaopay/incKakaopayCommon.php | 43 +++ shop/kakaopay/kakaopay_result.php | 76 +++++ shop/kakaopay/lgcns_CNSpay.php | 465 ++++++++++++++++++++++++++++ shop/kakaopay/lgcns_KMpay.php | 381 +++++++++++++++++++++++ shop/kakaopay/makehashdata.php | 21 ++ shop/kakaopay/orderform.1.php | 110 +++++++ shop/kakaopay/orderform.2.php | 33 ++ shop/kakaopay/orderform.3.php | 6 + shop/orderform.php | 30 +- shop/orderformupdate.php | 36 ++- shop/settle_kakaopay.inc.php | 9 + 16 files changed, 1403 insertions(+), 10 deletions(-) create mode 100644 shop/kakaopay/_common.php create mode 100644 shop/kakaopay/getTxnId.php create mode 100644 shop/kakaopay/incKakaopayCommon.php create mode 100644 shop/kakaopay/kakaopay_result.php create mode 100644 shop/kakaopay/lgcns_CNSpay.php create mode 100644 shop/kakaopay/lgcns_KMpay.php create mode 100644 shop/kakaopay/makehashdata.php create mode 100644 shop/kakaopay/orderform.1.php create mode 100644 shop/kakaopay/orderform.2.php create mode 100644 shop/kakaopay/orderform.3.php create mode 100644 shop/settle_kakaopay.inc.php diff --git a/adm/shop_admin/configform.php b/adm/shop_admin/configform.php index b23cd96b5..d135b0b0f 100644 --- a/adm/shop_admin/configform.php +++ b/adm/shop_admin/configform.php @@ -102,6 +102,16 @@ if(!isset($default['de_easy_pay_use'])) { sql_query(" ALTER TABLE `{$g5['g5_shop_default_table']}` ADD `de_easy_pay_use` tinyint(4) NOT NULL DEFAULT '0' AFTER `de_iche_use` ", true); } + +// 카카오페이 필드 추가 +if(!isset($default['de_kakaopay_mid'])) { + sql_query(" ALTER TABLE `{$g5['g5_shop_default_table']}` + ADD `de_kakaopay_mid` varchar(255) NOT NULL DEFAULT '' AFTER `de_tax_flag_use`, + ADD `de_kakaopay_key` varchar(255) NOT NULL DEFAULT '' AFTER `de_kakaopay_mid`, + ADD `de_kakaopay_enckey` varchar(255) NOT NULL DEFAULT '' AFTER `de_kakaopay_key`, + ADD `de_kakaopay_hashkey` varchar(255) NOT NULL DEFAULT '' AFTER `de_kakaopay_enckey`, + ADD `de_kakaopay_cancelpwd` varchar(255) NOT NULL DEFAULT '' AFTER `de_kakaopay_hashkey` ", true); +} ?>
@@ -679,6 +689,41 @@ if(!isset($default['de_easy_pay_use'])) { + + + + + KHSIR m + + + + + + + + + + + + + + + + + + + + + + + + + + + 입력하신 비밀번호와 상점관리자에서 설정하신 비밀번호가 일치하지 않으면 취소가 되지 않습니다."); ?> + + + 에스크로 사용 @@ -690,9 +735,9 @@ if(!isset($default['de_easy_pay_use'])) { - 신용카드 결제테스트 + 결제 테스트 - + id="de_card_test1"> id="de_card_test2"> diff --git a/adm/shop_admin/configformupdate.php b/adm/shop_admin/configformupdate.php index e49547b47..bf964555b 100644 --- a/adm/shop_admin/configformupdate.php +++ b/adm/shop_admin/configformupdate.php @@ -176,6 +176,11 @@ $sql = " update {$g5['g5_shop_default_table']} de_hp_use = '{$_POST['de_hp_use']}', de_escrow_use = '{$_POST['de_escrow_use']}', de_tax_flag_use = '{$_POST['de_tax_flag_use']}', + de_kakaopay_mid = '{$_POST['de_kakaopay_mid']}', + de_kakaopay_key = '{$_POST['de_kakaopay_key']}', + de_kakaopay_enckey = '{$_POST['de_kakaopay_enckey']}', + de_kakaopay_hashkey = '{$_POST['de_kakaopay_hashkey']}', + de_kakaopay_cancelpwd = '{$_POST['de_kakaopay_cancelpwd']}', 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/install/gnuboard5shop.sql b/install/gnuboard5shop.sql index 243e03cbe..a1bccf9e4 100644 --- a/install/gnuboard5shop.sql +++ b/install/gnuboard5shop.sql @@ -325,6 +325,11 @@ CREATE TABLE IF NOT EXISTS `g5_shop_default` ( `de_hp_use` tinyint(4) NOT NULL DEFAULT '0', `de_escrow_use` tinyint(4) NOT NULL DEFAULT '0', `de_tax_flag_use` tinyint(4) NOT NULL DEFAULT '0', + `de_kakaopay_mid` varchar(255) NOT NULL DEFAULT '', + `de_kakaopay_key` varchar(255) NOT NULL DEFAULT '', + `de_kakaopay_enckey` varchar(255) NOT NULL DEFAULT '', + `de_kakaopay_hashkey` varchar(255) NOT NULL DEFAULT '', + `de_kakaopay_cancelpwd` varchar(255) NOT NULL DEFAULT '', `de_member_reg_coupon_use` tinyint(4) NOT NULL DEFAULT '0', `de_member_reg_coupon_term` int(11) NOT NULL DEFAULT '0', `de_member_reg_coupon_price` int(11) NOT NULL DEFAULT '0', diff --git a/shop/kakaopay/_common.php b/shop/kakaopay/_common.php new file mode 100644 index 000000000..bad54a5d7 --- /dev/null +++ b/shop/kakaopay/_common.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/shop/kakaopay/getTxnId.php b/shop/kakaopay/getTxnId.php new file mode 100644 index 000000000..fd941fa81 --- /dev/null +++ b/shop/kakaopay/getTxnId.php @@ -0,0 +1,141 @@ +setPhpVersion($phpVersion); + +// TXN_ID를 요청하기 위한 PARAMETERR +$REQUESTDEALAPPROVEURL = KMPayRequest("requestDealApproveUrl"); //인증 요청 경로 +$PR_TYPE = KMPayRequest("prType"); //결제 요청 타입 +$MERCHANT_ID = KMPayRequest("MID"); //가맹점 ID +$MERCHANT_TXN_NUM = KMPayRequest("merchantTxnNum"); //가맹점 거래번호 +$channelType = KMPayRequest("channelType"); +$PRODUCT_NAME = KMPayRequest("GoodsName"); //상품명 +$AMOUNT = KMPayRequest("Amt"); //상품금액(총거래금액) (총거래금액 = 공급가액 + 부가세 + 봉사료) + +$CURRENCY = KMPayRequest("currency"); //거래통화(KRW/USD/JPY 등) +$RETURN_URL = KMPayRequest("returnUrl"); //결제승인결과전송URL +$CERTIFIED_FLAG = KMPayRequest("CERTIFIED_FLAG"); //가맹점 인증 구분값 ("N","NC") + +$OFFER_PERIOD_FLAG = KMPayRequest("OFFER_PERIOD_FLAG"); //상품제공기간 플래그 +$OFFER_PERIOD = KMPayRequest("OFFER_PERIOD"); //상품제공기간 + + +//무이자옵션 +$NOINTYN = KMPayRequest("noIntYN"); //무이자 설정 +$NOINTOPT = KMPayRequest("noIntOpt"); //무이자 옵션 +$MAX_INT =KMPayRequest("maxInt"); //최대할부개월 +$FIXEDINT = KMPayRequest("fixedInt"); //고정할부개월 +$POINT_USE_YN = KMPayRequest("pointUseYn"); //카드사포인트사용여부 +$POSSICARD = KMPayRequest("possiCard"); //결제가능카드설정 +$BLOCK_CARD = KMPayRequest("blockCard"); //금지카드설정 + +// ENC KEY와 HASH KEY는 가맹점에서 생성한 KEY 로 SETTING 한다. +$merchantEncKey = KMPayRequest("merchantEncKey"); +$merchantHashKey = KMPayRequest("merchantHashKey"); + $hashTarget = $MERCHANT_ID.$MERCHANT_TXN_NUM.str_pad($AMOUNT,7,"0",STR_PAD_LEFT); + +// payHash 생성 +$payHash = strtoupper(hash("sha256", $hashTarget.$merchantHashKey, false)); + +//json string 생성 +$strJsonString = new JsonString($LogDir); + +$strJsonString->setValue("PR_TYPE", $PR_TYPE); +$strJsonString->setValue("channelType", $channelType); +$strJsonString->setValue("MERCHANT_ID", $MERCHANT_ID); +$strJsonString->setValue("MERCHANT_TXN_NUM", $MERCHANT_TXN_NUM); +$strJsonString->setValue("PRODUCT_NAME", $PRODUCT_NAME); + +$strJsonString->setValue("AMOUNT", $AMOUNT); + +$strJsonString->setValue("CURRENCY", $CURRENCY); +$strJsonString->setValue("CERTIFIED_FLAG", $CERTIFIED_FLAG); + +$strJsonString->setValue("OFFER_PERIOD_FLAG", $OFFER_PERIOD_FLAG); +$strJsonString->setValue("OFFER_PERIOD", $OFFER_PERIOD); + +$strJsonString->setValue("NO_INT_YN", $NOINTYN); +$strJsonString->setValue("NO_INT_OPT", $NOINTOPT); +$strJsonString->setValue("MAX_INT", $MAX_INT); +$strJsonString->setValue("FIXED_INT", $FIXEDINT); + +$strJsonString->setValue("POINT_USE_YN", $POINT_USE_YN); +$strJsonString->setValue("POSSI_CARD", $POSSICARD); +$strJsonString->setValue("BLOCK_CARD", $BLOCK_CARD); + +$strJsonString->setValue("PAYMENT_HASH", $payHash); + +// 결과값을 담는 부분 +$resultCode = ""; +$resultMsg = ""; +$txnId = ""; +$merchantTxnNum = ""; +$prDt = ""; +$strValid = ""; + +// Data 검증 +$dataValidator = new KMPayDataValidator($strJsonString->getArrayValue()); +$strValid = $dataValidator->resultValid; +if (strlen($strValid) > 0) { + $arrVal = explode(",", $strValid); + if (count($arrVal) == 3) { + $resultCode = $arrVal[1]; + $resultMsg = $arrVal[2]; + } else { + $resultCode = $strValid; + $resultMsg = $strValid; + } +} + +// Data에 이상 없는 경우 +if (strlen($strValid) == 0) { + // CBC 암호화 + $paramStr = $strJsonString->getJsonString(); + $kmFunc->writeLog("Request"); + $kmFunc->writeLog($paramStr); + $kmFunc->writeLog($strJsonString->getArrayValue()); + $encryptStr = $kmFunc->parameterEncrypt($merchantEncKey, $paramStr); + $payReqResult = $kmFunc->connMPayDLP($REQUESTDEALAPPROVEURL, $MERCHANT_ID, $encryptStr); + $resultString = $kmFunc->parameterDecrypt($merchantEncKey, $payReqResult); + + $resultJSONObject = new JsonString($LogDir); + if (substr($resultString, 0, 1) == "{") { + $resultJSONObject->setJsonString($resultString); + $resultCode = $resultJSONObject->getValue("RESULT_CODE"); + $resultMsg = $resultJSONObject->getValue("RESULT_MSG"); + if ($resultCode == "00") { + $txnId = $resultJSONObject->getValue("TXN_ID"); + $merchantTxnNum = $resultJSONObject->getValue("MERCHANT_TXN_NUM"); + $prDt = $resultJSONObject->getValue("PR_DT"); + } + } + $kmFunc->writeLog("Result"); + $kmFunc->writeLog($resultString); + $kmFunc->writeLog($resultJSONObject->getArrayValue()); +} + +$result = array(); + +$result = array( + 'resultCode' => $resultCode, + 'resultMsg' => $resultMsg, + 'txnId' => $txnId, + 'prDt' => $prDt +); + +die(json_encode($result)); +?> \ No newline at end of file diff --git a/shop/kakaopay/incKakaopayCommon.php b/shop/kakaopay/incKakaopayCommon.php new file mode 100644 index 000000000..02a340544 --- /dev/null +++ b/shop/kakaopay/incKakaopayCommon.php @@ -0,0 +1,43 @@ + \ No newline at end of file diff --git a/shop/kakaopay/kakaopay_result.php b/shop/kakaopay/kakaopay_result.php new file mode 100644 index 000000000..490fb1835 --- /dev/null +++ b/shop/kakaopay/kakaopay_result.php @@ -0,0 +1,76 @@ +CnsActionUrl($CnsPayDealRequestUrl); +$connector->CnsPayVersion($phpVersion); + +// 요청 페이지 파라메터 셋팅 +$connector->setRequestData($_REQUEST); + +// 추가 파라메터 셋팅 +$connector->addRequestData("actionType", "PY0"); // actionType : CL0 취소, PY0 승인, CI0 조회 +$connector->addRequestData("MallIP", $_SERVER['REMOTE_ADDR']); // 가맹점 고유 ip +$connector->addRequestData("CancelPwd", $cancelPwd); + +//가맹점키 셋팅 (MID 별로 틀림) +$connector->addRequestData("EncodeKey", $merchantKey); + +// 4. CNSPAY Lite 서버 접속하여 처리 +$connector->requestAction(); + +// 5. 결과 처리 +$buyerName = $_REQUEST["BuyerName"]; // 구매자명 +$goodsName = $_REQUEST["GoodsName"]; // 상품명 +// $buyerName = iconv("euc-kr", "utf-8", $connector->getResultData("BuyerName")); // 구매자명 +// $goodsName = iconv("euc-kr", "utf-8", $connector->getResultData("GoodsName")); // 상품명 + +$resultCode = $connector->getResultData("ResultCode"); // 결과코드 (정상 :3001 , 그 외 에러) +$resultMsg = $connector->getResultData("ResultMsg"); // 결과메시지 +$authDate = $connector->getResultData("AuthDate"); // 승인일시 YYMMDDHH24mmss +$authCode = $connector->getResultData("AuthCode"); // 승인번호 +$payMethod = $connector->getResultData("PayMethod"); // 결제수단 +$mid = $connector->getResultData("MID"); // 가맹점ID +$tid = $connector->getResultData("TID"); // 거래ID +$moid = $connector->getResultData("Moid"); // 주문번호 +$amt = $connector->getResultData("Amt"); // 금액 +$cardCode = $connector->getResultData("CardCode"); // 카드사 코드 +$cardName = $connector->getResultData("CardName"); // 결제카드사명 +$cardQuota = $connector->getResultData("CardQuota"); // 00:일시불,02:2개월 +$cardInterest = $connector->getResultData("CardInterest"); // 무이자 여부 (0:일반, 1:무이자) +$cardCl = $connector->getResultData("CardCl"); // 체크카드여부 (0:일반, 1:체크카드) +$cardBin = $connector->getResultData("CardBin"); // 카드BIN번호 +$cardPoint = $connector->getResultData("CardPoint"); // 카드사포인트사용여부 (0:미사용, 1:포인트사용, 2:세이브포인트사용) +$paySuccess = false; // 결제 성공 여부 + +$nonRepToken =$_REQUEST["NON_REP_TOKEN"]; //부인방지토큰값 + + +$resultMsg = iconv("euc-kr", "utf-8", $resultMsg); +$cardName = iconv("euc-kr", "utf-8", $cardName); + +/** 위의 응답 데이터 외에도 전문 Header와 개별부 데이터 Get 가능 */ +if($payMethod == "CARD"){ //신용카드 + if($resultCode == "3001") $paySuccess = true; // 결과코드 (정상 :3001 , 그 외 에러) +} +if($paySuccess) { + $tno = $tid; + $amount = $amt; + $app_time = '20'.$authDate; + $bank_name = $cardName; + $depositor = ''; + $account = ''; + $commid = $cardCode; + $mobile_no = ''; + $app_no = $authCode; + $card_name = $cardName; + $pay_type = 'CARD'; + $escw_yn = '0'; +} else { + alert('[RESULT_CODE] : ' . $resultCode . '\\n[RESULT_MSG] : ' . $resultMsg); +} +?> diff --git a/shop/kakaopay/lgcns_CNSpay.php b/shop/kakaopay/lgcns_CNSpay.php new file mode 100644 index 000000000..fb2567721 --- /dev/null +++ b/shop/kakaopay/lgcns_CNSpay.php @@ -0,0 +1,465 @@ +ActionUrl = $url; + } + public function CnsPayVersion($ver) { + $this->phpVersion = $ver; + } + public function CnsPayWebConnector($LogDir) { + $this->cancelUrl = $this->ActionUrl."/lite/cancelProcess.jsp"; + if (substr($LogDir, strlen($LogDir) - 1) == "/") { + $LogDir = substr($LogDir, 0, strlen($LogDir) - 1); + } + @mkdir($LogDir); + $this->LogPath = $LogDir."/"; + } + public function setRequestData($request) { + try { + foreach (array_keys($request) as $key) { + $this->requestData[$key] = iconv("UTF-8", "EUC-KR", $request[$key]); + } + return "_TRUE_"; + } catch (Exception $ex) { + $this->writeLog("setRequestData() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function addRequestData($key, $value) { + try { + $this->requestData[$key] = $value; + return "_TRUE_"; + } catch (Exception $ex) { + $this->writeLog("addRequestData() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function getResultData($key) { + try { + if (!in_array($key, array_keys($this->resultData))) { + return ""; + } else if ($key == "Amt") { + if ($this->resultData[$key] != null && $this->resultData[$key] != "null" && $this->resultData[$key] != "") { + return $this->resultData[$key]; + } else { + return "0"; + } + } + return $this->resultData[$key]; + } catch (Exception $ex) { + $this->writeLog("getResultData() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + + // 2014.12.02 추가 (check key in array) + private function getRequestData($key) { + if (array_key_exists($key, $this->requestData)) { + return $this->requestData[$key]; + } else { + return ""; + } + } + + public function requestAction() { + $encodeKey = $this->requestData["EncodeKey"]; + unset($this->requestData["EncodeKey"]); + try { + if ($this->requestData["actionType"] != "CL0" && $this->requestData["actionType"] != "CI0") { + if ($this->getRequestData("PayMethod") != "ESCROW") { + $this->requestData["TID"] = $this->generateTID($this->requestData["MID"], $this->getRequestData("PayMethod")); + } + } + $serviceUrl = $this->setActionType($this->requestData["actionType"], $this->getRequestData("PayMethod")); + if ($serviceUrl == "_FAIL_" || $serviceUrl == "CNSPAY_10") { + $this->resultData["ResultCode"] = "JL10"; + $this->resultData["ResultMsg"] = "actionType 설정이 잘못되었습니다."; + return "_FAIL_"; + } + $this->writeLog("Request"); + $this->writeLog($this->requestData); + $requestMessage = $this->makeRequestText($this->requestData); + $resultMessage = $this->connectToServer($serviceUrl, $requestMessage); + $this->writeLog("Result"); + // 2014.12.02 수신 전문 로깅 처리 제외 + //$this->writeLog($resultMessage); + if ($resultMessage == "_FAIL_" || substr($resultMessage, 0, 4) == "FAIL") { + $resultCode = ""; + $resultMsg = ""; + $netCancelFlag = $this->requestNetCancel(); + if ($netCancelFlag == "_TRUE_") { + $resultCode = "JL32"; + $resultMsg = "PGWEB서버 통신중 오류가 발생하였습니다. (NET_CANCEL)"; + } else { // netCancel 실패이면, + $resultCode = "JL33"; + $resultMsg = "네트웍이 불안정으로 승인 실패하였습니다. 결제가 비 정상 처리 될 수 있으니 거래내역을 반드시 확인해주십시오."; + } + $this->resultData["ResultCode"] = $resultCode; + $this->resultData["ResultMsg"] = $resultMsg; + return "_FAIL_"; + } + $resultMessage = $this->parseResult($resultMessage); + //$this->writeLog($this->resultData); + // 2014.12.02 로깅 시 주요 데이터 마스킹 처리 + $this->writeLog($this->resultDataMask($this->resultData)); + if ($resultMessage == "_FAIL_" || $resultMessage == "CNSPAY_41") { + $this->resultData["ResultCode"] = "JL41"; + $this->resultData["ResultMsg"] = "응답전문이 없습니다."; + return "_FAIL_"; + } + return "_TRUE_"; + } catch (Exception $ex) { + $this->writeLog("requestAction() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + + // 2014.12.02 결과 배열 마스킹 + private function resultDataMask($strLogText) { + $arrMask = array(); + if (is_array($strLogText)) { + foreach (array_keys($strLogText) as $key) { + $k = str_replace("\n", "", trim($key)); + $arrMask[$k] = $this->requestMask($k, $strLogText[$key]); + } + return $arrMask; + } else { + return str_replace("\n", "", trim($strLogText)); + } + } + + // 2014.12.02 주요 정보 마스킹 + private function requestMask ($name, $text) { + $value = str_replace("\n", "", trim($text)); + + if ($value == null || strlen(trim($value)) == 0) return ""; + + if ($name == "X_CARDNO" || $name == "realPan" || $name == "cardNo" + || $name == "CardBin" || $name == "CardNo") { + return $this->masking($value, 6, true, false); + } else if ($name == "BuyerName" || $name == "buyerName") { + return $this->masking($value, 1, true, false); + } else if ($name == "BuyerEmail") { + return $this->masking($value, 6, false, true); + } else if ($name == "BuyerTel" || $name == "DstAddr") { + return $this->masking($value, 5, false, false); + } else if ($name == "BuyerAddr") { + return $this->masking($value, 6, true, false); + } else if ($name == "UserIP" || $name == "MallIP" || $name == "CancelPwd" + || $name == "mallUserID" || $name == "MallUserID" + || $name == "CancelIP") { + return $this->masking($value, mb_strlen(iconv('euc-kr','utf-8',$value), 'utf-8'), true, true); + } else { + return $value; + } + } + + // 2014.12.02 마스킹 처리 + private function masking($string, $num, $isLeftOrder, $beginMasking) { + + if ( $string == null ) + return ""; + + $res = ""; + $res2 = ""; + $sleng = 0; + + $str = iconv('euc-kr','utf-8',$string); + $n = mb_strlen($str, 'utf-8'); + + if ( $num >= 1 ) { + if ( $n < $num ) { + $res = $str; + } else { + if($beginMasking) { + if ($isLeftOrder) { + $res = str_repeat("*", $n); + } else { + $sleng = $num; + $res2 = mb_substr($str, $sleng, $n, 'utf-8'); + for ( $j = 0; $j < $sleng; $j++ ) { + $res .= "*"; + } + $res .= $res2; + } + } else { + $sleng = $num; + $res2 = mb_substr($str, 0, $sleng, 'utf-8'); + for ( $j = $sleng; $j < $n; $j++ ) { + $res .= "*"; + } + $res = $res2 . $res; + } + } + } else { + $res = $str; + } + + return iconv('utf-8','euc-kr',$res); + } + + private function requestNetCancel() { + try { + // 예기치 못한 오류인경우 망상취소 시도. + $serviceUrl = $this->cancelUrl; + $this->requestData["actionType"] = "CL0"; + $this->requestData["CancelIP"] = $this->requestData["MallIP"]; + if ($this->requestData["Amt"] == null) { + return "_FAIL_"; + } else { + if (is_numeric($this->requestData["Amt"])) { + $this->requestData["CancelAmt"] = $this->requestData["Amt"]; + } else { + $this->requestData["CancelAmt"] = parameterDecrypt($encodeKey, $this->requestData["Amt"]); + } + } + $this->requestData["CancelMsg"] = "NICE_NET_CANCEL"; + $this->requestData["PartialCancelCode"] = "0"; + $this->requestData["NetCancelCode"] = "1"; + if ($this->getRequestData("PayMethod") == "BILL" || $this->getRequestData("PayMethod") == "KAKAOPAY") $this->requestData["PayMethod"] = "CARD"; + $requestMessage = makeRequestText($this->requestData); + $resultMessage = connectToServer($serviceUrl, $this->requestData); + if ($resultMessage == "_FAIL_" || substr($resultMessage, 0, 4) == "FAIL") { + $resultMessage = connectToServer2($serviceUrl, $this->requestData, 20); + if ($resultMessage == "_FAIL_" || substr($resultMessage, 0, 4) == "FAIL") { + //$this->resultData["ResultCode"] = "JL41"; + //$this->resultData["ResultMsg"] = "망상취소 오류"; + return "_FAIL_"; + } + } + return "_TRUE_"; + } catch (Exception $ex) { + $this->writeLog("requestNetCancel() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + private function generateTID($mid, $svcCd) { + try { + $iRandom = str_pad(rand(0, 9999), 4, "0", STR_PAD_LEFT); + return $mid.$this->getSvcCd($svcCd)."01".date("ymdHis").$iRandom; + } catch (Exception $ex) { + $this->writeLog("generateTID() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + private function getSvcCd($svcCd) { + try { + if ($svcCd == "CARD" || $svcCd == "BILL" || $svcCd == "KAKAOPAY") { + return "01"; + } else if ($svcCd == "BANK") { + return "02"; + } else if ($svcCd == "VBANK") { + return "03"; + } else if ($svcCd == "CELLPHONE") { + return "05"; + } else if ($svcCd == "MOBILE_BILLING") { + return "05"; + } else if ($svcCd == "MOBILE_BILL") { + return "05"; + } + return "00"; + } catch (Exception $ex) { + $this->writeLog("getSvcCd() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + private function setActionType($type, $paymethod) { + try { + if ($type == null) return "CNSPAY_10"; + $builder = $this->ActionUrl; + if ($type == "CL0") { + $builder = $builder."/lite/cancelProcess.jsp"; + } else if ($type == "CI0") { + $builder = $builder."/lite/tidInfoProcess.jsp"; + } else if ($type == "PY0") { + if ($paymethod == "CASHRCPT") { // 현금영수증인경우 + $builder = $builder."/lite/cashReceiptProcess.jsp"; + } else if ($paymethod == "BILL") { + $builder = $builder."/lite/billingProcess.jsp"; + } else if ($paymethod == "BILLKEY") { + $builder = $builder."/lite/billkeyProcess.jsp"; + } else if ($paymethod == "ESCROW") { + $builder = $builder."/lite/escrowProcess.jsp"; + } else if ($paymethod == "MOBILE_AUTH") { + $builder = $builder."/lite/mobileAuth.jsp"; + } else if ($paymethod == "MOBILE_BILL") { + $builder = $builder."/lite/mobileBill.jsp"; + } else if ($paymethod == "MOBILE_BILLING") { + $builder = $builder."/lite/mobileBillingProcess.jsp"; + } else if ($paymethod == "MOBILE_AUTH_REQ") { + $builder = $builder."/lite/mobileConfirmRequest.jsp"; + } else if ($paymethod == "MOBILE_AUTH_RES") { + $builder = $builder."/lite/mobileConfirmResult.jsp"; + } else if ($paymethod == "CARD_ARS") { + $builder = $builder."/lite/cardArsProcess.jsp"; + } else if ($paymethod == "MOBILE_AUTH_NS") { + $builder = $builder."/lite/mobileAuth_NS.jsp"; + } else if ($paymethod == "OM_SUB_INS") { + $builder = $builder."/lite/payproxy/subMallSetProcess.jsp"; + } else if ($paymethod == "OM_SUB_PAY") { + $builder = $builder."/lite/payproxy/subMallIcheProcess.jsp"; + } else if ($paymethod == "LOTTE_POINT") { + $builder = $builder."/api/checkLottePoint.jsp"; + } else if ($paymethod == "HPBILLKEY") { + $builder = $builder."/lite/hpBillkeyProcess.jsp"; + } else if ($paymethod == "HPCARD_AUTH") { + $builder = $builder."/lite/hpCardAuthProcess.jsp"; + } else if ($paymethod == "HPCARD_BILLKEY") { + $builder = $builder."/lite/hpCardBillkeyProcess.jsp"; + } else { + $builder = $builder."/lite/payProcess.jsp"; + } + } + return $builder; + } catch (Exception $ex) { + $this->writeLog("setActionType() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + private function makeRequestText($reqData) { + try { + $strParameter = ""; + foreach (array_keys($reqData) as $key) { + $strParameter = $strParameter.$key."=".urlencode($reqData[$key])."&"; + } + $strParameter = substr($strParameter, 0, strlen($strParameter) - 1); + return $strParameter; + } catch (Exception $ex) { + $this->writeLog("makeRequestText() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + private function connectToServer($urlStr, $reqData) { + try { + return $this->connectToServer2($urlStr, $reqData, 15); + } catch (Exception $ex) { + $this->writeLog("connectToServer() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + private function connectToServer2($urlStr, $reqData, $timeout) { + try { + // php에 cURL 모듈 설치 필요(리눅스 - curl.so, 윈도우 - php_curl.dll 확장모듈 필요) + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $urlStr); //접속할 URL 주소 + //curl_setopt($ch, CURLOPT_PORT, 6464); //접속할 port, 주소에 있으므로 설정하지 않음 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 인증서 체크같은데 true 시 안되는 경우가 많다. + //curl_setopt($ch, CURLOPT_SSLVERSION, 3); // SSL 버젼 (https 접속시에 필요, 기본값으로 해야하므로 설정하지 않음) + curl_setopt($ch, CURLOPT_HEADER, 0); // 헤더 출력 여부 + curl_setopt($ch, CURLOPT_POST, 1); // Post Get 접속 여부 + curl_setopt($ch, CURLOPT_POSTFIELDS, $reqData); // Post 값 Get 방식처럼적는다. + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // TimeOut 값 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 결과값을 받을것인지 + curl_setopt($ch, CURLOPT_USERAGENT, $this->phpVersion); // 버전 + $result = curl_exec($ch); + $errcode = curl_error($ch); + if ($errcode != "") $result = $errcode; + //$errcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + //if ($errcode != 200) $result = $errcode; + curl_close($ch); + return $result; + } catch (Exception $ex) { + $this->writeLog("connectToServer2() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + private function parseResult($resultMessage) { + try { + if ($resultMessage == null) return "CNSPAY_41"; + $parsedArr = explode("|", $resultMessage); + foreach ($parsedArr as $valueArr) { + $posit = strpos($valueArr, "="); + $key = substr($valueArr, 0, $posit); + $value = substr($valueArr, $posit + 1); + $this->resultData[$key] = $value; + } + return "_TRUE_"; + } catch (Exception $ex) { + $this->writeLog("parseResult() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function writeLog($strLogText) { + $log_string = ""; + if (is_array($strLogText)) { + $log_string = "[".date("Y/m/d H:i:s")."] \r\n"; + foreach (array_keys($strLogText) as $key) { + $log_string = $log_string." [".$key."] => ".$strLogText[$key]."\r\n"; + } + } else { + $log_string = "[".date("Y/m/d H:i:s")."] ".$strLogText."\r\n"; + } + $log_filenm = $this->LogPath.date("Ymd")."_CNSpay.log"; + $log_file = fopen($log_filenm, "a"); + if($log_file == false) return; + flock($log_file, LOCK_EX); + //fwrite($log_file, $log_string); + fputs($log_file, $log_string); + fflush($log_file); + flock($log_file, LOCK_UN); + fclose($log_file); + } + public function makeDateString($sDate) { + try { + if ($sDate == null) return ""; + $strValue = ""; + if (strlen($sDate) == 12) { + $strValue = $strValue."20".substr($sDate, 0, 2)."-"; + $strValue = $strValue.substr($sDate, 2, 2)."-"; + $strValue = $strValue.substr($sDate, 4, 2). " "; + $strValue = $strValue.substr($sDate, 6, 2).":"; + $strValue = $strValue.substr($sDate, 8, 2).":"; + $strValue = $strValue.substr($sDate, 10, 2); + } else if (strlen($sDate) == 14) { + $strValue = $strValue.substr($sDate, 0, 4)."-"; + $strValue = $strValue.substr($sDate, 4, 2)."-"; + $strValue = $strValue.substr($sDate, 6, 2)." "; + $strValue = $strValue.substr($sDate, 8, 2).":"; + $strValue = $strValue.substr($sDate, 10, 2).":"; + $strValue = $strValue.substr($sDate, 12, 2); + } else if (strlen($sDate) == 8) { + $strValue = $strValue.substr($sDate, 0, 4)."-"; + $strValue = $strValue.substr($sDate, 4, 2)."-"; + $strValue = $strValue.substr($sDate, 6, 2); + } else { + $strValue = $sDate; + } + return $strValue; + } catch (Exception $ex) { + writeLog("makeDateString() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + + + public function makeHashInputString($salt) { + + $result = ""; + + for($count = 0;$count < strlen($salt)/2;$count++) { + $temp0 = substr($salt, 2*$count, 2); + $temp1 = hexdec($temp0); + $temp3 = reset(unpack("l", pack("l", $temp1 +0xffffff00))); + $temp4 = pack('C*', $temp3); + + $result = $result.$temp4; + + } + + return $result; + + } + + } +?> diff --git a/shop/kakaopay/lgcns_KMpay.php b/shop/kakaopay/lgcns_KMpay.php new file mode 100644 index 000000000..490df1b8e --- /dev/null +++ b/shop/kakaopay/lgcns_KMpay.php @@ -0,0 +1,381 @@ +LogPath = $LogDir."/"; + } + public function setPhpVersion($version) { + $this->phpVersion = $version; + } + public function parameterEncrypt($key, $plainText) { + try { + $encryptText = ""; + $iv = ""; + if ($key == null || $plainText == null || $key == "" || $plainText == "" || strlen($key) < 16) { + return ""; + } else { + $iv = substr($key, 0, 16); + $encryptText = $this->AESCBCPKCS5($plainText, $key, $iv, "enc", "yes"); + } + return $encryptText; + } catch (Exception $ex) { + $this->writeLog("parameterEncrypt() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function parameterDecrypt($key, $EncryptText) { + try { + $decryptText = ""; + $iv = ""; + if ($key == null || $EncryptText == null || $key == "" || $EncryptText == "" || strlen($key) < 16) { + return "1"; + } else { + $iv = substr($key, 0, 16); + $decryptText = $this->AESCBCPKCS5($EncryptText, $key, $iv, "dec", "yes"); + } + return $decryptText; + } catch (Exception $ex) { + $this->writeLog("parameterDecrypt() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function PKCS5Pad($text, $blocksize = 16) { + try { + $pad = $blocksize - (strlen($text) % $blocksize); + return $text.str_repeat(chr($pad), $pad); + } catch (Exception $ex) { + $this->writeLog("PKCS5Pad() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function PKCS5UnPad($text) { + try { + $pad = ord($text{strlen($text)-1}); + if ($pad > strlen($text)) return $text; + if (!strspn($text, chr($pad), strlen($text) - $pad)) return $text; + return substr($text, 0, -1 * $pad); + } catch (Exception $ex) { + $this->writeLog("PKCS5UnPad() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function encrypt($iv, $key, $str) { + try { + $td = mcrypt_module_open("rijndael-128", "", "cbc", ""); + @mcrypt_generic_init($td, $key, $iv); + $encrypted = @mcrypt_generic($td, $this->PKCS5Pad($str)); + mcrypt_generic_deinit($td); + mcrypt_module_close($td); + return $encrypted; + } catch (Exception $ex) { + $this->writeLog("encrypt() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function decrypt($iv, $key, $code) { + try { + $td = mcrypt_module_open("rijndael-128", "", "cbc", ""); + @mcrypt_generic_init($td, $key, $iv); + $decrypted = @mdecrypt_generic($td, $code); + mcrypt_generic_deinit($td); + mcrypt_module_close($td); + return $this->PKCS5UnPad($decrypted); + } catch (Exception $ex) { + $this->writeLog("decrypt() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function AESCBCPKCS5($source_data, $key, $iv, $mode="enc", $base64="yes") { + try { + if ($mode == "dec") { + if ($base64 == "yes") return $this->decrypt($iv, $key, base64_decode($source_data)); + else return $this->decrypt($iv, $key, $source_data); + } + else { + if ($base64 == "yes") return base64_encode($this->encrypt($iv, $key, $source_data)); + else return $this->encrypt($iv, $key, $source_data); + } + } catch (Exception $ex) { + $this->writeLog("AESCBCPKCS5() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function connMPayDLP($urlStr, $mid, $encryptStr) { + try { + // php에 cURL 모듈 설치 필요(리눅스 - curl.so, 윈도우 - php_curl.dll 확장모듈 필요) + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $urlStr); //접속할 URL 주소 + //curl_setopt($ch, CURLOPT_PORT, 12443); //접속할 port, 주소에 있으므로 설정하지 않음 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 인증서 체크같은데 true 시 안되는 경우가 많다. + //curl_setopt($ch, CURLOPT_SSLVERSION, 3); // SSL 버젼 (https 접속시에 필요, 기본값으로 해야하므로 설정하지 않음) + curl_setopt($ch, CURLOPT_HEADER, 0); // 헤더 출력 여부 + curl_setopt($ch, CURLOPT_POST, 1); // Post Get 접속 여부 + curl_setopt($ch, CURLOPT_POSTFIELDS, array("k" => $mid, "v" => $encryptStr)); // Post 값 Get 방식처럼적는다. + curl_setopt($ch, CURLOPT_TIMEOUT, 30); // TimeOut 값 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 결과값을 받을것인지 + curl_setopt($ch, CURLOPT_USERAGENT, $this->phpVersion); // 버전 + $result = curl_exec($ch); + $errcode = curl_error($ch); + if ($errcode != "") $result = $errcode; + //$errcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + //if ($errcode != 200) $result = $errcode; + curl_close($ch); + return $result; + } catch (Exception $ex) { + $this->writeLog("connMPayDLP() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function writeLog($strLogText) { + $log_string = ""; + if (is_array($strLogText)) { + $log_string = "[".date("Y/m/d H:i:s")."] \r\n"; + foreach (array_keys($strLogText) as $key) { + $log_string = $log_string." [".$key."] => ".$strLogText[$key]."\r\n"; + } + } else { + $log_string = "[".date("Y/m/d H:i:s")."] ".$strLogText."\r\n"; + } + $log_filenm = $this->LogPath.date("Ymd")."_KMpay.log"; + $log_file = fopen($log_filenm, "a"); + if($log_file == false) return; + flock($log_file, LOCK_EX); + //fwrite($log_file, $log_string); + fputs($log_file, $log_string); + fflush($log_file); + flock($log_file, LOCK_UN); + fclose($log_file); + } + } + class JsonString { + private $LogPath = ""; + private $strValues = array(); + public function JsonString($LogDir) { + if (substr($LogDir, strlen($LogDir) - 1) == "/") { + $LogDir = substr($LogDir, 0, strlen($LogDir) - 1); + } + @mkdir($LogDir); + $this->LogPath = $LogDir."/"; + } + public function setValue($key, $value) { + try { + $this->strValues[$key] = $value; + return "_TRUE_"; + } catch (Exception $ex) { + $this->writeLog("setValue() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function getValue($key) { + try { + if (!in_array($key, array_keys($this->strValues))) return ""; + return $this->strValues[$key]; + } catch (Exception $ex) { + $this->writeLog("getValue() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function getArrayValue() { + try { + return $this->strValues; + } catch (Exception $ex) { + $this->writeLog("getArrayValue() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function setJsonString($strJsonString) { + try { + $strJsonString = substr($strJsonString, 2, strlen($strJsonString) - 4); + $strItems = explode("\",\"", $strJsonString); + foreach ($strItems as $strItem) { + $strValue = explode("\":\"", $strItem); + $this->setValue($strValue[0], $strValue[1]); + } + return "_TRUE_"; + } catch (Exception $ex) { + $this->writeLog("setJsonString() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function getJsonString() { + try { + $strJsonString = "{"; + foreach (array_keys($this->strValues) as $key) { + $strJsonString = $strJsonString."\"".$key."\":"; + // 2014.11.25 str_replace 추가 + $strJsonString = $strJsonString."\"". str_replace(array("\\", "\""), array("\\\\", "\\\""), $this->strValues[$key])."\","; + } + $strJsonString = substr($strJsonString, 0, strlen($strJsonString)-1)."}"; + return $strJsonString; + } catch (Exception $ex) { + $this->writeLog("getJsonString() Exception Code ".$ex->getCode()." : ".$ex->getMessage()." in ".$ex->getFile()." on line ".$ex->getLine()); + return "_FAIL_"; + } + } + public function writeLog($strLogText) { + $log_string = ""; + if (is_array($strLogText)) { + $log_string = "[".date("Y/m/d H:i:s")."] \r\n"; + foreach (array_keys($strLogText) as $key) { + $log_string = $log_string." [".$key."] => ".$strLogText[$key]."\r\n"; + } + } else { + $log_string = "[".date("Y/m/d H:i:s")."] ".$strLogText."\r\n"; + } + $log_filenm = $this->LogPath.date("Ymd")."_KMpayLog.log"; + $log_file = fopen($log_filenm, "a"); + if($log_file == false) return; + flock($log_file, LOCK_EX); + //fwrite($log_file, $log_string); + fputs($log_file, $log_string); + fflush($log_file); + flock($log_file, LOCK_UN); + fclose($log_file); + } + } + + class KMPayDataValidator { + public $resultValid = ""; + public function KMPayDataValidator($value) { + $this->resultValid = $this->validator($value); + } + // 2014.12.02 추가 (check key in array) + private function getValueFromArray($arr, $key) { + if(array_key_exists($key, $arr)) { + return $arr[$key]; + } else { + return ""; + } + } + // 2014.12.02 수정 (getValueFromArray 사용) + private function validator($value) { + //필수정보 + $prType = $this->getValueFromArray($value, "PR_TYPE"); + $merchantID = $this->getValueFromArray($value, "MERCHANT_ID"); + $channelType = $this->getValueFromArray($value, "channelType"); + $merchantTxnNum = $this->getValueFromArray($value, "MERCHANT_TXN_NUM"); + $productName = $this->getValueFromArray($value, "PRODUCT_NAME"); + $amount = $this->getValueFromArray($value, "AMOUNT"); + $currency = $this->getValueFromArray($value, "CURRENCY"); + $returnUrl = $this->getValueFromArray($value, "RETURN_URL"); + + //추가정보 + $cardMerchantNum = $this->getValueFromArray($value, "CARD_MERCHANT_NUM"); + $supplyAmt = $this->getValueFromArray($value, "SUPPLY_AMT"); + $goodsVat = $this->getValueFromArray($value, "GOODS_VAT"); + $serviceAmt = $this->getValueFromArray($value, "SERVICE_AMT"); + $cancelTime = $this->getValueFromArray($value, "CANCEL_TIME"); + $fixedInt = $this->getValueFromArray($value, "FIXED_INT"); + $certifiedFlag = $this->getValueFromArray($value, "CERTIFIED_FLAG"); + $offerPeriodFlag = $this->getValueFromArray($value, "OFFER_PERIOD_FLAG"); + $offerPeriod = $this->getValueFromArray($value, "OFFER_PERIOD"); + + + if (strlen($certifiedFlag) == 0) { + $certifiedFlag = "N"; + } + if (strlen($supplyAmt) == 0) { + $supplyAmt = "0"; + } + if (strlen($goodsVat) == 0) { + $goodsVat = "0"; + } + if (strlen($cancelTime) == 0) { + $cancelTime = "1440"; + } + + //필수 + if (strlen($prType) == 0) { + return "USER_ERROR_CODE,804,결제요청타입은 필수입력사항 입니다."; + } + else if ($prType != "MPM" && $prType != "WPM") { + return "USER_ERROR_CODE,805,잘못된 결제요청타입 입니다."; + } + + if (strlen($merchantID) == 0) { + return "USER_ERROR_CODE,806,가맹점 ID 필수입력사항 입니다."; + } + else if (strlen($merchantID) > 38) { + return "USER_ERROR_CODE,808,가맹점 ID의 제한 길이가 초과 되었습니다."; + } + + if (strlen($merchantTxnNum) == 0) { + return "USER_ERROR_CODE,823,가맹점 거래번호는 필수입력사항 입니다."; + } + else if (strlen($merchantTxnNum) > 40) { + return "USER_ERROR_CODE,824,가맹점 거래번호의 제한 길이가 초과 되었습니다."; + } + + if (strlen($productName) == 0) { + return "USER_ERROR_CODE,809,상품명은 필수입력사항 입니다."; + } + else if (strlen($productName) > 200) { + return "USER_ERROR_CODE,810,상품명은 영문 200자 이내입니다."; + } + + if (strlen($amount) == 0) { + return "USER_ERROR_CODE,811,상품금액은 필수입력사항 입니다."; + } + else if (!is_numeric($amount)){ + return "USER_ERROR_CODE,812,상품금액은 숫자형입니다."; + } + + if (strlen($currency) == 0) { + return "USER_ERROR_CODE,813,거래통화는 필수입력사항 입니다."; + } + + if ($certifiedFlag == "CN") { + //웹결제에서는 필수체크 안함 + } + else if (strlen($certifiedFlag) == 0) { + return "USER_ERROR_CODE,830,결제승인결과전송URL은 필수입력사항 입니다."; + } + + if (strlen($cardMerchantNum) > 0 && !is_numeric($cardMerchantNum)) { + return "USER_ERROR_CODE,814,카드 가맹점 번호는 숫자형입니다."; + } + + if (strlen($supplyAmt) > 0 && !is_numeric($supplyAmt)) { + return "USER_ERROR_CODE,815,공급가액은 숫자형입니다."; + } + + if (strlen($goodsVat) > 0 && !is_numeric($goodsVat)) { + return "USER_ERROR_CODE,816,부가세는 숫자형입니다."; + } + + if (strlen($serviceAmt) > 0 && !is_numeric($serviceAmt)) { + return "USER_ERROR_CODE,817,봉사료는 숫자형입니다."; + } + + if (strlen($cancelTime) > 0 && !is_numeric($cancelTime)) { + return "USER_ERROR_CODE,818,결제취소시간(분)은 숫자형입니다."; + } + + if (strlen($fixedInt) == 0) { + // 정상 + } + else if (!is_numeric($fixedInt)) { + return "USER_ERROR_CODE,820,고정할부개월이 잘못되었습니다."; + } + else if (!((0 <= intval($fixedInt) && intval($fixedInt) <= 24) || $fixedInt == "36")) { + return "USER_ERROR_CODE,820,고정할부개월이 잘못되었습니다."; + } + + if ($certifiedFlag != "N" && $certifiedFlag != "CN") { + return "USER_ERROR_CODE,831,가맹점 인증 구분값은 N 혹은 CN 입니다"; + } + + return ""; + } + } +?> \ No newline at end of file diff --git a/shop/kakaopay/makehashdata.php b/shop/kakaopay/makehashdata.php new file mode 100644 index 000000000..e35eaed61 --- /dev/null +++ b/shop/kakaopay/makehashdata.php @@ -0,0 +1,21 @@ +makeHashInputString($salt); +$hash_calc = hash("sha256", $hash_input, false); +$hash_String = base64_encode($hash_calc); + +die(json_encode(array('hash_String' => $hash_String, 'error' => ''))); +?> \ No newline at end of file diff --git a/shop/kakaopay/orderform.1.php b/shop/kakaopay/orderform.1.php new file mode 100644 index 000000000..2ecf87f84 --- /dev/null +++ b/shop/kakaopay/orderform.1.php @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/shop/kakaopay/orderform.2.php b/shop/kakaopay/orderform.2.php new file mode 100644 index 000000000..090c4f607 --- /dev/null +++ b/shop/kakaopay/orderform.2.php @@ -0,0 +1,33 @@ + + +
+ + + + + + + + + + + + + + + + + + + +
+ + \ No newline at end of file diff --git a/shop/kakaopay/orderform.3.php b/shop/kakaopay/orderform.3.php new file mode 100644 index 000000000..24c25e0b4 --- /dev/null +++ b/shop/kakaopay/orderform.3.php @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/shop/orderform.php b/shop/orderform.php index 33e159240..89b868b22 100644 --- a/shop/orderform.php +++ b/shop/orderform.php @@ -53,9 +53,14 @@ $s_cart_id = $tmp_cart_id; $order_action_url = G5_HTTPS_SHOP_URL.'/orderformupdate.php'; require_once('./settle_'.$default['de_pg_service'].'.inc.php'); +require_once('./settle_kakaopay.inc.php'); // 결제대행사별 코드 include (스크립트 등) require_once('./'.$default['de_pg_service'].'/orderform.1.php'); + +if($is_kakaopay_use) { + require_once('./kakaopay/orderform.1.php'); +} ?> @@ -298,6 +303,10 @@ require_once('./'.$default['de_pg_service'].'/orderform.1.php'); @@ -579,11 +588,18 @@ require_once('./'.$default['de_pg_service'].'/orderform.1.php'); $escrow_title = "에스크로 "; } - if ($default['de_bank_use'] || $default['de_vbank_use'] || $default['de_iche_use'] || $default['de_card_use'] || $default['de_hp_use'] || $default['de_easy_pay_use']) { + if ($is_kakaopay_use || $default['de_bank_use'] || $default['de_vbank_use'] || $default['de_iche_use'] || $default['de_card_use'] || $default['de_hp_use'] || $default['de_easy_pay_use']) { echo '
'; echo '결제방법 선택'; } + // 카카오페이 + if($is_kakaopay_use) { + $multi_settle++; + echo ' '.PHP_EOL; + $checked = ''; + } + // 무통장입금 사용 if ($default['de_bank_use']) { $multi_settle++; @@ -705,6 +721,10 @@ require_once('./'.$default['de_pg_service'].'/orderform.1.php'); @@ -956,7 +976,7 @@ $(function() { $("#settle_bank").show(); }); - $("#od_settle_iche,#od_settle_card,#od_settle_vbank,#od_settle_hp,#od_settle_easy_pay").bind("click", function() { + $("#od_settle_iche,#od_settle_card,#od_settle_vbank,#od_settle_hp,#od_settle_easy_pay,#od_settle_kakaopay").bind("click", function() { $("#settle_bank").hide(); }); @@ -1324,6 +1344,12 @@ function forderform_check(f) calculate_tax(); + // 카카오페이 지불 + if(settle_method == "KAKAOPAY") { + getTxnId(f); + return false; + } + // pay_method 설정 f.site_cd.value = f.def_site_cd.value; diff --git a/shop/orderformupdate.php b/shop/orderformupdate.php index 9bacbb352..b8d7896ac 100644 --- a/shop/orderformupdate.php +++ b/shop/orderformupdate.php @@ -403,22 +403,43 @@ else if ($od_settle_case == "간편결제") if($od_misu == 0) $od_status = '입금'; } +else if ($od_settle_case == "KAKAOPAY") +{ + include G5_SHOP_PATH.'/kakaopay/kakaopay_result.php'; + + $od_tno = $tno; + $od_app_no = $app_no; + $od_receipt_price = $amount; + $od_receipt_point = $i_temp_point; + $od_receipt_time = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $app_time); + $od_bank_account = $card_name; + $pg_price = $amount; + $od_misu = $i_price - $od_receipt_price; + if($od_misu == 0) + $od_status = '입금'; +} else { die("od_settle_case Error!!!"); } +$od_pg = $default['de_pg_service']; +if($od_settle_case == 'KAKAOPAY') + $od_pg = 'KAKAOPAY'; + // 주문금액과 결제금액이 일치하는지 체크 if($tno) { if((int)$order_price !== (int)$pg_price) { $cancel_msg = '결제금액 불일치'; - switch($default['de_pg_service']) { + switch($od_pg) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_cancel.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_cancel.php'; break; + case 'KAKAOPAY': + break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub_cancel.php'; break; @@ -450,7 +471,6 @@ if($default['de_tax_flag_use']) { $od_free_mny = (int)$_POST['comm_free_mny']; } -$od_pg = $default['de_pg_service']; $od_email = get_email_address($od_email); $od_name = clean_xss_tags($od_name); $od_tel = clean_xss_tags($od_tel); @@ -531,13 +551,15 @@ $result = sql_query($sql, false); if(!$result) { if($tno) { $cancel_msg = '주문정보 입력 오류'; - switch($default['de_pg_service']) { + switch($od_pg) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_cancel.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_cancel.php'; break; + case 'KAKAOPAY': + break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub_cancel.php'; break; @@ -548,7 +570,7 @@ if(!$result) { $error = 'order'; include G5_SHOP_PATH.'/ordererrormail.php'; - die('

고객님의 주문 정보를 처리하는 중 오류가 발생해서 주문이 완료되지 않았습니다.

'.strtoupper($default['de_pg_service']).'를 이용한 전자결제(신용카드, 계좌이체, 가상계좌 등)은 자동 취소되었습니다.'); + die('

고객님의 주문 정보를 처리하는 중 오류가 발생해서 주문이 완료되지 않았습니다.

'.strtoupper($od_pg).'를 이용한 전자결제(신용카드, 계좌이체, 가상계좌 등)은 자동 취소되었습니다.'); } // 장바구니 상태변경 @@ -570,13 +592,15 @@ $result = sql_query($sql, false); if(!$result) { if($tno) { $cancel_msg = '주문상태 변경 오류'; - switch($default['de_pg_service']) { + switch($od_pg) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_cancel.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_cancel.php'; break; + case 'KAKAOPAY': + break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub_cancel.php'; break; @@ -590,7 +614,7 @@ if(!$result) { // 주문삭제 sql_query(" delete from {$g5['g5_shop_order_table']} where od_id = '$od_id' "); - die('

고객님의 주문 정보를 처리하는 중 오류가 발생해서 주문이 완료되지 않았습니다.

'.strtoupper($default['de_pg_service']).'를 이용한 전자결제(신용카드, 계좌이체, 가상계좌 등)은 자동 취소되었습니다.'); + die('

고객님의 주문 정보를 처리하는 중 오류가 발생해서 주문이 완료되지 않았습니다.

'.strtoupper($od_pg).'를 이용한 전자결제(신용카드, 계좌이체, 가상계좌 등)은 자동 취소되었습니다.'); } // 회원이면서 포인트를 사용했다면 테이블에 사용을 추가 diff --git a/shop/settle_kakaopay.inc.php b/shop/settle_kakaopay.inc.php new file mode 100644 index 000000000..4032d6b51 --- /dev/null +++ b/shop/settle_kakaopay.inc.php @@ -0,0 +1,9 @@ + \ No newline at end of file