POPBill Developers
가이드

튜토리얼

Delphi 개발환경에서 팝빌 SDK를 추가하여 휴폐업 대량조회 (CheckCorpNums) 함수를 구현하는 예시입니다.

1. POPBiLL SDK 추가

팝빌 연동자료실에서 Delphi SDK 예제코드 다운로드 후 압축을 해제합니다.

압축해제한 SDK 예제코드에서 Linkhub/ Popbill/ PopbillTaxinvoice/ 각 폴더의 pas파일 3개를 프로젝트 유닛으로 추가합니다.

2. POPBiLL SDK 설정

아래 코드를 참조하여 Form 파일을 수정합니다.

  1. ① use 참조유닛 추가
  2. ② 인증정보 변수와 서비스 클래스를 선언
  3. ③ FormCreate 프로시저에 휴폐업조회 서비스 클래스 인스턴스 생성 및 초기화
unit Example;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, TypInfo, shellapi, ExtCtrls,
  Popbill, PopbillClosedown;

const
  // 링크아이디, 연동신청시 발급받은 정보로 변경
  LinkID = 'TESTER';

  // 비밀키, 연동신청시 발급받은 정보로 변경
  SecretKey = 'SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=';
// 생략
// ...
// ...

var
  // 클래스 선언 추가
  closedownService : TClosedownService;
// 생략
// ...
// ...

procedure TfrmExample.FormCreate(Sender: TObject);
begin
  // 휴폐업조회 서비스 클래스 인스턴스 생성
  closedownService := TClosedownService.Create(LinkID,SecretKey);

  // true - 개발용(테스트베드), false - 상업용(실서비스)
  closedownService.IsTest := true;

  // API 오류 Exception 처리여부
  closedownService.IsThrowException := true;

  // 인증토큰 IP제한기능 사용여부, true(권장)
  closedownService.IPRestrictOnOff := true;

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

3. CheckCorpNums 기능 구현

Form에 버튼을 생성하고 버튼의 Click Event 코드에 휴폐업 대량조회 (CheckCorpNums) 함수를 추가합니다.

procedure TfrmExample.btnCheckCorpNumsClick(Sender: TObject);
var
    CorpNumList : Array Of String;
    StateList : TCorpStateList;
    tmp : string;
    i : Integer;
    pbCorpNum : String;
begin
    // 팝빌회원 사업자번호
    pbCorpNum := '1234567890';

    //조회할 사업자번호 목록, 최대 1000건
    SetLength(CorpNumList,3);
    CorpNumList[0] := '1234567890';
    CorpNumList[1] := '1234512345';
    CorpNumList[2] := '6798700433';

    try
            StateList := closedownService.checkCorpNums(CorpNumList, pbCorpNum);

    except
            on le : EPopbillException do begin
                    ShowMessage(IntToStr(le.code) + ' | ' +  le.Message);
                    Exit;
            end;
    end;

    if closedownService.LastErrCode <> 0 then
    begin
            ShowMessage(IntToStr(closedownService.LastErrCode) + ' | ' +  closedownService.LastErrMessage);
    end
    else
    begin
      tmp := '* type (사업자 과세유형) : null-알수없음, 1-일반과세자, 2-면세과세자, 3-간이과세자, 4-비영리법인, 국가기관' +#13;
      tmp := tmp + '* state (휴폐업상태) : null-알수없음, 0-등록되지 않은 사업자번호, 1-사업중, 2-폐업, 3-휴업' +#13#13;

      for i := 0 to Length(StateList) -1 do
      begin
              tmp := tmp +'corpNum(사업자번호) : '+ StateList[i].corpNum + #13;
              tmp := tmp +'type(사업자 과세유형) : '+ StateList[i].ctype + #13;
              tmp := tmp +'typeDate(과세유형 전환일자) : '+ StateList[i].typeDate + #13;
              tmp := tmp +'state(휴폐업상태) : '+ StateList[i].state + #13;
              tmp := tmp +'stateDate(휴폐업일자) : '+ StateList[i].stateDate + #13;
              tmp := tmp +'checkDate(국세청 확인일자) : '+ StateList[i].checkDate + #13#13;
      end;
      ShowMessage(tmp);
    end;
end;

4. 결과 확인

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