[.NET] 팝빌 현금영수증 SDK 튜토리얼
.NET 개발환경에서 프로젝트에 팝빌 SDK를 추가한 후 현금영수증 즉시발행(RegistIssue) 함수를 구현하는 예시입니다.
- C#.NET
- VB.NET
- ASP.NET
1. Popbill SDK 추가 및 클래스 초기화
① 팝빌 연동자료실에서 C#.NET SDK 예제코드 다운로드 후 압축을 해제합니다.
② 다운받은 SDK 예제코드의 Linkhub/, Popbill/ 폴더를 SDK를 적용할 프로젝트 경로에 복사하고. Linkhub.csproj, Popbill.csproj를 각각 기존 프로젝트로 추가합니다.

③ Popbill 프로젝트를 적용할 프로젝트의 참조로 추가합니다.

④ 연동환경 설정값, 현금영수증 서비스 클래스를 선언하고 폼의 생성자 Form1()에 서비스 클래스 초기화 코드를 추가합니다.
연동신청시 발급받은 인증정보로 링크아이디(LinkID)와 비밀키(SecretKey) 값을 변경하시기 바랍니다.
namespace Popbill.Cashbill
{
public partial class Form1 : Form
{
// 연동신청시 발급받은 링크아이디로 수정.
private string LinkID = "TESTER";
// 연동신청시 발급받은 비밀키로 수정.
private string SecretKey = "SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=";
// 현금영수증 서비스 객체 선언
private CashbillService cashbillService;
public Form1()
{
InitializeComponent();
// 현금영수증 서비스 객체 초기화
cashbillService = new CashbillService(LinkID, SecretKey);
// 연동환경 설정값, true - 개발용(테스트베드), false - 상업용(실서비스)
cashbillService.IsTest = true;
// 발급된 토큰에 대한 IP 제한기능 사용여부, 권장(True)
cashbillService.IPRestrictOnOff = true;
// 로컬PC 시간 사용 여부 true(사용), false(기본값) - 미사용
cashbillService.UseLocalTimeYN = false;
}
}
}
2. 현금영수증 즉시발행(RegistIssue) 함수 구현
① Form에 버튼을 생성하고 버튼의 Click Event 코드에 현금영수증 즉시발행(RegistIssue) 함수 호출 코드를 추가합니다.
private void btnRegistIssue_Click(object sender, EventArgs e)
{
// 팝빌회원 사업자번호
String corpNum = "1234567890";
// 팝빌회원 아이디
String userID = "testkorea";
// 메모
String memo = "현금영수증 즉시발행 메모";
Cashbill cashbill = new Cashbill();
// [필수] 문서번호, 발행자별 고유번호 할당, 1~24자리 영문,숫자,'-','_' 조합으로 중복없이 구성.
cashbill.mgtKey = "20180828-041";
// [취소거래시 필수] 원본 현금영수증 국세청승인번호
cashbill.orgConfirmNum = "";
// [취소거래시 필수] 원본 현금영수증 거래일자
cashbill.orgTradeDate = "";
// [필수] 문서형태, { 승인거래, 취소거래 } 중 기재
cashbill.tradeType = "승인거래";
// [필수] 거래구분, { 소득공제용, 지출증빙용 } 중 기재
cashbill.tradeUsage = "소득공제용";
// 거래유형, { 일반, 도서공연, 대중교통 } 중 기재
cashbill.tradeOpt = "일반";
// [필수] 과세형태, { 과세, 비과세 } 중 기재
cashbill.taxationType = "과세";
// [필수] 거래금액 ( 공급가액 + 세액 + 봉사료 )
cashbill.totalAmount = "11000";
// [필수] 공급가액
cashbill.supplyCost = "10000";
// [필수] 부가세
cashbill.tax = "1000";
// [필수] 봉사료
cashbill.serviceFee = "0";
// [필수] 가맹점 사업자번호
cashbill.franchiseCorpNum = corpNum;
// 가맹점 상호
cashbill.franchiseCorpName = "가맹점 상호";
// 가맹점 대표자 성명
cashbill.franchiseCEOName = "가맹점 대표자 성명";
// 가맹점 주소
cashbill.franchiseAddr = "가맹점 주소";
// 가맹점 전화번호
cashbill.franchiseTEL = "070-1234-1234";
// [필수] 식별번호
// 거래구분(tradeUsage) - '소득공제용' 인 경우
// - 주민등록/휴대폰/카드번호 기재 가능
// 거래구분(tradeUsage) - '지출증빙용' 인 경우
// - 사업자번호/주민등록/휴대폰/카드번호 기재 가능
cashbill.identityNum = "0101112222";
// 주문자명
cashbill.customerName = "주문자명";
// 주문상품명
cashbill.itemName = "주문상품명";
// 주문번호
cashbill.orderNumber = "주문번호";
// 주문자 이메일
// 팝빌 개발환경에서 테스트하는 경우에도 안내 메일이 전송되므로,
// 실제 거래처의 메일주소가 기재되지 않도록 주의
cashbill.email = "test@test.com";
// 주문자 휴대폰
cashbill.hp = "010-111-222";
// 주문자 팩스번호
cashbill.fax = "02-6442-9700";
// 발행시 알림문자 전송여부
cashbill.smssendYN = false;
try
{
Response response = cashbillService.RegistIssue(corpNum, cashbill, memo, userID);
MessageBox.Show("응답코드(code) : " + response.code.ToString() + "\r\n" +
"응답메시지(message) : " + response.message, "현금영수증 즉시발행");
}
catch (PopbillException ex)
{
MessageBox.Show("응답코드(code) : " + ex.code.ToString() + "\r\n" +
"응답메시지(message) : " + ex.Message, "현금영수증 즉시발행");
}
}
② 버튼 클릭으로 함수호출 결과를 확인합니다.

1. Popbill SDK 추가 및 클래스 초기화
① 팝빌 연동자료실에서 VB.NET SDK 예제코드 다운로드 후 압축을 해제합니다.
② 다운받은 SDK 예제코드의 Linkhub/, Popbill/ 폴더를 SDK를 적용할 프로젝트 경로에 복사하고. Linkhub.csproj, Popbill.csproj를 각각 기존 프로젝트로 추가합니다.

③ Popbill 프로젝트를 적용할 프로젝트의 참조로 추가합니다.

④ 연동환경 설정값, 현금영수증 서비스 클래스를 선언하고 Form1_Load() 함수에 서비스 클래스 초기화 코드를 추가합니다.
연동신청시 발급받은 인증정보로 링크아이디(LinkID)와 비밀키(SecretKey) 값을 변경하시기 바랍니다.
Public Class Form1
'링크아이디
Private Const LinkID As String = "TESTER"
'비밀키
Private SecretKey As String = "SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I="
'현금영수증 서비스 변수 선언
Private cashbillService As CashbillService
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'현금영수증 서비스 객체 초기화
cashbillService = New CashbillService(LinkID, SecretKey)
'연동환경 설정값 (True-개발용, False-상업용)
cashbillService.IsTest = True
'인증토큰의 IP제한기능 사용여부, (True-권장)
cashbillService.IPRestrictOnOff = True
'로컬PC 시간 사용 여부 True(사용), False(기본값) - 미사용
cashbillService.UseLocalTimeYN = False
End Sub
End Class
2. 현금영수증 즉시발행(RegistIssue) 함수 구현
① Form에 버튼을 생성하고 버튼의 Click Event 코드에 현금영수증 즉시발행(RegistIssue) 함수 호출 코드를 추가합니다.
Private Sub btnRegistIssue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegistIssue.Click
Dim cashbill As Cashbill = New Cashbill
'팝빌회원 사업자번호
Dim corpNum As String = "1234567890"
'현금영수증 관리번호, 1~24자리 영문,숫자조합으로 사업자별로 중복되지 않도록 구성
cashbill.mgtKey = "20190829-01"
'[취소거래시 필수] 원본 현금영수증 국세청승인번호
'문서정보(GetInfo) 함수의 응답항목중 국세청승인번호(confirmNum)를 확인하여 기재
cashbill.orgConfirmNum = ""
'[취소거래시 필수] 원본 현금영수증 거래일자
'문서정보(GetInfo) 함수의 응답항목중 거래일자(tradeDate)를 확인하여 기재
cashbill.orgTradeDate = ""
'문서형태, [승인거래, 취소거래] 중 기재
cashbill.tradeType = "승인거래"
'거래구분, [소득공제용, 지출증빙용] 중 기재
cashbill.tradeUsage = "소득공제용"
'거래유형, [일반, 도서공연, 대중교통] 중 기재
cashbill.tradeOpt = "일반"
'과세형태, [과세, 비과세] 중 기재
cashbill.taxationType = "과세"
'거래금액, 공급가액 + 봉사료 + 세액
cashbill.totalAmount = "11000"
'공급가액
cashbill.supplyCost = "10000"
'부가세
cashbill.tax = "1000"
'봉사료
cashbill.serviceFee = "0"
'가맹점 사업자번호, "-" 제외 10자리
cashbill.franchiseCorpNum = corpNum
'가맹점 상호명
cashbill.franchiseCorpName = "발행자 상호"
'가맹점 대표자 성명
cashbill.franchiseCEOName = "발행자 대표자"
'가맹점 주소
cashbill.franchiseAddr = "발행자 주소d"
'가맹점 전화번호
cashbill.franchiseTEL = "070-1234-1234"
'식별번호, 거래유형에 따라 작성
'소득공제용 - 주민등록/휴대폰/카드번호 기재가능
'지출증빙용 - 사업자번호/주민등록/휴대폰/카드번호 기재가능
cashbill.identityNum = "0101112222"
'주문자명
cashbill.customerName = "주문자명"
'주문상품명
cashbill.itemName = "주문상품명"
'주문번호
cashbill.orderNumber = "주문번호"
'주문자 이메일
cashbill.email = "test@test.com"
'주문자 휴대폰번호
cashbill.hp = "010-111-222"
'현금영수증 발행 알림문자 전송여부, 미기재시 "false"
cashbill.smssendYN = False
'메모
Dim memo As String = "즉시발행 메모"
Try
Dim response As Response = cashbillService.RegistIssue(corpNum, cashbill, memo)
MsgBox("응답코드(code) : " + response.code.ToString() + vbCrLf + "응답메시지(message) : " + response.message)
Catch ex As PopbillException
MsgBox("응답코드(code) : " + ex.code.ToString() + vbCrLf + "응답메시지(message) : " + ex.Message)
End Try
End Sub
② 버튼 클릭으로 함수호출 결과를 확인합니다.

1. Popbill SDK 추가 및 클래스 초기화
① 팝빌 연동자료실에서 ASP.NET SDK 예제코드 다운로드 후 압축을 해제합니다.
② 다운받은 SDK 예제코드의 Linkhub/, Popbill/ 폴더를 SDK를 적용할 프로젝트 경로에 복사하고. Linkhub.csproj, Popbill.csproj를 각각 기존 프로젝트로 추가합니다.

③ Popbill 프로젝트를 적용할 프로젝트의 참조로 추가합니다.

④ 프로젝트에 Global.asax 파일을 생성하고 연동환경 설정값, 현금영수증 서비스 클래스를 선언하고 Application_Start() 함수에 현금영수증 서비스 클래스 초기화 코드를 추가합니다.

연동신청시 발급받은 인증정보로 링크아이디(LinkID)와 비밀키(SecretKey) 값을 변경하시기 바랍니다.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Xml.Linq;
using Popbill.Cashbill;
namespace Tutorial_Example
{
public class Global : System.Web.HttpApplication
{
// 연동신청시 발급받은 링크아이디로 수정.
private string LinkID = "LINKID";
// 연동신청시 발급받은 비밀키로 수정.
private string SecretKey = "SwWxqU+0TExEXy/9TVjKPExI2VTUMMSLZtJf3Ed8q3I=";
// 현금영수증 서비스 객체 선언
public static CashbillService cashbillService;
protected void Application_Start(object sender, EventArgs e)
{
// 현금영수증 서비스 객체 초기화
cashbillService = new CashbillService(LinkID, SecretKey);
// 연동환경 설정값 (true-개발용, false-상업용)
cashbillService.IsTest = true;
// 인증토큰 IP 제한기능 사용여부, 권장(true)
cashbillService.IPRestrictOnOff = true;
// 팝빌 API 서비스 고정 IP 사용여부(GA), true-사용, false-미사용, 기본값(false)
cashbillService.UseStaticIP = false;
// 로컬서버 시간 사용 여부 true-사용, false-미사용, 기본값(false)
cashbillService.UseLocalTimeYN = true;
}
}
}
2. 현금영수증 즉시발행(RegistIssue) 함수 구현
① Web Form을 추가하여 registIssue.aspx를 생성하여 응답코드, 메시지 확인 페이지를 추가하고, registIssue.aspx.cs 파일의 Page_Load 이벤트에 함수 호출 코드를 추가합니다.
registIssue.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="registIssue.aspx.cs" Inherits="Popbill.Cashbill.Example.registIssue" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Popbill Cashbill</title>
</head>
<body>
<div>
<p>Response</p>
<br/>
<fieldset>
<legend>현금영수증 즉시발행</legend>
<ul>
<li>Response.code : <%= code %></li>
<li>Response.message : <%= message %></li>
</ul>
</fieldset>
</div>
</body>
</html>
registIssue.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Popbill.Cashbill.Example
{
public partial class registIssue : System.Web.UI.Page
{
public String code;
public String message;
protected void Page_Load(object sender, EventArgs e)
{
// 팝빌회원 사업자번호, '-' 제외 10자리
String testCorpNum = "1234567890";
// 팝빌회원 아이디
String testUserID = "testkorea";
// 현금영수증 문서번호
String mgtKey = "20190829-011";
// 메모
String memo = "즉시발행 메모";
// 현금영수증 정보 객체
Cashbill cashbill = new Cashbill();
// [필수] 문서번호, 사업자별로 중복되지 않도록 관리번호 할당
// 1~24자리 영문,숫자,'-','_' 조합 구성
cashbill.mgtKey = mgtKey;
// [취소거래시 필수] 원본 현금영수증 국세청승인번호
cashbill.orgConfirmNum = "";
// [취소거래시 필수] 원본 현금영수증 거래일자
cashbill.orgTradeDate = "";
// [필수] 문서형태, {승인거래, 취소거래} 중 기재
cashbill.tradeType = "승인거래";
// [필수] 거래구분, {소득공제용, 지출증빙용} 중 기재
cashbill.tradeUsage = "소득공제용";
// [필수] 거래유형, {일반, 도서공연, 대중교통} 중 기재
cashbill.tradeOpt = "일반";
// [필수] 과세형태, { 과세, 비과세 } 중 기재
cashbill.taxationType = "과세";
// [필수] 거래금액 ( 공급가액 + 세액 + 봉사료 )
cashbill.totalAmount = "11000";
// [필수] 공급가액
cashbill.supplyCost = "10000";
// [필수] 부가세
cashbill.tax = "1000";
// [필수] 봉사료
cashbill.serviceFee = "0";
// [필수] 가맹점 사업자번호
cashbill.franchiseCorpNum = testCorpNum;
// 가맹점 상호
cashbill.franchiseCorpName = "발행자 상호";
// 가맹점 대표자 성명
cashbill.franchiseCEOName = "발행자 대표자";
// 가맹점 주소
cashbill.franchiseAddr = "발행자 주소";
// 가맹점 전화번호
cashbill.franchiseTEL = "070-1234-1234";
// [필수] 식별번호
// 거래구분(tradeUsage) - '소득공제용' 인 경우
// - 주민등록/휴대폰/카드번호 기재 가능
// 거래구분(tradeUsage) - '지출증빙용' 인 경우
// - 사업자번호/주민등록/휴대폰/카드번호 기재 가능
cashbill.identityNum = "0101112222";
// 주문자명
cashbill.customerName = "고객명";
// 주문상품명
cashbill.itemName = "상품명";
// 주문번호
cashbill.orderNumber = "주문번호";
// 주문자 메일
cashbill.email = "test@test.com";
// 주문자 휴대폰번호
cashbill.hp = "010-111-222";
// 주문자 팩스번호
cashbill.fax = "02-111-222";
// 발행시 알림문자 전송여부
cashbill.smssendYN = false;
try
{
Response response = Global.cashbillService.RegistIssue(testCorpNum, cashbill, memo, testUserID);
code = response.code.ToString();
message = response.message;
}
catch (PopbillException ex)
{
code = ex.code.ToString();
message = ex.Message;
}
}
}
}
② 추가한 페이지를 호출하여 함수 응답코드와 응답메시지를 확인합니다.
