검색을 불러오는 중…

검색을 불러오는 중…

본문으로 건너뛰기

API v2는 기존 연동을 위한 버전입니다. 신규 연동에는 API v3를 사용하세요.

API v3에서 이 페이지 보기
상품 및 구독Checkout Session 생성

Checkout Session 생성

Tokenz 대시보드에서 관리하는 카탈로그 아이템으로 Checkout Session을 생성하는 방법을 알아봅니다.

개요

가상 아이템과 번들은 Tokenz 대시보드에서 카탈로그 아이템으로 관리합니다. Checkout Session을 생성할 때 카탈로그 아이템과 그 요금제 중 하나를 id로 참조합니다. 이름, 이미지, 가격은 카탈로그에서 가져오므로 요청에 가격을 넣지 않습니다.

사전 준비

카탈로그 아이템으로 Checkout Session을 생성하기 전에 다음을 준비하세요.

  1. 비밀 키: Tokenz 대시보드에서 연동에 사용할 비밀 키를 준비하세요.
  2. 카탈로그 설정: 판매할 카탈로그 아이템을 Tokenz 대시보드에서 공개하고, 게시된 요금제를 하나 이상 준비하세요.
  3. 카탈로그 아이템 및 요금제 id: 카탈로그 아이템 id(catalogitem_…)와 그 요금제의 id(priceplan_…)를 확인하세요. 둘 다 카탈로그 아이템 엔드포인트로 조회할 수 있습니다. 테스트 키는 테스트 아이템을 반환하며, 테스트 아이템의 id는 _t로 끝납니다.

카탈로그 아이템으로 Checkout Session 생성

카탈로그 아이템마다 itemDetails에 항목을 하나씩 추가하세요. 각 항목에는 필수 필드 세 개를 가진 catalogItem 객체를 지정합니다.

  • catalogItemId: 카탈로그 아이템의 id.
  • pricePlanId: 아이템의 pricePlans 중 하나의 id. 아이템의 defaultPricePlanId는 먼저 표시할 요금제를 가리킵니다.
  • quantity: 판매 수량. 1 이상이어야 합니다.

가상 아이템과 번들 모두 같은 방식으로 참조합니다.

카탈로그 아이템 하나

bash
curl --request POST \
  --url https://api.tokenz.one/v2/checkoutsession \
  --header 'Authorization: Bearer secret_test_YOUR_KEY_HERE' \
  --header 'Content-Type: application/json' \
  --data '{
    "itemDetails": [
      {
        "catalogItem": {
          "catalogItemId": "catalogitem_7Gp1KlY3wSz_t",
          "pricePlanId": "priceplan_4Tm8XuQ5pFg_t",
          "quantity": 2
        }
      }
    ],
    "customerInfo": {},
    "successUrl": "https://yourdomain.com/success",
    "pendingUrl": "https://yourdomain.com/pending",
    "cancelUrl": "https://yourdomain.com/cancel",
    "locale": "en_US"
  }'

카탈로그 아이템 여러 개

하나의 Checkout Session에 카탈로그 아이템을 여러 개 포함할 수 있습니다. 예를 들어 번들과 가상 아이템을 함께 지정합니다.

bash
curl --request POST \
  --url https://api.tokenz.one/v2/checkoutsession \
  --header 'Authorization: Bearer secret_test_YOUR_KEY_HERE' \
  --header 'Content-Type: application/json' \
  --data '{
    "itemDetails": [
      {
        "catalogItem": {
          "catalogItemId": "catalogitem_8Hq2LmZ4xTa_t",
          "pricePlanId": "priceplan_3Rk9VwP2nDe_t",
          "quantity": 1
        }
      },
      {
        "catalogItem": {
          "catalogItemId": "catalogitem_7Gp1KlY3wSz_t",
          "pricePlanId": "priceplan_4Tm8XuQ5pFg_t",
          "quantity": 3
        }
      }
    ],
    "customerInfo": {},
    "successUrl": "https://yourdomain.com/success",
    "pendingUrl": "https://yourdomain.com/pending",
    "cancelUrl": "https://yourdomain.com/cancel",
    "locale": "en_US"
  }'

구현 예제

javascript
import fetch from 'node-fetch';

async function createCheckoutSession() {
  const response = await fetch('https://api.tokenz.one/v2/checkoutsession', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.TOKENZ_SECRET_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      itemDetails: [
        {
          catalogItem: {
            catalogItemId: "catalogitem_7Gp1KlY3wSz_t",
            pricePlanId: "priceplan_4Tm8XuQ5pFg_t",
            quantity: 2
          }
        }
      ],
      customerInfo: {},
      successUrl: "https://yourdomain.com/success",
      pendingUrl: "https://yourdomain.com/pending",
      cancelUrl: "https://yourdomain.com/cancel",
      locale: "en_US"
    })
  });

  const session = await response.json();

  // Redirect user to checkout
  return session.url;
}

응답

API는 Checkout Session 객체를 반환합니다.

json
{
  "id": "checkoutsession_12345678QsZ",
  "object": "checkoutsession",
  "url": "https://checkout.tokenz.one/12345678QsZ",
  "cancelUrl": "https://yourdomain.com/cancel",
  "pendingUrl": "https://yourdomain.com/pending",
  "successUrl": "https://yourdomain.com/success",
  "order": {
    "id": "order_1xdzo1aZRGB",
    "object": "order",
    "status": "requiresPayment",
    "amount": {
      "amount": 398,
      "currency": "USD"
    },
    "items": [
      {
        "id": "item_1xdzo1ZpRcT",
        "detail": {
          "product": {
            "price": {
              "amount": 199,
              "currency": "USD"
            },
            "quantity": 2,
            "label": "100 Gems",
            "description": "",
            "images": [
              "https://example.com/images/gems-100.png"
            ],
            "sku": "gems-100",
            "taxCategory": "DIGITAL_GOODS_AND_SERVICES",
            "catalogItemId": "catalogitem_7Gp1KlY3wSz_t",
            "pricePlanId": "priceplan_4Tm8XuQ5pFg_t"
          }
        }
      }
    ],
    "test": true,
    "createdAt": "2026-11-20T04:32:04.696Z",
    "updatedAt": "2026-11-20T04:32:04.696Z"
  },
  "createdAt": "2026-11-20T04:32:04.374Z",
  "updatedAt": "2026-11-20T04:32:04.374Z",
  "test": true,
  "customerInfo": {},
  "locale": "en_US",
  "preferApplePay": false,
  "preferGooglePay": false
}

order.items의 각 product에는 가격의 기준이 된 catalogItemId와 pricePlanId가 포함됩니다. 이 값으로 지급할 내용을 결정하세요.

오류

카탈로그 아이템 항목이 포함된 요청은 다음 오류로 실패할 수 있습니다.

  • 400 itemDetails.catalogItem.not-supported: 계정이 Payment Gateway 모델을 사용하는 경우. 이 모델은 카탈로그 아이템을 지원하지 않습니다.
  • 400 pricePlan.recurring-not-supported: 구독을 생성하지 않는 Checkout Session에서 RECURRING 요금제를 지정한 경우.
  • 400 pricePlan.one-time-not-supported: 구독을 생성하는 Checkout Session에서 ONE_TIME 요금제를 지정한 경우.
  • 404 entity.not-found: 참조한 카탈로그 아이템 또는 요금제를 찾을 수 없는 경우.

권장 사항

  1. API에서 id 조회: 카탈로그 아이템과 요금제 id는 코드에 고정하지 말고 카탈로그 아이템 엔드포인트에서 조회하세요.
  2. 오류 처리: 위에 나열된 오류를 적절하게 처리하세요.
  3. 웹훅 사용: 결제 상태 업데이트를 실시간으로 받도록 설정하세요.
  4. 충분한 테스트: 운영 전 테스트 모드로 연동을 검증하세요.

다음 단계