POPBill Developers
가이드

튜토리얼

.NET Core 개발환경에서 팝빌 SDK를 추가하여 예금주성명 조회 (CheckAccountInfo) 함수를 구현하는 예시입니다.

1. POPBiLL SDK 추가

[프로젝트 > NuGet 패키지 관리] 메뉴에서 popbill을 검색하여 최신 버전의 패키지를 설치합니다.

2. POPBiLL SDK 설정

① 프로젝트의 Startup.cs 파일에 koreanName 서비스 인스턴스 클래스를 생성하고, Startup클래스의 ConfigureServices() 함수에 의존성 주입 패턴으로 Singleton 서비스 인스턴스를 추가합니다.

② koreanName 서비스명으로 컨트롤러를 생성하고 생성한 컨트롤러의 생성자 함수에서 koreanName 인스턴스 객체를 할당합니다.

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Popbill.moduleName;

public class serviceNameInstance
{
  // 링크아이디
  private string linkID = "TESTER";
  // 비밀키
  private string secretKey = "SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=";

  // koreanName  서비스 객체 선언
  public serviceNameService classNameService;

  public serviceNameInstance()
  {
    // koreanName  서비스 객체 초기화
    accountCheckService = new AccountCheck(linkID, seretKey);

    // 연동환경 설정, true-테스트, false-운영(Production), (기본값: false)
    accountCheckService.IsTest = true;

    // 인증토큰 IP 검증 설정, ture-사용, false-미사용, (기본값: true)
    accountCheckService.IPRestrictOnOff = true;

    // 통신 고정 IP, true-사용, false-미사용, (기본값: false)
    accountCheckService.UseStaticIP = false;

    // 로컬시스템 시간 사용여부, true-사용, false-미사용, (기본값: false)
    accountCheckService.UseLocalTimeYN = true
  }
}

namespace serviceNameExample
{
  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<serviceNameInstance>();
    }

    // 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=serviceName}/{action=Index}");
      });
    }
  }
}

3. CheckAccountInfo 기능 구현

예금주조회 서비스명으로 생성한 컨트롤러의 생성자 함수에 인스턴스 객체를 할당하고, 예금주성명 조회 함수(CheckAccountInfo) 호출 코드를 추가합니다.

// Controllers/AccountCheckController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

using Popbill;
using Popbill.AccountCheck;

namespace AccountCheck_Example.Controllers
{
    public class AccountCheckController : Controller
    {
        private readonly AccountCheckService _accountCheckService;

        public AccountCheckController(AccountCheckInstance EInstance)
        {
            _accountCheckService = EInstance.accountCheckService;
        }

        public IActionResult Index()
        {
            return View();
        }

        /*
         * 1건의 계좌에 대한 예금주정보 조회합니다.
         */
        public IActionResult CheckAccountInfo()
        {
            try
            {
                // 팝빌 회원 사업자번호
                string corpNum = "1234567890";

                // 기관코드
                string bankCode = "0011";

                // 계좌번호
                string accountNumber = "3011599770921";

                var response = _accountCheckService.CheckAccountInfo(corpNum, bankCode, accountNumber);

                return View("CheckAccountInfo", response);

            }
            catch (PopbillException pe)
            {
                return View("PopbillError", pe);
            }
        }
    }
}

4. 결과 확인

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