# 데이터 저장 설계

원문: https://commerce.bootpay.ai/api/reference/data-model

> 데이터 저장 설계 — Bootpay 연동 시 가맹점 DB 에 무엇을 언제 저장하는지

API 응답과 웹훅 데이터를 가맹점 DB에 저장하고 동기화합니다.

## Bootpay ↔ 가맹점 모델 매핑

Bootpay API 사용 시 데이터를 가맹점 DB에 동기화합니다. **Receipt는 orders 테이블에 포함**합니다.

:::canvas-flow
{
  "nodes": [
    {
      "id": "order",
      "label": "Order\n주문",
      "col": 0,
      "row": 0
    },
    {
      "id": "receipt",
      "label": "Receipt\n결제 영수증 · 검증 API 로 저장",
      "col": 0,
      "row": 1
    },
    {
      "id": "subscription",
      "label": "OrderSubscription\n구독 계약",
      "col": 0,
      "row": 2
    },
    {
      "id": "billingkey",
      "label": "BillingKey\n빌링키",
      "col": 0,
      "row": 3
    },
    {
      "id": "orders",
      "label": "orders\n주문 + 결제 정보",
      "col": 1,
      "row": 0,
      "type": "success"
    },
    {
      "id": "subscriptions",
      "label": "subscriptions\n구독 기록",
      "col": 1,
      "row": 2,
      "type": "success"
    },
    {
      "id": "billing_keys",
      "label": "billing_keys\n저장 결제수단",
      "col": 1,
      "row": 3,
      "type": "success"
    }
  ],
  "edges": [
    {
      "from": "order",
      "to": "orders",
      "label": "조회 API / 웹훅"
    },
    {
      "from": "receipt",
      "to": "orders"
    },
    {
      "from": "subscription",
      "to": "subscriptions",
      "label": "구독 API / 웹훅"
    },
    {
      "from": "billingkey",
      "to": "billing_keys",
      "label": "조회 API"
    }
  ],
  "direction": "LR",
  "cols": 2,
  "rows": 4
}
:::

| Bootpay 모델 | 가맹점 테이블 | 동기화 방법 | 사용하는 API |
|---|---|---|---|
| Order (주문) | `orders` | 주문 조회 API + 웹훅 수신 | [커머스 API](https://commerce.bootpay.ai/docs/orders) |
| Receipt (결제 영수증) | `orders`에 결제 필드로 포함 | 결제 검증 API 응답 저장 | [결제 API](https://developers.bootpay.ai/guide/intro) |
| OrderSubscription | `subscriptions` | 구독 조회 API + 웹훅 수신 | [구독관리](https://commerce.bootpay.ai/docs/subscription) |

::: tip API별 저장 테이블
- 커머스 API 사용: `orders` + `subscriptions` (구독 시)
:::

::: info Receipt를 별도 테이블로 분리해야 하는 경우
한 주문에 결제가 여러 번 일어나면(부분결제, 추가결제) `order_payments` 서브테이블로 분리할 수 있습니다. 1주문 = 1결제이면 `orders`에 포함합니다.
:::

---

## API별 데이터 책임 경계

API별로 누가 무엇을 관리하는지는 가이드 [커머스 SDK 소개 > 커머스 API 가 대신하는 일](https://commerce.bootpay.ai/docs/start#커머스-api-가-대신하는-일)에 있습니다. 아래는 그 경계에 맞춘 저장 설계입니다. 결제 SDK 만 쓸 때의 저장 설계(결제 필드 · 빌링키 테이블)는 결제 문서 [데이터 모델 설계](https://developers.bootpay.ai/reference/architecture/data-model)에 있습니다.

---

## 커머스 API — 데이터 책임 경계 {#commerce-api}

커머스 API는 **주문 · 구독 · 이행까지** Bootpay가 관리합니다. 가맹점은 상품과 회원만 관리하면 됩니다.

### 가맹점이 직접 관리

| 데이터 | 설명 |
|------|------|
| 상품 · 회원 | 이름, 가격, 재고, Auth, 프로필 |
| Bootpay ID 매핑 | order_id, subscription_id 등 |
| 비즈니스 로직 | 주문 메모, 내부 태그, CRM 데이터 |

### Bootpay가 관리 → 가맹점이 동기화

| 데이터 | Bootpay가 하는 일 | 가맹점이 하는 일 |
|------|------|------|
| 결제 상태 | PG 승인 · 취소 · 환불 처리 | 웹훅으로 상태 동기화 (CS 조회용) |
| 주문 상태 | 주문 → 결제 → 이행 상태머신 관리 | 웹훅으로 상태 동기화 (운영 대시보드) |
| 이행 상태 | 발주 확인 → 배송 → 배달 추적 | 웹훅으로 배송 현황 동기화 |
| 구독 상태 | 활성 · 정지 · 해지 전환, 자동 과금 | 웹훅으로 서비스 접근 제어 on/off |
| 취소/환불 | 취소 요청 → 승인 → 금액 계산 → PG 환불 | 웹훅으로 취소 상태 동기화 |

### Bootpay만 관리

| 데이터 | 설명 |
|------|------|
| PG 트랜잭션 원본 | 카드사 승인번호, PG 응답 전문 |
| 빌링키 | 저장 결제수단, 토큰 (PCI DSS 준수) |
| 구독 과금 이력 | 회차별 결제 시도 · 성공 · 실패 · 재시도 |
| 상품 스냅샷 | 주문 시점의 가격 · 옵션 고정 |
| 웹훅 발송 이력 | 이벤트 전송 로그, 재시도 상태 |

::: tip
상태 데이터의 정본(source of truth)은 항상 Bootpay입니다. 가맹점 DB의 상태는 캐시 역할이며, 불일치 시 API로 최신 상태를 확인합니다.
:::

### 내부 모델 계층

API 응답과 웹훅 데이터는 아래 내부 모델 구조를 따릅니다. 가맹점은 내부 모델에 직접 접근할 수 없습니다.

```
Project (가맹점 프로젝트)
├── User (고객, 개인정보 암호화)
│   └── UserWallet (저장 결제수단, 빌링키)
│
├── Product (상품)
│   ├── ProductOption (옵션: 색상, 사이즈 등)
│   ├── ProductSnapshot (주문 시점 가격 고정)
│   └── SubscriptionSetting (구독 정책: 주기, 재시도, 해지)
│
├── OrderPre (결제 전 임시 주문)
│   └── Order (결제 완료 확정 주문)
│       ├── OrderPurchase (판매자별 이행/배송 단위)
│       └── OrderCancellationRequestHistory (취소/환불 이력)
│
├── OrderSubscription (구독 계약)
│   └── OrderSubscriptionBill (회차별 과금)
│       └── OrderSubscriptionTransaction (결제 실행)
│
└── WebhookJob → WebhookLog (이벤트 발송/이력)
```

주문 상태는 결제 대기·진행·완료, 취소·반품·교환, 구독 분기를 합쳐 18종이고, 구독 상태와 회차(Bill) 상태는 서로 다른 체계입니다. 값은 [커머스 Enum](https://commerce.bootpay.ai/api/reference/enum)에 있습니다.

::: info 3단계 주문 구조
주문은 `OrderPre(결제 전)` → `Order(결제 완료)` → `OrderPurchase(이행)` 3단계로 처리됩니다. 결제 전 주문서는 일정 시간(기본 30분, 몰 설정의 결제 유효시간으로 변경 가능) 후 자동 만료되며, 결제가 완료되면 `Order`로 확정됩니다. 상세는 [주문·배송](https://commerce.bootpay.ai/docs/orders) · [주문 처리 예제](https://commerce.bootpay.ai/api/server/order-example)에서 확인합니다.
:::

### 도메인별 상세

#### 주문 영역

| 데이터 | Bootpay | 가맹점 | 동기화 |
|------|:---:|:---:|------|
| 주문번호 ↔ 내부 ID 매핑 | - | 직접 관리 | - |
| 주문 메모, 내부 태그 | - | 직접 관리 | - |
| 주문 상태 (결제대기 → 완료 → 취소) | 관리 | 동기화 | 웹훅 `order.*` |
| 결제 트랜잭션 (PG 응답, 카드사) | 관리 | - | API 조회 |
| 이행 상태 (확인 → 배송 → 배달) | 관리 | 동기화 | API 조회 ([배송추적 조회](https://commerce.bootpay.ai/api/orders/tracking)) — 이행 웹훅은 없습니다 |
| 취소/환불 처리 | 관리 | 동기화 | 웹훅 `order.cancelled` |
| 배송 추적 (택배사, 운송장) | 관리 | - | API 조회 |

#### 구독 영역

| 데이터 | Bootpay | 가맹점 | 동기화 |
|------|:---:|:---:|------|
| 구독 ID ↔ 서비스 정책 매핑 | - | 직접 관리 | - |
| 서비스 접근 제어 (active/inactive) | - | 직접 관리 | - |
| 구독 상태 (대기 → 활성 → 정지 → 해지) | 관리 | 동기화 | 웹훅 `subscription.*` |
| 회차별 과금 + 자동 재시도 | 관리 | - | API 조회 |
| 구독 정책 (주기, 재시도, 해지 조건) | 관리 | - | API 설정 |

#### 고객 영역

| 데이터 | Bootpay | 가맹점 | 동기화 |
|------|:---:|:---:|------|
| **자체 Auth** (로그인, 비밀번호) | - | 직접 관리 | - |
| 고객 프로필 (이름, 이메일, 전화번호) | 암호화 보관 | 선택 저장 | - |
| 저장 결제수단 (빌링키) | 관리 | - | - |
| 결제/주문/구독 이력 | 관리 | - | API 조회 |

### 최소 DB 스키마

#### 주문 + 결제

```sql
CREATE TABLE orders (
    id              BIGINT PRIMARY KEY AUTO_INCREMENT,
    user_id         BIGINT NOT NULL,
    bootpay_order_id    VARCHAR(100),     -- Bootpay 주문 ID
    bootpay_order_number VARCHAR(100),    -- Bootpay 주문 번호
    order_name      VARCHAR(200),
    total_amount    INTEGER NOT NULL,
    status          VARCHAR(20) DEFAULT 'pending',
    -- pending → paid → confirmed → completed → refunded
    paid_at         DATETIME,
    created_at      DATETIME DEFAULT CURRENT_TIMESTAMP,

    INDEX idx_user (user_id),
    INDEX idx_bootpay_order (bootpay_order_id)
);

CREATE TABLE order_items (
    id              BIGINT PRIMARY KEY AUTO_INCREMENT,
    order_id        BIGINT NOT NULL,
    product_id      BIGINT NOT NULL,      -- 가맹점 상품 ID
    product_name    VARCHAR(200),
    quantity        INTEGER DEFAULT 1,
    unit_price      INTEGER NOT NULL,

    FOREIGN KEY (order_id) REFERENCES orders(id)
);
```

**저장 시점**:
1. 주문서 요청 전 → `orders` 레코드 생성 (status: `pending`)
2. [서버 검증](https://commerce.bootpay.ai/api/checkout/create#서버-검증-개발자--서버) 성공 후 → status를 `paid`로 변경, `bootpay_order_number` 저장 (`bootpay_order_id` 는 [주문 목록](https://commerce.bootpay.ai/api/orders/list) 응답에서만 받을 수 있습니다)
3. [웹훅](https://commerce.bootpay.ai/api/server/webhook-setup) `order.cancelled` 수신 → status를 `refunded`로 변경

#### 주문 + 이행/배송 관리

물리적 배송이 있는 쇼핑몰이라면 이행(Fulfillment) 상태를 추적하는 테이블을 추가합니다.

```sql
CREATE TABLE order_fulfillments (
    id                  BIGINT PRIMARY KEY AUTO_INCREMENT,
    order_id            BIGINT NOT NULL,
    bootpay_order_number VARCHAR(100) NOT NULL,   -- Bootpay 주문 번호
    progress_status     VARCHAR(20) DEFAULT 'ready',
    -- ready → confirmed → preparing → shipped → delivered
    confirmed_at        DATETIME,                 -- 발주 확인
    shipped_at          DATETIME,                 -- 배송 시작
    delivered_at        DATETIME,                 -- 배송 완료
    delivery_company    VARCHAR(50),              -- 택배사명
    tracking_number     VARCHAR(100),             -- 운송장 번호

    FOREIGN KEY (order_id) REFERENCES orders(id),
    INDEX idx_order (order_id),
    INDEX idx_status (progress_status)
);
```

**Bootpay 이행 상태와의 매핑**:

응답의 `order_purchases[].status` 로 매핑합니다. 같은 배열의 `progress_status` 는 발송처리로 갱신되지 않으니 쓰면 안 됩니다.

| Bootpay 내부 상태 | 코드 | 가맹점 스키마의 `progress_status` |
|---|---|---|
| PRE_ORDER | 0 | `ready` |
| READY (발주 대기) | 1 | `ready` |
| CONFIRMED | 2 | `confirmed` |
| PREPARING | 3 | `preparing` |
| SENT | 4 | `shipped` |
| DELIVERED | 5 | `delivered` |

::: tip
디지털 상품이라면 이행 테이블 없이 `orders.status`를 `paid` → `completed`로 바로 전환하면 됩니다.
:::

#### 구독 결제

```sql
CREATE TABLE subscriptions (
    id              BIGINT PRIMARY KEY AUTO_INCREMENT,
    user_id         BIGINT NOT NULL,
    bootpay_subscription_id VARCHAR(100) NOT NULL,  -- Bootpay 구독 ID
    plan_name       VARCHAR(100),         -- "Pro", "Enterprise" 등
    amount          INTEGER NOT NULL,     -- 회차 결제 금액
    service_active  BOOLEAN DEFAULT FALSE,-- 서비스 접근 허용 여부
    status          VARCHAR(20) DEFAULT 'pending',
    -- pending → active → paused → terminated
    current_period_end DATETIME,          -- 현재 구독 기간 종료일
    created_at      DATETIME DEFAULT CURRENT_TIMESTAMP,

    INDEX idx_user (user_id),
    INDEX idx_bootpay_sub (bootpay_subscription_id)
);
```

**저장 시점**:
1. 구독 신청 시 → `subscriptions` 레코드 생성 (status: `pending`)
2. [웹훅](https://commerce.bootpay.ai/api/server/webhook-setup) `subscription.approved` → `service_active = true`, status: `active`
3. 웹훅 `subscription.terminated` → `service_active = false`, status: `terminated`

::: warning 중요
구독 회차별 결제 이력은 Bootpay가 관리합니다. 가맹점은 서비스 접근 제어(active/inactive)만 관리하면 됩니다. 회차 상세는 [회차 조회 API](https://commerce.bootpay.ai/api/subscription-ops/bill/cycle)로 확인합니다.
:::

### 주문 조회 응답에서 저장할 필드

| 응답 필드 | 저장 여부 | 용도 |
|-----------|:---:|------|
| `order_number` | 필수 | Bootpay 주문 번호 |
| `price` | 필수 | 결제 금액 |
| `status` | 필수 | 주문 상태 |
| `purchased_at` | 권장 | 결제 시각 |
| `receipt_id` | 권장 | 결제 영수증 ID |
| `order_id` | 선택 | Bootpay 주문 문서 ID — 상세 응답에는 없고 [주문 목록](https://commerce.bootpay.ai/api/orders/list) 응답에만 있습니다 |

## 저장하면 안 되는 것

::: danger PCI DSS 준수
아래 데이터는 절대 저장하면 안 됩니다:
- 카드 번호 전체 (full PAN)
- CVV/CVC
- 카드 비밀번호
- 유효기간 (월/년)

마스킹된 카드번호(`557042**1074`)와 카드사명은 저장해도 됩니다.
:::

---

## 데이터 흐름 상세

### 커머스 API — Order → orders

:::canvas-sequence
{
  "participants": [
    {
      "id": "db",
      "label": "가맹점 DB"
    },
    {
      "id": "be",
      "label": "서버"
    },
    {
      "id": "bp",
      "label": "BOOTPAY"
    }
  ],
  "messages": [
    {
      "from": "bp",
      "to": "be",
      "label": "① 리다이렉트로 order_number 전달",
      "type": "dashed"
    },
    {
      "from": "be",
      "to": "bp",
      "label": "② 주문 검증 GET /v1/orders/{order_number}",
      "type": "solid"
    },
    {
      "from": "bp",
      "to": "be",
      "label": "③ Order 응답 (price · status · products)",
      "type": "dashed"
    },
    {
      "from": "be",
      "to": "be",
      "label": "④ 금액·상태 검증",
      "type": "solid"
    },
    {
      "from": "be",
      "to": "db",
      "label": "⑤ orders에 저장",
      "type": "solid"
    },
    {
      "from": "bp",
      "to": "be",
      "label": "⑥ 웹훅 (order.done / cancelled)",
      "type": "dashed"
    },
    {
      "from": "be",
      "to": "db",
      "label": "⑦ status 업데이트",
      "type": "solid"
    }
  ]
}
:::

④ 는 `price` 가 주문 금액과 같은지, `status` 가 `payment_completed`(결제 완료)인지 확인합니다.

::: warning 조회 키는 `order_number` 입니다
`order_id`(24자리 ObjectId)를 `GET /v1/orders/{...}` 에 넣으면 `ORDER_NOT_FOUND` 가 반환됩니다. 조회·취소에는 `order_number` 를 사용합니다. `order_id` 는 [주문 상세](https://commerce.bootpay.ai/api/orders/detail)·웹훅에는 없고 [주문 목록](https://commerce.bootpay.ai/api/orders/list) 응답에만 있습니다.
:::

#### 필드 매핑

| Bootpay Order 필드 | → | 가맹점 orders 컬럼 | 저장 | 용도 |
|---|---|---|---|---|
| `order_number` | → | `bootpay_order_number` | 필수 | 주문 고유번호. 주문 조회·취소는 이 값으로 합니다 |
| `order_id` | → | `bootpay_order_id` | 선택 | 내부 식별자 (24자리). 목록 응답에서만 받을 수 있고 조회 키가 아닙니다 |
| `price` | → | `total_amount` | 필수 | 결제 금액 (검증용) |
| `status` | → | `status` | 필수 | 주문 상태 |
| `purchased_at` | → | `paid_at` | 권장 | 결제 완료 시각 |
| `receipt_id` | → | `receipt_id` | 권장 | 결제 영수증 ID |
| `user.user_id` | → | `customer_id` | 권장 | 구매 고객 연결 |
| `products[].product_id` | → | `order_items.product_id` | 권장 | 주문 상품 |
| `products[].quantity` | → | `order_items.quantity` | 권장 | 수량 |

#### 주문 상태 코드 (`status`)

:::canvas-flow
{
  "nodes": [
    {
      "id": "created",
      "label": "주문 생성\n0 · order_pending",
      "col": 0,
      "row": 0
    },
    {
      "id": "paying",
      "label": "결제 진행\n1 · payment_pending",
      "col": 1,
      "row": 0
    },
    {
      "id": "paid",
      "label": "결제 완료\n2 · payment_completed",
      "col": 2,
      "row": 0,
      "type": "success"
    },
    {
      "id": "cancelled",
      "label": "취소 완료\n10 · cancellation_completed",
      "col": 2,
      "row": 1
    }
  ],
  "edges": [
    {
      "from": "created",
      "to": "paying",
      "label": "결제 시작"
    },
    {
      "from": "paying",
      "to": "paid",
      "label": "결제 성공"
    },
    {
      "from": "paid",
      "to": "cancelled",
      "label": "취소 승인"
    }
  ],
  "direction": "LR"
}
:::

::: warning 「취소 요청」은 주문 상태가 아닙니다
취소 요청은 주문 `status` 가 아니라 별도 리소스(`order_cancellation_request_history`)의 상태입니다 —
`cancel_requested` → `cancel_approved` 로 바뀌고, 승인된 뒤에야 주문 `status` 가 `cancellation_completed`(10) 로 바뀝니다.
주문 `status` 의 `3`·`4` 는 취소가 아니라 구독 관련 상태(`subscription_request_completed`·`subscription_pending`)입니다.
전체 값은 [커머스 Enum](https://commerce.bootpay.ai/api/reference/enum#주문-상태-status)을 확인합니다.
:::

| `status` | 의미 | 가맹점 처리 |
|---|---|---|
| `order_pending` | 주문 생성 (결제 대기) | — |
| `payment_pending` | 결제 진행 중 | — |
| **`payment_completed`** | **결제 완료** | orders에 저장, 서비스 제공 |
| `cancellation_completed` | 취소 완료 | status 업데이트, 환불 처리 |
| `return_completed` | 반품 완료 | 반품 처리 |
| `payment_failed` | 결제 실패 | 주문 실패 처리 |

### 커머스 API — OrderSubscription → subscriptions

:::canvas-sequence
{
  "participants": [
    {
      "id": "db",
      "label": "가맹점 DB"
    },
    {
      "id": "be",
      "label": "서버"
    },
    {
      "id": "bp",
      "label": "BOOTPAY"
    }
  ],
  "messages": [
    {
      "from": "be",
      "to": "bp",
      "label": "① 구독 승인 PUT /v1/order_subscriptions/:id/approve",
      "type": "solid"
    },
    {
      "from": "bp",
      "to": "be",
      "label": "② 구독 응답 (status · payment_next_at)",
      "type": "dashed"
    },
    {
      "from": "be",
      "to": "db",
      "label": "③ subscriptions 저장 · service_active = true",
      "type": "solid"
    },
    {
      "from": "bp",
      "to": "bp",
      "label": "④ 매 회차 빌링키로 자동 결제",
      "type": "solid"
    },
    {
      "from": "bp",
      "to": "be",
      "label": "⑤ 회차 주문 웹훅 order.done",
      "type": "dashed"
    },
    {
      "from": "be",
      "to": "bp",
      "label": "⑥ 회차 · 계약 조회 (payment_next_at)",
      "type": "solid"
    },
    {
      "from": "be",
      "to": "db",
      "label": "기간 연장",
      "type": "solid"
    },
    {
      "from": "bp",
      "to": "be",
      "label": "⑦ 웹훅 (자동 해지 · 관리자 정지)",
      "type": "dashed"
    },
    {
      "from": "be",
      "to": "db",
      "label": "⑧ 서비스 차단 · service_active = false",
      "type": "solid"
    }
  ]
}
:::

⑤ 는 회차마다 만들어지는 결제용 주문의 주문 웹훅(`order.done`, 실패는 `order.confirm_error`)입니다. 회차 성공 전용 구독 웹훅(`subscription.renewed`)은 지금 발송되지 않고, 주문 웹훅에는 계약 상태가 담기지 않습니다. ⑦ 도 고객이 요청한 해지·일시정지에는 오지 않습니다. 그래서 ⑥ 은 [회차 조회](https://commerce.bootpay.ai/api/subscription-ops/bill/cycle)와 [계약 상세](https://commerce.bootpay.ai/api/subscription-contract/detail)의 `payment_next_at` 을 주기적으로 읽어 반영합니다. 자세한 내용은 [주문 웹훅 설정의 알려진 문제](https://commerce.bootpay.ai/api/server/webhook-setup#구독-이벤트)에 있습니다.

#### 필드 매핑

| Bootpay Subscription 필드 | → | 가맹점 subscriptions 컬럼 | 저장 | 용도 |
|---|---|---|---|---|
| `order_subscription_id` | → | `bootpay_subscription_id` | 필수 | 구독 조회·해지 시 사용 |
| `order_number` | → | `bootpay_order_number` | 필수 | 원 주문 연결 |
| `status` | → | `status` | 필수 | 구독 상태 |
| `price` | → | `amount` | 필수 | 회차별 결제 금액 |
| `subscription_payment_cycle_type` | → | `billing_cycle` | 권장 | `1month`, `1year` 등 — [결제 주기](https://commerce.bootpay.ai/api/reference/enum#구독-결제-주기-subscription_payment_cycle_type) |
| `payment_next_at` | → | `next_billing_at` | 권장 | 다음 결제 예정일 |
| `service_start_at` | → | `started_at` | 권장 | 서비스 시작일 |
| `approval_at` | → | `approved_at` | 선택 | 승인 시각 |

#### 구독 상태 코드 (`status`)

:::canvas-flow
{
  "nodes": [
    {
      "id": "pending",
      "label": "대기\n0 · contract_requested_completed",
      "col": 0,
      "row": 1
    },
    {
      "id": "active",
      "label": "구독 중\n1 · subscribing",
      "col": 1,
      "row": 1,
      "type": "success"
    },
    {
      "id": "paused",
      "label": "일시정지\n-2 · temporarily_paused",
      "col": 1,
      "row": 0
    },
    {
      "id": "hold",
      "label": "문제로 멈춤 (반복 결제 실패)\n-3 · paused_due_to_issue",
      "col": 2,
      "row": 0
    },
    {
      "id": "terminated",
      "label": "해지\n20 · manual_terminated",
      "col": 2,
      "row": 1
    },
    {
      "id": "expired",
      "label": "만료\n15 · auto_terminated",
      "col": 1,
      "row": 2
    }
  ],
  "edges": [
    {
      "from": "pending",
      "to": "active",
      "label": "승인"
    },
    {
      "from": "active",
      "to": "paused",
      "label": "정지 요청"
    },
    {
      "from": "paused",
      "to": "active",
      "label": "재개"
    },
    {
      "from": "active",
      "to": "terminated",
      "label": "해지"
    },
    {
      "from": "active",
      "to": "hold"
    },
    {
      "from": "active",
      "to": "expired",
      "label": "기간 만료"
    }
  ],
  "direction": "LR",
  "cols": 3,
  "rows": 3
}
:::

| 값 | `status` | 의미 | 가맹점 `service_active` |
|----|----------|------|---|
| `0` | `contract_requested_completed` | 대기 (승인 전) | `false` |
| `1` | `subscribing` | 구독 중 | `true` |
| `-2` | `temporarily_paused` | 일시정지 (고객이 스스로 멈춤) | `false` (일시) |
| `-3` | `paused_due_to_issue` | 반복 결제 실패로 자동 중단 — `subscription.hold_on` | `false` |
| `20` | `manual_terminated` | 고객 해지 | `false` |
| `-11` | `admin_terminated` | 관리자 해지 | `false` |
| `15` | `auto_terminated` | 기간 만료 | `false` |

---

## 모델 관계

API 응답과 웹훅에 쓰이는 내부 모델은 아래처럼 이어집니다.

:::canvas-flow
{
  "nodes": [
    {
      "id": "product",
      "label": "Product\n상품",
      "col": 0,
      "row": 0
    },
    {
      "id": "order",
      "label": "Order\n주문",
      "col": 1,
      "row": 0
    },
    {
      "id": "receipt",
      "label": "Receipt\n결제 영수증",
      "col": 2,
      "row": 0,
      "type": "success"
    },
    {
      "id": "purchase",
      "label": "OrderPurchase\n이행·배송",
      "col": 1,
      "row": 1
    },
    {
      "id": "subscription",
      "label": "OrderSubscription\n구독 계약",
      "col": 0,
      "row": 2
    },
    {
      "id": "bill",
      "label": "SubscriptionBill\n회차 과금",
      "col": 1,
      "row": 2,
      "type": "success"
    }
  ],
  "edges": [
    {
      "from": "product",
      "to": "order",
      "label": "주문서 결제"
    },
    {
      "from": "product",
      "to": "subscription",
      "label": "구독 상품"
    },
    {
      "from": "order",
      "to": "receipt",
      "label": "결제"
    },
    {
      "from": "order",
      "to": "purchase",
      "label": "이행"
    },
    {
      "from": "subscription",
      "to": "bill",
      "label": "매 회차"
    }
  ],
  "direction": "LR",
  "cols": 3,
  "rows": 3
}
:::

| 모델 | 설명 | API 응답에서 확인 |
|---|---|---|
| Product | 상품 (일반/구독) | [상품 조회](https://commerce.bootpay.ai/api/catalog/list) |
| Order | 결제 완료된 확정 주문 | [주문 상세](https://commerce.bootpay.ai/api/orders/detail) |
| OrderPurchase | 판매자별 이행/배송 단위 | 주문 상세 응답 내 `order_purchases` |
| Receipt | PG 결제 영수증 | [결제 검증](https://developers.bootpay.ai/server/verify) · [결제 조회](https://developers.bootpay.ai/server/verify) |
| OrderSubscription | 구독 계약 | [계약 조회](https://commerce.bootpay.ai/api/subscription-contract/list) |
| SubscriptionBill | 회차별 과금 기록 | [회차 조회](https://commerce.bootpay.ai/api/subscription-ops/bill/cycle) |
