[이니시스/PG] Mobile 모듈 붙이기 프로그래밍
2016.12.28 10:21 Edit
저번에 WebStandard 모듈 포스팅에 이어
이니시스 Mobile 용 붙이기 입니다.
설치 전체조건 :
httpClient(http Background) 통신이 가능한 웹서버, DBMS, PHP 4.3.4 이상
꽤 옛날에 작성한 api인지.. euc-kr 로 데이터를 넘겨야하며.....
메뉴얼에는 1트랜잭션(1 Transaction), 2트랜잭션(2 Transaction) 방식 2가지가 있는데
2트랜잭션(2 Transaction) 방식만 쓰이는듯......
그러므로 2트랜잭션(2 Transaction) 방식으로 설명합니다.
1. 이니시스 INIpay(Mobile) 다운로드 받기
2. 압축풀기
- inicis.com\INIpay(Mobile)\INIpayMobile_WEBmanual\Mobile Sample
3. INIpayMobile_Sample.html 모듈 요청페이지를 커스터마이징(form 요청, input 값 셋팅)
<form id="form1" name="ini" method="post" action="" accept-charset="EUC-KR"> <input type="hidden" name="inipaymobile_type" value="web" /> <!-- 기본값 --> <input type="hidden" name="paymethod" value="wcard" /> <!-- 결제방법 --> <input type="hidden" name="P_MID" value="<?=$mid?>" /> <!-- 이니시스 에서 발급받은 mid 값 --> <input type="hidden" name="P_OID" value="<?=$P_OID?>" /> <!-- 상점에서 생성한 주문번호 --> <input type="hidden" name="P_AMT" value="<?=$nTotalPrice?>" /> <!-- 상품결제요청 가격 --> <input type="hidden" name="P_UNAME" value="<?=$strArrUser[0]['user_nm']?>" /> <!-- 결제요청 user 이름 --> <input type="hidden" name="P_MNAME" value="store" /> <!-- 상점이름 --> <input type="hidden" name="P_NOTI" value="<?=$P_NOTI?>" /> <!-- 인증 성공시 가맹점으로 리턴변수(개발자 개인변수) --> <input type="hidden" name="P_GOODS" value="<?=$strGoodsName?>" /> <!-- 상품이름 --> <input type="hidden" name="P_MOBILE" value="" /> <!-- 결제요청 user 전화번호 --> <input type="hidden" name="P_EMAIL" value="<?=$strArrUser[0]['email']?>" /> <!-- user 메일 --> <input type="hidden" name="P_HPP_METHOD" value="2"> <!-- 휴대폰 결제일때 컨텐츠/실물 여부 --> <input type="hidden" name="P_RESERVED" value="twotrs_isp=Y&block_isp=Y&twotrs_isp_noti=N&ismart_use_sign=Y&vbank_receipt=Y&bank_receipt=N&apprun_check=Y" /> <!-- 결제옵션 파라미터 --> <input type="hidden" name="P_NEXT_URL" value="<?=$_SERVER['REQUEST_SCHEME']?>://<?=$config['domain']?>/order_inicis_step1.php" /> <!-- 결제요청 처리 url --> </form> <script> jQuery(document).ready( function() { // 결제버튼 클릭시 jQuery('.btn-join').click( function() { on_web(); } ); } ); function on_web() { var order_form = document.ini; var paymethod = order_form.paymethod.value; order_form.action = "https://mobile.inicis.com/smart/" + paymethod + "/"; order_form.submit(); } </script>
5. 결제완료시 P_NEXT_URL 변수에 있는 url로 이동후 처리(order_inicis_step1.php)
$P_STATUS = $_REQUEST['P_STATUS']; $P_REQ_URL = $_REQUEST['P_REQ_URL']; $P_TID = $_REQUEST['P_TID']; $P_MID = !isset($_REQUEST['P_MID']) ? 'INIpayTest' : $_REQUEST['P_MID']; $oP_NOTI = json_decode(mb_convert_encoding(str_replace("'",'"', stripslashes($_REQUEST['P_NOTI'])), 'UTF-8', 'EUC-KR')); // 성공이 아닐경우 if( $P_STATUS != '00' ) { //echo '주문이 실패하였습니다! 관리자에게 문의해주세요!(9)'; return; } // 메세지 utf-8 치환 $_REQUEST['P_RMESG1'] = iconv('EUC-KR', 'UTF-8', $_REQUEST['P_RMESG1']); // sql에 넣을 배열 생성 $strArrFirstPGReq = $_REQUEST; $strArrFirstPGReq['P_NOTI'] = mb_convert_encoding(stripslashes($_REQUEST['P_NOTI']), 'UTF-8', 'EUC-KR'); // 쓰지않는 컬럼삭제 unset($strArrFirstPGReq['P_REQ_URL']); unset($strArrFirstPGReq['P_OID']); // filed 생성 $strPGFiled = strtolower(implode(', ', array_keys($strArrFirstPGReq))); // value 생성 $strPGValue = '"'; $strPGValue .= implode('","', array_values($strArrFirstPGReq)); $strPGValue .= '"'; // 기승인 TID 여부 확인 $strArrPG = sql_fetch('SELECT * FROM pg_mobile WHERE user_id = ? AND p_tid = ?', array($oP_NOTI->user_id, $P_TID), 0); if( count($strArrPG) >= 1 ) { //echo '이미 주문접수가 되어있습니다! 다시시도해주세요! (10)'; return; } $oDBConnect->beginTransaction(); try { //******************************************* // pg_mobile 저장 & pg기승인 START //******************************************* // 기승인된 TID 를 DB 에 저장 $strPGSql = "INSERT INTO pg_mobile (user_id, $strPGFiled, p_oid, cret_id, cret_ip, cret_dtm) "; $strPGSql .= "VALUES (?, $strPGValue, ?, ?, ?, ?)"; $oResult = sql_query($strPGSql, array( $oP_NOTI->user_id, $oP_NOTI->P_OID, $oP_NOTI->user_id, $config['ip'], $config['date3'] )); if( $oResult->errorInfo()[0] != 0000 ) { throw new Exception('주문이 실패하였습니다! 관리자에게 문의해주세요!(1)'); } // 데이터 수신 $output = array(); $params = array( 'P_TID' => $P_TID, 'P_MID' => $P_MID ); $r = request_curl($_REQUEST['P_REQ_URL'], 1, $params); parse_str($r[0], $output); // 글자 utf-8로 변경 if( !empty($output['P_RMESG1']) ) $output['P_RMESG1'] = iconv('EUC-KR', 'UTF-8', $output['P_RMESG1']); if( !empty($output['P_UNAME']) ) $output['P_UNAME'] = iconv('EUC-KR', 'UTF-8', $output['P_UNAME']); if( !empty($output['P_VACT_NAME']) ) $output['P_VACT_NAME'] = iconv('EUC-KR', 'UTF-8', $output['P_VACT_NAME']); if( !empty($output['P_FN_NM']) ) $output['P_FN_NM'] = iconv('EUC-KR', 'UTF-8', $output['P_FN_NM']); if( !empty($output['P_CARD_ISSUER_NAME']) ) $P_CARD_ISSUER_NAME = iconv('EUC-KR', 'UTF-8', $output['P_CARD_ISSUER_NAME']); if( !empty($output['P_CARD_PURCHASE_NAME']) ) $P_CARD_PURCHASE_NAME = iconv('EUC-KR', 'UTF-8', $output['P_CARD_PURCHASE_NAME']); // 데이터수신이 성공인지 if( $output['P_STATUS'] != '00' ) { throw new Exception('주문이 실패하였습니다! 관리자에게 문의해주세요!(2)'); } // 셋팅된 가격과 결제금액이 맞는지 체크 if( $output['P_AMT'] != $oP_NOTI->prn_s ) { throw new Exception('가격에 오류가 있습니다! 관리자에게 문의해주세요!(2-1)'); } // 필요없는 데이터 삭제 unset($output['P_TID']); unset($output['P_OID']); unset($output['P_NOTI']); unset($output['P_CARD_ISSUER_NAME']); unset($output['P_CARD_PURCHASE_NAME']); unset($output['P_CARD_APPLPRICE']); unset($output['P_APPL_NUM']); $strPGUpdateSql = ''; foreach( $output as $key => $val ) { $strPGUpdateSql .= strtolower($key)."='".$val."', "; } $strPGUpdateSql = substr($strPGUpdateSql, 0, -2); $strPGSql = "UPDATE pg_mobile SET $strPGUpdateSql "; $strPGSql .= "WHERE user_id = ? AND p_tid = ? AND p_oid = ?"; $oResult = sql_query($strPGSql, array($oP_NOTI->user_id, $P_TID, $oP_NOTI->P_OID)); //echo $strPGSql; if( $oResult->errorInfo()[0] != 0000 ) { throw new Exception('주문이 실패하였습니다! 관리자에게 문의해주세요!(3)'); } //******************************************* // pg_mobile 저장 & pg기승인 END //******************************************* //******************************************* // 주문테이블에 주문서 집어넣기 START //******************************************* // order에 주문서 insert $strOrderSql = "INSERT INTO order ($strFileds, cret_id, cret_ip, cret_dtm) "; $strOrderSql .= "VALUES ($strValues, ?, ?, ?)"; $oResult = sql_query($strOrderSql, array( $oP_NOTI->user_id, $config['ip'], $config['date3'] )); if( $oResult->errorInfo()[0] != 0000 ) { throw new Exception('주문이 실패하였습니다! 관리자에게 문의해주세요!(4)'); } // order_item 에 아이템 insert $nArrGoodsEa = explode('|', $oP_NOTI->ea); $nArrDeliveryPrice = explode('|', $oP_NOTI->d_price); $nArrDeliveryType = explode('|', $oP_NOTI->d_type); foreach( explode('|', $oP_NOTI->goods_id) as $key => $val ) { $strOrderSql = "INSERT INTO order_item ($strFileds, cret_id, cret_ip, cret_dtm) "; $strOrderSql .= "VALUES ($strValues, ?, ?, ?)"; $oResult = sql_query($strOrderSql, array( $oP_NOTI->user_id, $config['ip'], $config['date3'] )); if( $oResult->errorInfo()[0] != 0000 ) { throw new Exception('주문이 실패하였습니다! 관리자에게 문의해주세요!(5)'); } // order_item_option 에 아이템 insert // Todo... // .... // .... // order_delivery 에 배송정보 insert $strOrderSql = "INSERT INTO order_delivery ($strFileds, cret_id, cret_ip, cret_dtm) "; $strOrderSql .= "VALUES ($strValues, ?, ?, ?)"; $oResult = sql_query($strOrderSql, array( $oP_NOTI->user_id, $config['ip'], $config['date3'] )); if( $oResult->errorInfo()[0] != 0000 ) { throw new Exception('주문이 실패하였습니다! 관리자에게 문의해주세요!(6)'); } } //******************************************* // 주문테이블에 주문서 집어넣기 END //******************************************* $oDBConnect->commit(); } catch( Exception $e ) { $oDBConnect->rollBack(); //echo $e->getMessage(); echo "<script>alert('".$e->getMessage()."');location.replace('../index.php');</script>"; return; } // 가상계좌 일경우 가상계좌안내 페이지로 이동 if( $nPtype == 3 ) { /* echo '*****가상계좌 안내*****'; echo '계좌번호 : ' . $output['P_VACT_NUM']; echo '입금마감일자 : ' . $output['P_VACT_DATE']; echo '입금마감시간 : ' . $output['P_VACT_TIME']; echo '계좌주명 : ' . $output['P_VACT_NAME']; echo '은행 : ' . getBankName($output['P_VACT_BANK_CODE']); echo '결제금액 : ' . $output['P_AMT']; */ require_once './order_finish.php'; // 신용카드 일경우 결제완료 페이지로 이동 } else if( $nPtype == 1 ) { /* echo '*****결제승인 안내*****'; echo '결제카드 : ' . $P_CARD_ISSUER_NAME; echo '카드번호 : ' . $output['P_CARD_NUM']; echo 'PG승인번호 : ' . $output['P_AUTH_NO']; echo 'PG승인카드번호 : ' . $output['P_ISP_CARDCODE']; echo 'PG승인시각 : ' . $output['P_AUTH_DT']; echo '결제금액 : ' . $output['P_AMT']; */ require_once './pay_finish.php'; // 휴대폰 일경우 결제완료 페이지로 이동 } else if( $nPtype == 4 ) { /* echo '*****결제승인 안내*****'; echo '결제통신사 : ' . $output['P_HPP_CORP']; echo '결제번호 : ' . $output['P_HPP_NUM']; echo '결제금액 : ' . $output['P_AMT']; */ require_once './pay_finish.php'; }
WebStandard 모듈에 비해 간단하기는 하나..
예외사항이 많아서 처음에 구현할때 이니시스에 전화를 몇번을 했는지...
메뉴얼이 아직 업데이트 안되있다고 개소리를 하지않나...
스트레스 많아받음...ㅠㅠ