POPBill Developers
가이드

튜토리얼

Python 개발환경에서 팝빌 SDK를 추가하여 휴폐업 대량조회 (CheckCorpNums) 함수를 구현하는 예시입니다.

1. POPBiLL SDK 추가

팝빌 Python SDK를 추가하기 위해 pip install 명령어를 사용하여 패키지를 설치합니다.

$ pip install popbill

2. POPBiLL SDK 설정

Django 프로젝트의 settings.py 파일에 연동신청시 발급받은 인증정보와 연동환경 설정값을 선언합니다.

# -*- coding: utf-8 -*-
import os
import sys
import imp
imp.reload(sys)

try:
    sys.setdefaultencoding('UTF8')
except Exception as E:
    pass

#생략
#...
#...

# 링크아이디
LinkID = "TESTER"

# 발급받은 비밀키, 유출에 주의하시기 바랍니다.
SecretKey = "SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I="

# 연동환경 설정값, 개발용(True), 상업용(False)
IsTest = True

# 인증토큰 IP제한기능 사용여부, 권장(True)
IPRestrictOnOff = True

# 팝빌 API 서비스 고정 IP 사용여부, true-사용, false-미사용, 기본값(false)
UseStaticIP = False

#로컬시스템 시간 사용여부, 권장(True)
UseLocalTimeYN = True

3. CheckCorpNums 기능 구현

Django App에 생성된 views.py 파일에 휴폐업조회 서비스 클래스 객체 생성과 휴폐업 대량조회 (CheckCorpNums) 함수 호출 코드를 추가합니다.

# -*- coding: utf-8 -*-
from django.shortcuts import render
from popbill import ClosedownService, PopbillException, JoinForm, ContactInfo, CorpInfo

from config import settings

# settings.py 작성한 LinkID, SecretKey를 이용해 ClosedownService 객체 생성
closedownService = ClosedownService(settings.LinkID, settings.SecretKey)

# 연동환경 설정값, 개발용(True), 상업용(False)
closedownService.IsTest = settings.IsTest

# 인증토큰 IP제한기능 사용여부, 권장(True)
closedownService.IPRestrictOnOff = settings.IPRestrictOnOff

# 팝빌 API 서비스 고정 IP 사용여부, true-사용, false-미사용, 기본값(false)
closedownService.UseStaticIP = settings.UseStaticIP

#로컬시스템 시간 사용여부, 권장(True)
closedownService.UseLocalTimeYN = settings.UseLocalTimeYN

def checkCorpNums(request):
    try:
        # 팝빌회원 사업자번호
        CorpNum = "1234567890"

        # 확인하고자 하는 사업자번호 (최대 1000건)
        targetCorpNumList = ["1234567890", "6798700433", "1231212312"]

        bizCheckInfo = closedownService.checkCorpNums(CorpNum, targetCorpNumList)

        return render(request, 'response.html', {'bizCheckInfo': bizCheckInfo})
    except PopbillException as PE:
        return render(request, 'exception.html', {'code': PE.code, 'message': PE.message})
	

함수 호출결과 코드와 메시지를 출력하는 "/response.html" 파일을 추가합니다.

<html xmlns=" http://www.w3.org/1999/xhtml ">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Popbill API Test.</title>
</head>
<div id="content">
    <fieldset class="fieldset1">
        <br>
        <p class="info"> type (사업자 과세유형) : [None-알수없음 / 1-일반과세자 / 2-면세과세자 / 3-간이과세자 / 4-비영리법인, 국가기관]</p>
        <p class="info"> state (휴폐업상태) : [None-알수없음 / 0-등록되지 않은 사업자번호 / 1-사업중 /2-폐업 / 3-휴업]</p>
        <legend>휴폐업조회 - 대량</legend>
        <ul>
              {% for corpState in bizCheckInfo %}
                <fieldset class="fieldset2">
                    <legend>휴폐업조회 결과 [{{ forloop.counter }}]</legend>
                    <ul>
                        <li> corpNum (사업자번호) : {{ corpState.corpNum }}</li>
                        <li> type (사업자 과세유형) : {{ corpState.type }}</li>
                        <li> typeDate (과세유형 전환일자) : {{ corpState.typeDate }}</li>
                        <li> state (휴폐업상태) : {{ corpState.state }}</li>
                        <li> stateDate (휴폐업일자) : {{ corpState.stateDate }}</li>
                        <li> checkDate (확인일자) : {{ corpState.checkDate }}</li>
                    </ul>
                </fieldset>
            {% endfor %}
        </ul>
    </fieldset>
</div>
</html> 

4. 결과 확인

함수 호출 반환 결과는 아래와 같습니다.
- 성공 : Response code 로 숫자 1 반환
- 실패 : PopbillException 으로 음의 정수 8자리 숫자값 오류코드와 오류메시지 반환 [오류코드]