# 웹훅 이벤트

전자명세서 발행에서 발생하는 웹훅 이벤트입니다.

> 실제 고객사 서버로 전송된 웹훅 이벤트 정보는 [\[Webhook 실행내역 확인\]](https://developers.popbill.com/reference/statement/dotnetcore/webhook/introduction#check) 을 참고하여 주시기 바랍니다.

## 1. 웹훅 헤더

|  순번 | 변수명                  |  필수 | 설명                     | 예시                                         |
| :-: | -------------------- | :-: | ---------------------- | ------------------------------------------ |
|  1  | Pb-Webhook-Type      |  Y  | Webhook 유형             | STATEMENT.STATE                            |
|  2  | Pb-Webhook-MID       |  Y  | 이벤트 식별값                | 016120000002-1777d55c2c41492ab06826d       |
|  3  | Pb-Webhook-Corpnum   |  Y  | 팝빌 사업자번호               | 6798700433                                 |
|  4  | Content-Type         |  Y  | Webhook 메시지 Body 타입    | application/json                           |
|  5  | Authorization        |  N  | Base64 인코딩한 BASIC 인증정보 | Basic VEVTVDoxMjM= → HTTP 인증 사용하는 경우 추가 항목 |
|  6  | X-Api-Key            |  N  | API Key 인증정보           | TESTAPIKEY → HTTP 인증 사용하는 경우 추가 항목         |
|  7  | Pb-Webhook-EventType |  N  | Webhook 메시지 Event 타입   | Issue                                      |

> 팝빌은 기본으로 제공되는 Header 필드 외 프로그램 공급사 운영환경에 맞춘 커스텀 필드 지원이 가능합니다.\
> 커스텀 필드 추가가 필요한 경우 팝빌 기술지원센터(1600-9854)로 문의주시기 바랍니다.

## 2. 문서 상태

전자명세서에서 발생하는 웹훅 이벤트입니다.\
각 이벤트 발생시점은 [\[상태확인\]](https://developers.popbill.com/guide/statement/introduction/issue#check-state) 에서 확인 가능합니다.

| 이벤트 유형                                                                                                               | 설명              |
| -------------------------------------------------------------------------------------------------------------------- | --------------- |
| [Issue](https://developers.popbill.com/reference/statement/dotnetcore/webhook/webhook-event#statement-state-issue)   | 전자명세서 발행        |
| [Cancel](https://developers.popbill.com/reference/statement/dotnetcore/webhook/webhook-event#statement-state-cancel) | 전자명세서 발행취소      |
| [OPEN](https://developers.popbill.com/reference/statement/dotnetcore/webhook/webhook-event#statement-state-open)     | 수신자 발행 안내 메일 확인 |

> 팝빌 사이트에서 “Webhook 실행” 버튼을 클릭하여 웹훅을 전송하는 경우, eventType으로 “MANUAL”이 반환됩니다.

### Issue - 발행

발신자가 전자명세서를 작성하여 발행을 완료한 시점에 실행됩니다.

**이벤트 본문**

- corpNum `type: string` `length: 10` `required: Y` `description: 발행자 사업자번호`
- itemKey `type: string` `length: 18` `required: Y` `description: 팝빌번호`
- invoiceNum `type: string` `length: 24` `required: Y` `description: 팝빌승인번호`
- stateCode `type: number` `length: 3` `required: Y` `description: 상태코드`
  - [\[참고\] 팝빌 상태코드](https://developers.popbill.com/reference/statement/dotnetcore/response-code#state-code)
- stateDT `type: string` `length: 14` `required: Y` `description: 상태 변경일시`
  - 형식 : yyyyMMddHHmmss
- issueDT `type: string` `length: 14` `required: Y` `description: 발행일시`
  - 형식 : yyyyMMddHHmmss
- mgtKey `type: string` `length: 24` `required: N` `description: 파트너가 할당한 문서번호`
- eventDT `type: string` `length: 14` `required: Y` `description: 이벤트 실행일시`
  - 형식 : yyyyMMddHHmmss
- eventType `type: string` `length: 30` `required: Y` `description: 이벤트 유형`
  - `Issue`
- itemCode `type: number` `length: 3` `required: Y` `description: 전자명세서 구분`
  - `121`: 거래명세서
  - `122`: 청구서
  - `123`: 견적서
  - `124`: 발주서
  - `125`: 입금표
  - `126`: 영수증
- interOPYN `type: boolean` `length: -` `required: Y` `description: 연동문서 여부`
  - `true`: API로 발행한 연동문서
  - `false`: 팝빌 사이트에서 발행한 일반문서
- stateMemo `type: string` `length: 200` `required: N` `description: 상태메모`

**이벤트 예시**

```json
{
    "corpNum": "1234567890",
    "itemKey": "022111416074100001",
    "invoiceNum": "123456789020221114000001",
    "stateCode": 300,
    "stateDT": "20221114160743",
    "issueDT": "20221114160743",
    "eventDT": "20221114160743",
    "eventType": "Issue",
    "itemCode": 121,
    "interOPYN": false
}
```

### Cancel - 발행취소

발신자가 전자명세서를 발행취소한 시점에 실행됩니다.

**이벤트 본문**

- corpNum `type: string` `length: 10` `required: Y` `description: 발행자 사업자번호`
- itemKey `type: string` `length: 18` `required: Y` `description: 팝빌번호`
- invoiceNum `type: string` `length: 24` `required: Y` `description: 팝빌승인번호`
- stateCode `type: number` `length: 3` `required: Y` `description: 상태코드`
  - [\[참고\] 팝빌 상태코드](https://developers.popbill.com/reference/statement/dotnetcore/response-code#state-code)
- stateDT `type: string` `length: 14` `required: Y` `description: 상태 변경일시`
  - 형식 : yyyyMMddHHmmss
- issueDT `type: string` `length: 14` `required: Y` `description: 발행일시`
  - 형식 : yyyyMMddHHmmss
- mgtKey `type: string` `length: 24` `required: N` `description: 파트너가 할당한 문서번호`
- eventDT `type: string` `length: 14` `required: Y` `description: 이벤트 실행일시`
  - 형식 : yyyyMMddHHmmss
- eventType `type: string` `length: 30` `required: Y` `description: 이벤트 유형`
  - `Cancel`
- itemCode `type: number` `length: 3` `required: Y` `description: 전자명세서 구분`
  - `121`: 거래명세서
  - `122`: 청구서
  - `123`: 견적서
  - `124`: 발주서
  - `125`: 입금표
  - `126`: 영수증
- interOPYN `type: boolean` `length: -` `required: Y` `description: 연동문서 여부`
  - `true`: API로 발행한 연동문서
  - `false`: 팝빌 사이트에서 발행한 일반문서
- stateMemo `type: string` `length: 200` `required: N` `description: 상태메모`

**이벤트 예시**

```json
{
    "corpNum": "1234567890",
    "itemKey": "022111416205800001",
    "invoiceNum": "123456789020221114000002",
    "stateCode": 500,
    "stateDT": "20221114162103",
    "issueDT": "20221114162100",
    "eventDT": "20221114162103",
    "eventType": "Cancel",
    "itemCode": 121,
    "interOPYN": false
}
```

### OPEN - 발행 안내 메일 확인

수신자가 발행 안내 메일의 ‘전자명세서 보기’ 버튼을 클릭하는 시점에 실행됩니다.

**이벤트 본문**

- corpNum `type: string` `length: 10` `required: Y` `description: 발행자 사업자번호`
- itemKey `type: string` `length: 18` `required: Y` `description: 팝빌번호`
- invoiceNum `type: string` `length: 24` `required: Y` `description: 팝빌승인번호`
- stateCode `type: number` `length: 3` `required: Y` `description: 상태코드`
  - [\[참고\] 팝빌 상태코드](https://developers.popbill.com/reference/statement/dotnetcore/response-code#state-code)
- stateDT `type: string` `length: 14` `required: Y` `description: 상태 변경일시`
  - 형식 : yyyyMMddHHmmss
- issueDT `type: string` `length: 14` `required: Y` `description: 발행일시`
  - 형식 : yyyyMMddHHmmss
- mgtKey `type: string` `length: 24` `required: N` `description: 파트너가 할당한 문서번호`
- eventDT `type: string` `length: 14` `required: Y` `description: 이벤트 실행일시`
  - 형식 : yyyyMMddHHmmss
- eventType `type: string` `length: 30` `required: Y` `description: 이벤트 유형`
  - `OPEN`
- itemCode `type: number` `length: 3` `required: Y` `description: 전자명세서 구분`
  - `121`: 거래명세서
  - `122`: 청구서
  - `123`: 견적서
  - `124`: 발주서
  - `125`: 입금표
  - `126`: 영수증
- interOPYN `type: boolean` `length: -` `required: Y` `description: 연동문서 여부`
  - `true`: API로 발행한 연동문서
  - `false`: 팝빌 사이트에서 발행한 일반문서
- stateMemo `type: string` `length: 200` `required: N` `description: 상태메모`

**이벤트 예시**

```json
{
    "corpNum": "1234567890",
    "itemKey": "022111416074100001",
    "invoiceNum": "123456789020221114000001",
    "stateCode": 300,
    "stateDT": "20221114160743",
    "issueDT": "20221114160743",
    "eventDT": "20221114161852",
    "eventType": "OPEN",
    "itemCode": 121,
    "interOPYN": false
}
```
