튜토리얼
Node.js 개발환경에서 팝빌 SDK를 추가하고, 사업자등록상태 대량조회 (CheckCorpNums) API를 호출하는 기본 과정을 단계별로 따라 해볼 수 있도록 구성된 가이드 입니다.
1. POPBiLL SDK 추가
팝빌 Node.js SDK를 추가하기 위해 Express 프로젝트 "package.json" 파일에 팝빌 Node.js SDK 정보를 추가하고 npm install 또는 npm update를 진행합니다.
{
"name": "Popbill TEST",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"ejs": "~2.5.7",
"express": "~4.16.0",
"http-errors": "~1.6.2",
"morgan": "~1.9.0",
"popbill": "^1.63.0"
}
}
2. POPBiLL SDK 설정
프로젝트 routes 폴더 하위의 index.js 파일에 연동신청시 발급받은 API Key 를 변수로 선언하고 아래의 코드를 참조하여 사업자등록상태조회 서비스 객체를 생성 합니다.
// 생략..
var popbill = require('popbill');
popbill.config( {
// 링크아이디
LinkID :'TESTER',
// 비밀키
SecretKey : 'SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3T=',
// 연동환경 설정, true-테스트, false-운영(Production), (기본값:false)
IsTest : true,
// 통신 IP 고정, true-사용, false-미사용, (기본값:true)
IPRestrictOnOff: true,
// 팝빌 API 서비스 고정 IP 사용여부, 기본값(false)
UseStaticIP: false,
// 로컬시스템 시간 사용여부, true-사용, false-미사용, (기본값:true)
UseLocalTimeYN: true,
defaultErrorHandler: function (Error) {
console.log('Error Occur : [' + Error.code + '] ' + Error.message);
}
});
// 사업자등록상태조회 서비스 객체 초기화
var closedownService = popbill.ClosedownService();
// 생략..
3. CheckCorpNums 기능 구현
index.js 파일에 사업자등록상태 대량조회 (CheckCorpNums) 함수 호출 코드를 추가합니다.
router.get('/checkCorpNums', function (req, res, next) {
// 팝빌회원 사업자번호, '-' 제외 10자리
var testCorpNum = '1234567890';
// 조회 사업자번호 배열, 최대 1,000건
var checkCorpNumList = ['1234567890', '6798700433', '401-03-94930'];
closedownService.checkCorpNums(testCorpNum, checkCorpNumList,
function (CorpState) {
res.render('CheckCorpNums', {path: req.path, result: CorpState});
}, function (Error) {
res.render('response', {path: req.path, code: Error.code, message: Error.message});
});
});
함수 호출결과 코드와 메시지를 출력하는 "/views/CheckCorpNums.ejs" 파일을 추가합니다.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" th:href="${uncached.getForLookupPath('/stylesheets/style.css')}" media="screen"/>
<title>Popbill Closedown.</title>
</head>
<body>
<div>
<br/>
<fieldset>
<legend><%= path %></legend>
<br/>
<p class="info"> type : null (알수없음), 1 (부가가치세 일반과세자), 2 (부가가치세 면세과세자), 3 (부가치세 간이과세자) 4 (비영리법인 또는 국가기관, 고유번호가 할당된 단체)</p>
<p class="info"> state : null (알수없음), 0 (등록되지 않은 사업자번호), 1 (사업중), 2 (폐업), 3 (휴업)</p>
<%
result.forEach(function(result, index){
%>
<fieldset class="fieldset2">
<legend>사업자등록상태조회 - 대량</legend>
<ul>
<li>corpNum (사업자번호) : <%= result.corpNum %></li>
<li>type (사업자 과세유형) : <%= result.type %></li>
<li>typeDate (과세유형 전환일자) : <%= result.typeDate %></li>
<li>state (휴폐업상태) : <%= result.state %></li>
<li>stateDate (휴폐업일자) : <%= result.stateDate %></li>
<li>checkDate (확인일자) : <%= result.checkDate %></li>
</ul>
</fieldset>
<%
});
%>
</c:forEach>
</c:if>
</fieldset>
<br/>
</div>
</body>
</html>
4. API 응답결과 확인
API 호출 응답결과는 다음과 같습니다.
| 구분 | 응답 |
| 성공 | state(휴폐업상태) : 0 ~ 3 (1자리 문자열) |
| 실패 |
code : 오류코드 (8자리 음의 정수) [오류코드] message : 오류메시지 |












