# 네이버페이 연동 가이드

## 1. 네이버페이 타입 <a href="#npay-type" id="npay-type"></a>

***

네이버페이에는 '결제형'과 '주문형' 두 가지 서비스 타입이 있습니다.

-결제형 : 결제수단의 하나로 네이버페이 간편결제가 제공됩니다.\
결제 이후 쇼핑몰의 구매완료 페이지에 돌아오기 때문에 에이스카운터 스크립트로 분석이 가능합니다.

-주문형 : 네이버 ID 로그인 후 네이버 쇼핑으로 넘어가 구매완료까지 이루어집니다.\
본 가이드를 참고해 네이버페이 연동 세팅을 해야만 주문형에 대한 네이버페이 분석이 가능합니다.

<figure><img src="/files/t2Hf69d0zMt9GTM5ZTag" alt=""><figcaption><p>네이버 페이 &#x26; 에이스카운터 연동을 위해서는 <strong>네이버페이 가맹점 연동 가이드</strong>에 대한 숙지가 되어 있어야 합니다.</p></figcaption></figure>

## 2. 네이버페이 연동 프로세스 <a href="#npay-process" id="npay-process"></a>

***

<figure><img src="/files/Kt82Yh3WVEaWcGmZiWhn" alt=""><figcaption><p>*에이스카운터 연동 가이드 참고 페이지 => 인증키 획득(P5), 인증키 세팅(P6), 응답 데이터 전송(P8)</p></figcaption></figure>

## 3. 네이버페이 연동 방법 <a href="#npay-method" id="npay-method"></a>

***

### 1) 제품상세 페이지 - 에이스인증키 획득 (공통) <a href="#npay-step1" id="npay-step1"></a>

* 네이버페이 버튼 핸들러 함수(buy\_nc)에서 에이스인증키 획득
* 획득한 에이스 인증키를 주문정보 등록 URL 파라미터로 전송

<pre><code>function buy_nc(url) { 
<strong> varcheck = checkOption(...) ... 
</strong><strong> 
</strong> if (check) {
    try { 
        varacePid= window._AcePID; // 에이스인증키획득
    } catch (e) {} 
 location.href= url+ "?customcode=" + acePid;// 에이스인증키를주문정보등록url파라미터로전송
 }
}
</code></pre>

\[참고] 네이버페이 가맹점 연동 가이드.pdf - 2.2 네이버페이 버튼 동작

### 2) 주문 정보 등록 페이지 - 에이스 인증키 세팅 <a href="#npay-step2" id="npay-step2"></a>

주문정보 등록시 merchantCustomCode1 요소의 값으로 앞 단계에서 획득한\
에이스인증키 값을 넣어서 주문서 등록을 진행 (1.0버전은 MALL\_MANAGE\_CODE)

#### **네이버 페이 API 버전 별 차이**

|                        버전                        |                   v 1.0(= API 4.1)                  |                   v2.1 (= API 5.0)                   |
| :----------------------------------------------: | :-------------------------------------------------: | :--------------------------------------------------: |
|                    주문등록 데이터 방식                   |                        쿼리스트링                        |                          XML                         |
| <mark style="color:blue;">'에이스인증키' 저장 key</mark> | <mark style="color:blue;">MALL\_MANAGE\_CODE</mark> | <mark style="color:blue;">merchantCustomCode1</mark> |

#### 1.0 버전(쿼리스트링)

<pre><code> &#x3C;?
 ...
 // 에이스인증키를MALL_MANAGE_CODE 로설정
if (isset($_REQUEST["customcode"])) { 
<strong> $queryString .= 
</strong>  ‘&#x26;MALL_MANAGE_CODE=‘.
   $_REQUEST["customcode"]; 
}
...
 ?>
</code></pre>

\[참고] 네이버페이 가맹점 연동 가이드.pdf-3.1.2 주문 정보 등록

#### 2.1 버전 (XML)

<pre><code>&#x3C;!– 에이스인증키를MerchantCustomCode1 로설정-->
&#x3C;order>
 &#x3C;merchantId>상점ID&#x3C;/merchantId>
 &#x3C;certiKey>인증키&#x3C;/certiKey>
 ...
<strong> &#x3C;interface>
</strong>  &#x3C; merchantCustomCode1>에이스인증키
&#x3C;/merchantCustomCode1 >
 &#x3C;/interface>
 ...
 &#x3C;/order>
</code></pre>

```
<? 
...
 // xml 생성하기 위한 php코드
if (isset($_REQUEST["customcode"])) {
 $data .=
 '<interface>< merchantCustomCode1>＇.
 $_REQUEST["customcode"] .
 }
 ... 
?>
```

### 3) 주문 정보 조회 페이지 - 응답 데이터를 에이스카운터로 전송 <a href="#npay-step3" id="npay-step3"></a>

* 전송 조건 : 네이버페이 API GetProductOrderInfoList 를 이용하면 결제 완료된 상품리스트를 응답 받는다.\
  응답 데이터에 <mark style="color:blue;">MerchantCustomCode1 속성이 있고 빈 값이 아닌 경우에만 전송한다.</mark>\ <mark style="color:red;">(네이버페이 API 4.1버전은 MallManageCode 속성값 사용)</mark>
* 전송 방법 : HTTPS 통신이 가능한 cURL 또는 그 외 HTTPS 통신 툴
* 전송 URL : 응답 데이터 중 MerchantCustomCode1 속성값\ <mark style="color:red;">(네이버페이 API 4.1 버전은 MallManageCode 속성값 사용)</mark>

#### **파라미터**

<table><thead><tr><th width="120" align="center">필드명</th><th width="100" align="center">타입</th><th width="100" align="center">필수 여부(Y/N)</th><th>설명</th></tr></thead><tbody><tr><td align="center">orderNo</td><td align="center">string</td><td align="center">Y</td><td>주문번호. 전달받은 주문번호를 입력</td></tr><tr><td align="center">pay</td><td align="center">string</td><td align="center">Y</td><td>결제수단. 전달받은 결제수단을 입력</td></tr><tr><td align="center">ll</td><td align="center">string</td><td align="center">Y</td><td>상품 리스트. 상품의 속성은 @로 구분하고<br>여러 상품의 묶음은 ^로 구분해서 생성한다.<br>('상품리스트 생성' 페이지참고)</td></tr></tbody></table>

#### 주의사항

> 1\. 전송 URL 끝에 <mark style="color:red;">**&**</mark>을 반드시 추가하세요\
> ex : $curl="https\://".$MerchantCustomCode1."\&ll=".$ll."\&pay=".$sPay."\&orderno=".$sOrderno.<mark style="color:red;">**"&"**</mark>;
>
> 2\. <mark style="background-color:red;">**중복수집 예방을 위해 주문은 최초 1회만 전송하세요.**</mark>

#### 네이버 페이 API 4.1 버전

```
<?
 //네이버페이API 4.1버전–MallManageCode사용
//GetProductOrderListAPI요청
// MallManageCode예시-> gtp4.acecounter.com/?cuid=AH1A418…(생략)
 $sOrderNo= {주문번호};
 $sPay= {결제수단};
 $ll= {상품리스트};
 $curl = https:// . $MallManageCode. 
"&ll=” . $ll . "&pay=" . $sPay. "&orderno=" . $sOrderNo. "&"; 
$ch= curl_init(); 
curl_setopt($ch, CURLOPT_URL, $curl); 
curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 $ret = curl_exec($ch); 
curl_close($ch); 
?>
```

#### 네이버 페이 API 5.0 버전

```
<?
 //네이버페이API 5.0버전-MerchantCustomCode1사용
//GetProductOrderListAPI 요청
// MerchantCustomCode1 예시-> gtp4.acecounter.com/?cuid=AH1A418…(생략)
 $sOrderNo= {주문번호};
 $sPay= {결제수단};
 $ll= {상품리스트};
 $curl = "https://" . $MerchantCustomCode1. 
"&ll=" . $ll. "&pay=" . $sPay. "&orderno=" . $sOrderNo. "&"; 
$ch= curl_init(); 
curl_setopt($ch, CURLOPT_URL, $curl); 
curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 $ret = curl_exec($ch); 
curl_close($ch); 
?>
```

### 4) 주문 정보 조회 페이지 - 상품리스트 생성 <a href="#npay-step4" id="npay-step4"></a>

* 상품의 속성은 @로 구분하고 여러 상품의 묶음은 ^로 구분해서 생성합니다.
* 상품 가격은 상품 소계(각 상품의 구매 합계)입니다.

```
<?
 $productArray = array();
 $cnt = 0; 
// 구매상품을A와B 라고가정, 구매상품만큼배열추가
$ornList[] = array("pcategory"=>A상품카테고리, "pname"=>A상품명, "pcode"=>A상품번호, "pprice"=>A상품가격, "pquantity"=>A구매개수); 
$ornList[] = array("pcategory"=>B상품카테고리, "pname"=>B상품명, "pcode"=>B상품번호, "pprice"=>B상품가격, "pquantity"=>B구매개수, "opt"=>B옵션명); 
// 특수문자(#&^@,) & 태그제거함수
function removeStr($s, $m=0) {
 $ret= "";
 if ($m === 1) { 
$ret = preg_replace("/[#&^@,]*/s", "", $s);
 } else if ($m === 2) { 
$ret = preg_replace("/[<][^>]*[>]*/s", "", $s); 
$ret = preg_replace("/[#&^@,]*/s", "", $ret); 
} else { $ret = preg_replace("/[#&^@,]*/s", "", $s); } 
return $ret; 
} 
// 상품리스트를스트링으로변환해배열로저장
foreach ($ornList as $pVal) {
 $strTemp= "";
 $pCategory= removeStr($pVal['pcategory']);
 $pName = removeStr($pVal['pname'], 2);
 $pCode = removeStr($pVal['pcode']);
 $pPrice = removeStr($pVal['pprice'], 1);
 $pQuantity= removeStr($pVal['pquantity'], 1);
 $pOptName= removeStr($pVal['opt'], 1); 
// 표준형식: 카테고리명@상품명@상품가격@수량@상품ID@옵션명
$strTemp= $pCategory. "@" . $pName. "@" . $pPrice. "@" . $pQuantity. "@" . $pCode. "@" . $pOptName; 
$productArray[$cnt] = $strTemp; $cnt++; 
}
 $sOrderNo= "{주문번호}";
 $sPay= "{결제수단}";
 $ll= urlencode(implode("^", $productArray) . "^"); // 상품리스트
?>
```

### 5) 데이터 확인 <a href="#npay-step5" id="npay-step5"></a>

에이스카운터에 로그인하여 데이터 확인이 가능합니다.

* 메뉴 위치 : **에이스카운터 로그인 > 분석통계 > 구매자 > 결제 수단 분석**
* 구매자의 브라우저가 종료되면 약 40분 정도 이후에 데이터가 확인됩니다.

<figure><img src="/files/DvBje0pfOn2NWbZ7LxM4" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://acecounter.gitbook.io/guide/script-setting/install/npay.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
