POPBill Developers
가이드

튜토리얼

Java 개발환경에서 팝빌 SDK를 추가하여 전자명세서 즉시 발행 (RegistIssue) 함수를 구현하는 예시입니다.

1. POPBiLL SDK 추가

팝빌 Java SDK를 추가하기 위해 Spring 프로젝트 "pom.xml" 파일에 팝빌 Java SDK dependency 정보를 추가하고 Maven 업데이트합니다.

<dependency>
    <groupId>kr.co.linkhub</groupId>
    <artifactId>popbill-sdk</artifactId>
    <version>1.63.1</version>
</dependency>

2. POPBiLL SDK 설정

전자명세서 클래스를 Spring 빈으로 추가합니다. 아래의 코드를 참조하여 "servlet-context.xml" 파일을 수정합니다.

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <annotation-driven/>

    <resources mapping="/resources/**" location="/resources/"/>

    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/"/>
        <beans:property name="suffix" value=".jsp"/>
    </beans:bean>

    <context:component-scan base-package="com.popbill.example"/>

    <util:properties id="EXAMPLE_CONFIG">
        <!-- 링크아이디 -->
        <beans:prop key="LinkID">TESTER</beans:prop>
        <!-- 비밀키 -->
        <beans:prop key="SecretKey">SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=</beans:prop>
        <!-- 연동환경 설정값 true(개발용), false(상업용) -->
        <beans:prop key="IsTest">true</beans:prop>
        <!-- 인증토큰 아이피 제한 기능 사용여부 권장(true) -->
        <beans:prop key="IsIPRestrictOnOff">true</beans:prop>
        <!-- 팝빌 API 서비스 고정 IP 사용여부, true-사용, false-미사용, 기본값(false) -->
        <beans:prop key="UseStaticIP">false</beans:prop>
        <!-- 로컬시스템 시간 사용여부 true-사용(기본값-권장), false-미사용 -->
        <beans:prop key="UseLocalTimeYN">true</beans:prop>
    </util:properties>

    <beans:beans>
        <!-- 전자명세서 Service Implementation Bean registration.  -->
        <beans:bean id="statementService"
            class="com.popbill.api.statement.StatementServiceImp">
            <beans:property name="linkID" value="#{EXAMPLE_CONFIG.LinkID}"/>
            <beans:property name="secretKey" value="#{EXAMPLE_CONFIG.SecretKey}"/>
            <beans:property name="test" value="#{EXAMPLE_CONFIG.IsTest}"/>
            <beans:property name="IPRestrictOnOff" value="#{EXAMPLE_CONFIG.IsIPRestrictOnOff}"/>
            <beans:property name="useStaticIP" value="#{EXAMPLE_CONFIG.UseStaticIP}"/>
            <beans:property name="useLocalTimeYN" value="#{EXAMPLE_CONFIG.UseLocalTimeYN}"/>
        </beans:bean>
    </beans:beans>
</beans:beans>

3. RegistIssue 기능 구현

① 서비스 클래스 빈 객체 추가를 위해 @Autowired 어노테이션과 registIssue 함수 코드를 추가합니다.

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.popbill.api.PopbillException;
import com.popbill.api.Response;
import com.popbill.api.StatementService;
import com.popbill.api.statement.Statement;
import com.popbill.api.statement.StatementDetail;

@Controller
@RequestMapping(value = "StatementService")
public class StatementServiceExample {

    @Autowired
    private StatementService statementService;

    @RequestMapping(value = "registIssue", method = RequestMethod.GET)
    public String registIssue(Model m) {

        // 발행자 사업자번호
        String corpNum = "1234567890";

        // 팝빌회원 아이디
        String testUserID = "testkorea";

        // 발행안내 메일 제목, 미기재시 기본 양식으로 전송
        String emailSubject = "메일제목 테스트";

        // 메모
        String Memo = "전자명세서 즉시 발행 메모";

        //  전자명세서 정보 객체
        Statement statement = new Statement();

        // [필수] 작성일자, 형태 yyyyMMdd
        statement.setWriteDate("20220101");

        // [필수] {영수, 청구, 없음} 중 기재
        statement.setPurposeType("영수");

        // [필수] {과세, 영세, 면세} 중 기재
        statement.setTaxType("과세");

        // 맞춤양식코드, 미기재시 기본양식으로 처리
        statement.setFormCode("");

        // [필수] 명세서 코드, [121 - 거래명세서], [122 - 청구서], [123 - 견적서], [124 - 발주서], [125 - 입금표], [126 - 영수증]
        statement.setItemCode((short) 121);

        // [필수] 문서번호, 최대 24자리 영문, 숫자, '-', '_'로 구성
        statement.setMgtKey("20220101-001");


        /*********************************************************************
         *                          발신자 정보
         *********************************************************************/

        // [필수] 발신자 사업자번호
        statement.setSenderCorpNum(corpNum);

        // [필수] 발신자 상호
        statement.setSenderCorpName("발신자 상호");

        // 발신자 주소
        statement.setSenderAddr("발신자 주소");

        // [필수] 발신자 대표자 성명
        statement.setSenderCEOName("발신자 대표자 성명");

        // 발신자 종사업장 식별번호, 숫자 4자리, 필요시 기재
        statement.setSenderTaxRegID("");

        // 발신자 종목
        statement.setSenderBizClass("업종");

        // 발신자 업태
        statement.setSenderBizType("업태");

        // 발신자 담당자명
        statement.setSenderContactName("발신자 담당자명");

        // 발신자 담당자 메일주소
        statement.setSenderEmail("test@test.com");

        // 발신자 담당자 연락처
        statement.setSenderTEL("070-7070-0707");

        // 발신자 담당자 휴대폰번호
        statement.setSenderHP("010-000-2222");


        /*********************************************************************
         *                          수신자 정보
         *********************************************************************/

        // [필수] 수신자 사업자번호
        statement.setReceiverCorpNum("8888888888");

        // [필수] 수신자 상호
        statement.setReceiverCorpName("수신자 상호");

        // [필수] 수신자 대표자명
        statement.setReceiverCEOName("수신자 대표자 성명");

        // 수신자 주소
        statement.setReceiverAddr("수신자 주소");

        // 수신자 종목
        statement.setReceiverBizClass("수신자 종목");

        // 수신자 업태
        statement.setReceiverBizType("수신자 업태");

        // 수신자 담당자명
        statement.setReceiverContactName("수신자 담당자명");

        // 수신자 메일주소
        // 팝빌 개발환경에서 테스트하는 경우에도 안내 메일이 전송되므로,
        // 실제 거래처의 메일주소가 기재되지 않도록 주의
        statement.setReceiverEmail("test@receiver.com");


        /*********************************************************************
         *                      전자명세서 기재정보
         *********************************************************************/

        // 공급가액 합계
        statement.setSupplyCostTotal("400000");

        // 세액 합계
        statement.setTaxTotal("40000");

        // 합계금액.  공급가액 + 세액
        statement.setTotalAmount("440000");

        // 기재상 일련번호 항목
        statement.setSerialNum("123");

        // 기재상 비고 항목
        statement.setRemark1("비고1");
        statement.setRemark2("비고2");
        statement.setRemark3("비고3");

        // 사업자등록증 이미지 첨부여부
        statement.setBusinessLicenseYN(false);

        // 통장사본 이미지 첨부여부
        statement.setBankBookYN(false);


        /*********************************************************************
         *                      전자명세서 품목항목
         *********************************************************************/

        statement.setDetailList(new ArrayList<StatementDetail>());

        StatementDetail detail = new StatementDetail();        // 상세항목(품목) 배열

        detail.setSerialNum((short) 1);                    // 일련번호, 1부터 순차기재
        detail.setItemName("품명");                        // 품목명
        detail.setPurchaseDT("20220101");                // 거래일자
        detail.setQty("1");                                // 수량
        detail.setSupplyCost("200000");                    // 공급가액
        detail.setTax("20000");                            // 세액

        statement.getDetailList().add(detail);

        detail = new StatementDetail();                    // 상세항목(품목) 배열
        detail.setSerialNum((short) 2);                    // 일련번호 1부터 순차기재
        detail.setItemName("품명");                        // 품목명
        detail.setPurchaseDT("20220101");                // 거래일자
        detail.setQty("1");                                // 수량
        detail.setSupplyCost("200000");                    // 공급가액
        detail.setTax("20000");                            // 세액

        statement.getDetailList().add(detail);


        /*********************************************************************
         *                     전자명세서 추가속성
         *********************************************************************/

        Map<String, String> propertyBag = new HashMap<String, String>();

        propertyBag.put("Balance", "15000");            // 전잔액
        propertyBag.put("Deposit", "5000");                // 입금액
        propertyBag.put("CBalance", "20000");            // 현잔액

        statement.setPropertyBag(propertyBag);

        try {
            Response response = statementService.registIssue(corpNum, statement, Memo, testUserID, emailSubject);

            m.addAttribute("Response", response);

        } catch (PopbillException e) {
            // 예외 발생 시, e.getCode() 로 오류 코드를 확인하고, e.getMessage()로 오류 메시지를 확인합니다.
            System.out.println("오류 코드" + e.getCode());
            System.out.println("오류 메시지" + e.getMessage());
        }

        return "response";
    }
}

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

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Popbill SDK Response</title>
  </head>

  <body>
    <p>응답코드 (Response.code) : ${Response.code}</p>
    <p>응답메시지 (Response.message) : ${Response.message}</p>
    <li>팝빌 승인번호 (Response.invoiceNum) : ${Response.invoiceNum}</p>
  </body>
</html>

4. 결과 확인

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