POPBill Developers
가이드

튜토리얼

Ruby 개발환경에서 팝빌 SDK를 추가하여 현금영수증 즉시 발행 (RegistIssue) 함수를 구현하는 예시입니다.

1. POPBiLL SDK 추가

팝빌 Ruby SDK를 추가하기 위해 Rails 프로젝트 "Gemfile" 파일에 팝빌 Ruby Gem SDK 정보를 추가하고 bundle install을 진행합니다.

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.3.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'

# 팝빌 API Service
gem 'popbill', '1.52.0'

# 생략
# ...

2. POPBiLL SDK 설정

프로젝트에 현금영수증 서비스 기능을 수행할 Controller를 생성합니다.

rails generate controller tutorial

Controller에 연동신청시 발급받은 API Key 를 변수로 선언하고 아래의 코드를 참조하여 현금영수증 서비스 객체를 생성 합니다.

require 'popbill/cashbill'

class CashbillController < ApplicationController

# 링크아이디
LinkID = "LinkID"

# 비밀키
SecretKey = "SwWxqU+0TExEXy/9TVjKPExI2VTUMMSLZtJf3Ed8q3I="

# 현금영수증 서비스 객체 초기화
CBService = CashbillService.instance(
  CashbillController::LinkID,
  CashbillController::SecretKey
)

# 연동환경 설정, true-테스트, false-운영(Production), (기본값:false)
CBService.setIsTest(true)

# 인증토큰 IP 검증 설정, true-사용, false-미사용, (기본값:true)
CBService.setIpRestrictOnOff(true)

# 통신 IP 고정, true-사용, false-미사용, (기본값:false)
CBService.setUseStaticIP(false)

# 로컬시스템 시간 사용여부, true-사용, false-미사용, (기본값:true)
CBService.setUseLocalTimeYN(true)

end

3. RegistIssue 기능 구현

Controller 코드에 현금영수증 즉시 발행 (RegistIssue) 함수 호출 코드를 추가합니다.

def registIssue

    # 팝빌회원 사업자번호
    corpNum = "1234567890"

    # 현금영수증 문서번호 (문서번호는 1~24자리로 숫자, 영문 '-', '_' 조합으로 구성할 수 있습니다.)
    mgtKey = "20220101-21"

    # 현금영수증 정보
    cashbill = {

        # [필수] 문서번호
        "mgtKey" => mgtKey,

        # [필수] 문서형태
        "tradeType" => "승인거래",

        # [필수] 거래구분, {소득공제용, 지출증빙용} 중 기재
        "tradeUsage" => "소득공제용",

        # [필수] 거래유형, {일반, 도서공연, 대중교통} 중 기재
        "tradeOpt" => "일반",

        # [필수] 식별번호
        # 거래구분(tradeUsage) - '소득공제용' 인 경우 주민등록/휴대폰/카드번호 기재 가능
        # 거래구분(tradeUsage) - '지출증빙용' 인 경우 사업자번호/주민등록/휴대폰/카드번호 기재 가능
        "identityNum" => "0100001234",

        # [필수] 과세형태, {과세, 비과세} 중 기재
        "taxationType" => "과세",

        # [필수] 공급가액
        "supplyCost" => "10000",

        # [필수] 부가세
        "tax" => "1000",

        # [필수] 봉사료
        "serviceFee" => "0",

        # [필수] 거래금액
        "totalAmount" => "11000",

        # [필수] 가맹점 사업자번호
        "franchiseCorpNum" => corpNum,

        # 가맹점 종사업장 식별번호
        "franchiseTaxRegID" => "",

        # 가맹점 상호
        "franchiseCorpName" => "가맹점 상호",

        # 가맹점 대표자 성명
        "franchiseCEOName" => "가맹점 대표자 성명",

        # 가맹점 주소
        "franchiseAddr" => "가맹점 주소",

        # 가맹점 연락처
        "franchiseTEL" => "가맹점 연락처",

        # 고객명
        "customerName" => "고객명",

        # 상품명
        "itemName" => "상품명",

        # 가맹점 주문번호
        "orderNumber" => "가맹점 주문번호",

        # 거래처 이메일
        # 팝빌 개발환경에서 테스트하는 경우에도 안내 메일이 전송되므로,
        # 실제 거래처의 메일주소가 기재되지 않도록 주의
        "email" => "test@Testcom",

        # 거래처 휴대폰
        "hp" => "010-111-222",

        # 발행안내문자 전송여부
        "smssendYN" => false,
    } # end of cashbill hash

    begin
      @Response = TutorialController::CBService.registIssue(
          corpNum,
          cashbill,
      )
      render "home/response"
    rescue PopbillException => pe
      @Response = pe
      render "home/exception"
    end
end

4. 결과 확인

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