POPBill Developers
가이드

튜토리얼

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

1. POPBiLL SDK 추가

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

2. POPBiLL SDK 설정

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

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

using Popbill.AccountCheck;

public class AccountCheckInstance
{
    // 연동신청 후 메일로 발급받은 링크아이디(LinkID)와 비밀키(SecretKey)값 으로 변경하시기 바랍니다.
    private string linkID = "TESTER";
    private string secretKey = "SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=";

    public AccountCheckService accountCheckService;

    public AccountCheckInstance()
    {
        // 예금주조회 서비스 객체 초기화
        accountCheckService = new AccountCheckService(linkID, secretKey);

        // 연동환경 설정값, 개발용(true), 상업용(false)
        accountCheckService.IsTest = true;

        // 인증토큰 아이피 제한 기능 사용여부 권장(true)
        accountCheckService.IPRestrictOnOff = true;

        // 팝빌 API 서비스 고정 IP 사용여부, true-사용, false-미사용, 기본값(false)
        accountCheckService.UseStaticIP = false;

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

namespace AccountCheck_Example
{
    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.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // 예금주조회 서비스 객체 의존성 주입
            services.AddSingleton<AccountCheckInstance>();
        }

        // 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.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

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가 "성공"으로 반환되며, 실패일 경우 PopbillException으로 오류코드("-"로 시작하는 8자리 숫자값)와 오류메시지가 반환됩니다. [오류코드] 바로가기