튜토리얼
.NET Core 개발환경에서 팝빌 SDK를 추가하여 현금영수증 즉시 발행 (RegistIssue) 함수를 구현하는 예시입니다.
1. POPBiLL SDK 추가
[프로젝트 > NuGet 패키지 관리] 메뉴에서 popbill을 검색하여 최신 버전의 패키지를 설치합니다.

2. POPBiLL SDK 설정
① 프로젝트의 Startup.cs 파일에 현금영수증 서비스 인스턴스 클래스를 생성하고, Startup클래스의 ConfigureServices() 함수에 의존성 주입 패턴으로 Singleton 서비스 인스턴스를 추가합니다.
② 현금영수증 서비스명으로 컨트롤러를 생성하고 생성한 컨트롤러의 생성자 함수에서 현금영수증 인스턴스 객체를 할당합니다.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Popbill.Cashbill;
public class CashbillInstance
{
// 연동신청 후 메일로 발급받은 링크아이디(LinkID)와 비밀키(SecretKey)값 으로 변경하시기 바랍니다.
private string linkID = "TESTER";
private string secretKey = "SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=";
public CashbillService cashbillService;
public CashbillInstance()
{
//현금영수증 서비스 객체 초기화
cashbillService = new CashbillService(linkID, secretKey);
//연동환경 설정값, 개발용(true), 상업용(false)
cashbillService.IsTest = true;
// 인증토큰 아이피 제한 기능 사용여부 권장(true)
cashbillService.IPRestrictOnOff = true;
// 팝빌 API 서비스 고정 IP 사용여부, true-사용, false-미사용, 기본값(false)
cashbillService.UseStaticIP = false;
// 로컬시스템 시간 사용여부, true(사용) - 기본값, false(미사용)
cashbillService.UseLocalTimeYN = true;
}
}
namespace CashbillExample
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
//현금영수증 서비스 객체 의존성 주입
services.AddSingleton<CashbillInstance>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Cashbill}/{action=Index}");
});
}
}
}
3. RegistIssue 기능 구현
현금영수증 서비스명으로 생성한 컨트롤러의 생성자 함수에 인스턴스 객체를 할당하고, 현금영수증 즉시 발행 함수(RegistIssue) 호출 코드를 추가합니다.
// Controllers/CashbillController.cs
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Popbill;
using Popbill.Cashbill;
namespace CashbillExample.Controllers
{
public class CashbillController : Controller
{
private readonly CashbillService _cashbillService;
public CashbillController(CashbillInstance CBinstance)
{
// 현금영수증 서비스 객체 주입
_cashbillService = CBinstance.cashbillService;
}
public IActionResult RegistIssue()
{
//팝빌 연동회원 사업자번호 (하이픈 '-' 제외 10자리)
string corpNum = "1234567890";
//팝빌 연동회원 아이디
string userID = "testkorea";
// 현금영수증 정보 객체
Cashbill cashbill = new Cashbill();
// [필수] 문서번호, 사업자별로 중복되지 않도록 문서번호 할당
// 1~24자리 영문,숫자,'-','_' 조합 구성
cashbill.mgtKey = "20220101-021";
// [취소거래시 필수] 원본 현금영수증 국세청승인번호
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.franchiseTaxRegID = "";
// 가맹점 상호
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;
// 현금영수증 발행 메모
string memo = "현금영수증 즉시 발행 메모";
try
{
var response = _cashbillService.RegistIssue(corpNum, cashbill, memo, userID);
return View("Response", response);
}
catch (PopbillException pe)
{
return View("Exception", pe);
}
}
}
}
4. 결과 확인
함수 호출이 정상적으로 처리된 경우 Response가 "성공"으로 반환되며, 실패일 경우 PopbillException으로 오류코드("-"로 시작하는 8자리 숫자값)와 오류메시지가 반환됩니다. [오류코드] 바로가기