POPBill Developers
SDK Reference
Java

Tutorial

Following is an example to implement e-Tax invoice issuance (RegistIssue) API by adding the POPBiLL SDK within Java setting.

1. Add POPBiLL SDK

To add POPBiLL Java SDK, input POPBiLL Java SDK dependency information on “pom.xml” file of Spring project and update the Maven.

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

2. POPBiLL SDK Setting

Add e-Tax Invoice class into Spring Bean. By referring to the code below, edit “servlet-context.xml” file.

<?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">
        <!-- LinkID -->
        <beans:prop key="LinkID">TESTER</beans:prop>
        <!-- SecretKey -->
        <beans:prop key="SecretKey">SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=</beans:prop>
        <!-- Stage setting value , true(TEST), false(PRODUCTION) -->
        <beans:prop key="IsTest">true</beans:prop>
        <!-- Whether to recommend use of authentication token IP restriction function or not, -->
        <!-- recommended to use (true) -->
        <beans:prop key="IsIPRestrictOnOff">true</beans:prop>
        <!-- Whether to use POPBiLL API service static IP or not, -->
        <!-- true – use, false- do not use, default(false) -->
        <beans:prop key="UseStaticIP">false</beans:prop>
        <!-- Whether to use local system time or not, -->
        <!-- true – use(default – recommended), false – do not use -->
        <beans:prop key="UseLocalTimeYN">true</beans:prop>
    </util:properties>

    <beans:beans>
        <!-- e-Tax Invoice Service Implementation Bean registration.  -->
        <beans:bean id="taxinvoiceService"
            class="com.popbill.api.taxinvoice.TaxinvoiceServiceImp">
            <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. Implement RegistIssue Function

① To add Service Class Bean object, add @Autowired annotation and registIssue API code.

import java.util.ArrayList;

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.IssueResponse;
import com.popbill.api.PopbillException;
import com.popbill.api.TaxinvoiceService;
import com.popbill.api.taxinvoice.Taxinvoice;
import com.popbill.api.taxinvoice.TaxinvoiceAddContact;
import com.popbill.api.taxinvoice.TaxinvoiceDetail;

@Controller
public class TaxinvoiceServiceExample {

    @Autowired
    private TaxinvoiceService taxinvoiceService;

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

        // Tax invoice information object
        Taxinvoice taxinvoice = new Taxinvoice();

        // Date of preparation, format of data(yyyyMMdd)
        taxinvoice.setWriteDate("20220101");

        // Charge direction, select 정과금(Regular-Charge)
        taxinvoice.setChargeDirection("정과금");

        // Issuance type, select 정발행 (General Issuance)
        taxinvoice.setIssueType("정발행");

        // Payments received or not, select either [영수(paid), 청구(charge),없음(none)]
        taxinvoice.setPurposeType("영수");

        // Tax type, [과세(Tax),영세(Zero-taxed),면세(Tax Exemption)]
        taxinvoice.setTaxType("과세");


        /*********************************************************************
         *                     Seller Information
         *********************************************************************/

        // [Seller] business registration number
        taxinvoice.setInvoicerCorpNum("1234567890");

        // [Seller] business registration number
        // for minor business place, optional, 4-digit numbers
        taxinvoice.setInvoicerTaxRegID("");

        // [Seller] company name
        taxinvoice.setInvoicerCorpName("Seller Company Name");

        // [Seller] document ID
        // combination of 1~24 alphanumeric characters(number, alphabet, ‘-’, ‘_’),
        // to avoid duplicates, assign unique values for each business place
        taxinvoice.setInvoicerMgtKey("20220101-001");

        // [Seller] CEO name
        taxinvoice.setInvoicerCEOName("Seller Company's CEO Name");

        // [Seller] company address
        taxinvoice.setInvoicerAddr("Seller Address");

        // [Seller] items of business
        taxinvoice.setInvoicerBizClass("Seller Business Class");

        // [Seller] type of business
        taxinvoice.setInvoicerBizType("Seller Business Type");

        // [Seller] name of the person in charge
        taxinvoice.setInvoicerContactName("Seller Contactor Name");

        // [Seller] email of the person in charge
        taxinvoice.setInvoicerEmail("test@test.com");

        // [Seller] contact number of the person in charge
        taxinvoice.setInvoicerTEL("070-7070-0707");

        // [Seller] cell phone number of the person in charge
        taxinvoice.setInvoicerHP("010-000-2222");

        // Whether to send a notification text message
        // when issuing a tax invoice
        // - If sent, SMS service points will be deducted
        //   and if sending fails, point will be returned.
        taxinvoice.setInvoicerSMSSendYN(false);

        /*********************************************************************
         *                      Buyer Information
         *********************************************************************/

        // [Buyer] type of buyer,
        // select either [사업자(Business Proprietor), 개인(Individual), 외국인(Foreigner)]
        taxinvoice.setInvoiceeType("사업자");

        // [Buyer] business registration number, 10-digits except ‘_’
        taxinvoice.setInvoiceeCorpNum("8888888888");

        // [Buyer] branch number, 4-digits
        taxinvoice.setInvoiceeTaxRegID("");

        // [Buyer] company name
        taxinvoice.setInvoiceeCorpName("Buyer Company Name");

        // [Buyer] CEO name
        taxinvoice.setInvoiceeCEOName("Buyer Company's CEO Name");

        // [Buyer] company address
        taxinvoice.setInvoiceeAddr("Buyer Address");

        // [Buyer] items of business
        taxinvoice.setInvoiceeBizClass("Buyer Business Class");

        // [Buyer] type of business
        taxinvoice.setInvoiceeBizType("Buyer Business Type");

        // [Buyer] name of the person in charge
        taxinvoice.setInvoiceeContactName1("Buyer Contactor Name");

        // [Buyer] email of the person in charge
        // Do not include the email address of an actual customer.
        // POPBiLL sends an instructional email in the TEST stage as well.
        taxinvoice.setInvoiceeEmail1("test@invoicee.com");

        // [Buyer] contact information of the person in charge
        taxinvoice.setInvoiceeTEL1("070-111-222");

        // [Buyer] cell phone number of the person in charge
        taxinvoice.setInvoiceeHP1("010-111-222");

        // Whether to send a notification text message when issuing a requested invoice
        // - If sent, SMS service points will be deducted
        //   and if sending fails, point will be returned.
        taxinvoice.setInvoiceeSMSSendYN(false);


        /*********************************************************************
         *                   Tax Invoice Information
         *********************************************************************/

        // [Mandatory] total amount of supply value
        taxinvoice.setSupplyCostTotal("100000");

        // [Mandatory] total amount of tax
        taxinvoice.setTaxTotal("10000");

        // [Mandatory] total amount, supply value + tax amount
        taxinvoice.setTotalAmount("110000");

        // Serial number
        taxinvoice.setSerialNum("123");

        // Cash
        taxinvoice.setCash("");

        // Bill
        taxinvoice.setChkBill("");

        // Note
        taxinvoice.setNote("");

        // Accounts receivable
        taxinvoice.setCredit("");

        // Remark
        taxinvoice.setRemark1("Remark1");
        taxinvoice.setRemark2("Remark2");
        taxinvoice.setRemark3("Remark3");

        // 권 ‘kwon’(unit to count number of books of tax invoices),
        // maximum value : 32767
        taxinvoice.setKwon((short) 1);

        // 호 ‘ho’(unit to count the number of volumes for each book of tax invoices),
        // maximum value : 32767
        taxinvoice.setHo((short) 1);

        /*********************************************************************
         * Information of revised invoice
         * (write this for a revised invoice)
         * - Refer to the integration manual
         *   or development guide link
         *   for any information related to revised invoice
         *********************************************************************/

        // [mandatory when writing a revised invoice]
        // code for reasons for revocation,
        // select between 1-6 depending on the reason for revocation
        taxinvoice.setModifyCode(null);

        // [mandatory when writing a revised invoice]
        // write the NTS confirmation number of the original tax invoice
        taxinvoice.setOrgNTSConfirmNum("");

        /*********************************************************************
         *              Information of detailed list of items
         *********************************************************************/

        taxinvoice.setDetailList(new ArrayList<TaxinvoiceDetail>());

        // Object of detailed information
        TaxinvoiceDetail detail = new TaxinvoiceDetail();

        detail.setSerialNum((short) 1); // Serial number, write sequentially starting from 1
        detail.setPurchaseDT("20220101"); // Date of trade
        detail.setItemName(""Item name"); // Item name
        detail.setSpec("Specification");  // Specification
        detail.setQty("1"); // Quantity
        detail.setUnitCost("50000"); // Unit price
        detail.setSupplyCost("50000"); // Supply value
        detail.setTax("5000"); // Tax
        detail.setRemark("Item remark");  // Remark for item

        taxinvoice.getDetailList().add(detail);

        detail = new TaxinvoiceDetail();

        detail.setSerialNum((short) 2); // Serial number, write sequentially starting from 1
        detail.setPurchaseDT("20220130"); // Date of trade
        detail.setItemName(""Item name2"); // Item  name
        detail.setSpec("Specification");  // Specification
        detail.setQty("1"); // Quantity
        detail.setUnitCost("50000"); // Unit price
        detail.setSupplyCost("50000"); // Supply value
        detail.setTax("5000"); // Tax
        detail.setRemark("Item remark2"); // Remark

        taxinvoice.getDetailList().add(detail);

        /*********************************************************************
         *           Additional Person In Charge Information
         *********************************************************************/

        taxinvoice.setAddContactList(new ArrayList<TaxinvoiceAddContact>());

        TaxinvoiceAddContact addContact = new TaxinvoiceAddContact();

        addContact.setSerialNum(1);
        addContact.setContactName("Additional Contactor Name");
        addContact.setEmail("test2@test.com");

        taxinvoice.getAddContactList().add(addContact);


        // Whether to concurrently generate the transaction details or not
        Boolean WriteSpecification = false;

        // Document ID of the transaction details
        String DealInvoiceKey = null;

        // Memo for issuance
        String Memo = "Memo";

        // Option on whether to allow the delayed issuance or not
        // You may be subjected to penalty tax
        // if you issue a tax invoice past the deadline for issuance.
        // If you must issue regardless of the penalty tax,
        // set the forceIssue value as true and call the issuance API (Issue API).
        Boolean ForceIssue = false;

        try {
            IssueResponse response = taxinvoiceService.registIssue("1234567890",
                taxinvoice, WriteSpecification, Memo, ForceIssue, DealInvoiceKey);
            m.addAttribute("Response", response);
        } catch (PopbillException e) {
            // If an exception occurs,
            // check an error code with e.gtCode()
            // and error message with e.getMessage()
            System.out.println("Error Code : " + e.getCode());
            System.out.println("Error Message : " + e.getMessage());
        }

        return "response";
    }
}

② Add response.jsp file that outputs the code and message of the API calling result.

<%@ 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) : ${Response.code}</p>
    <p>Response message(Response.message) : ${Response.message}</p>
    <p>NTS confirmation number(Response.ntsConfirmNum) : ${Response.ntsConfirmNum}</p>
  </body>
</html>

4. Check the Result

If the API calling is being processed successfully, Response code will be returned as “1” and if it fails, an error code(8-digits that starts with “-”) and error message will be returned to POPBiLL Exception. [Error Code]