Skip to main content
@dodopayments/express adaptor는 Express 앱에 세 가지 route handler를 제공합니다. checkoutHandler는 checkout URL을 반환하고, CustomerPortal는 고객을 Customer Portal로 보내며, Webhooks는 webhook 요청을 검증하고 이벤트 handler를 호출합니다.

Checkout Handler

Express 앱에서 payment link와 checkout session을 생성합니다.

Customer Portal

고객이 subscription과 세부 정보를 관리할 수 있도록 합니다.

Webhooks

Dodo Payments webhook 이벤트를 검증하고 처리합니다.

설치

1

Install the Package

프로젝트 루트에서 다음 명령을 실행합니다:
2

Set Up Environment Variables

프로젝트 루트에 .env 파일을 생성합니다:
Developer → API Keys에서 API key를 생성합니다. Developer → Webhooks에서 webhook endpoint를 추가하고 signing secret을 복사하여 DODO_PAYMENTS_WEBHOOK_KEY에 입력합니다. 개발하는 동안에는 DODO_PAYMENTS_ENVIRONMENT=test_mode가 포함된 test mode API key를 사용하세요. test mode key는 test mode에서만 작동하기 때문입니다. DODO_PAYMENTS_RETURN_URL는 선택 사항입니다.
.env 파일이나 secret을 version control에 commit하지 마세요.

Route Handler 예시

이 예시에서는 express()로 생성한 Express 앱에 route를 등록합니다. POST checkout handler와 webhook handler는 req.body를 읽으므로, 각 예시에서는 route보다 먼저 express.json()를 등록합니다.
이 handler를 사용하여 Express 앱에 Dodo Payments checkout을 통합합니다. static (GET), dynamic (POST), session (POST) payment flow를 지원합니다. 하나의 path에 각 POST flow를 등록하세요. 해당 path에 처음 등록된 handler가 모든 요청에 응답하기 때문입니다.

Checkout Route Handler

adaptor는 세 가지 Dodo Payments checkout flow를 모두 지원합니다. handler config에서 type를 설정하여 route가 제공할 flow를 선택합니다. 모든 flow는 고객이 열 수 있는 checkout_url를 포함한 JSON으로 응답합니다.
  • Static Payment Links: type: "static", GET. query parameter를 확인한 후 하나의 product에 대한 payment link를 생성합니다.
  • Dynamic Payment Links: type: "dynamic", POST. product가 recurring인지에 따라 payment link를 사용하여 일회성 payment 또는 subscription을 생성합니다.
  • Checkout Sessions: type: "session", POST. product cart와 customer 세부 정보로 checkout session을 생성합니다. 새 통합에는 이 flow를 사용하세요.
checkoutHandler는 다음 option을 사용합니다: type가 static이면 GET에 handler를 등록하고, dynamic 또는 session이면 POST에 등록합니다. handler는 다른 method에 대해 405를 반환합니다.

지원되는 Query Parameter

string
필수
Product identifier입니다. 예: ?productId=pdt_nZuwz45WAs64n3l07zpQR.
integer
기본값:"1"
Product 수량입니다.
string
Customer의 전체 이름입니다. firstName 또는 lastName가 제공되면 무시됩니다.
string
Customer의 이름입니다.
string
Customer의 성입니다.
string
Customer의 email address입니다.
string
Customer의 국가이며 ISO 3166-1 alpha-2 code입니다.
string
Customer의 street address입니다.
string
Customer의 city입니다.
string
Customer의 state 또는 province입니다.
string
Customer의 postal 또는 ZIP code입니다.
boolean
true로 설정하면 전체 이름 field를 비활성화합니다.
boolean
true로 설정하면 이름 field를 비활성화합니다.
boolean
true로 설정하면 성 field를 비활성화합니다.
boolean
true로 설정하면 email field를 비활성화합니다.
boolean
true로 설정하면 country field를 비활성화합니다.
boolean
true로 설정하면 address line field를 비활성화합니다.
boolean
true로 설정하면 city field를 비활성화합니다.
boolean
true로 설정하면 state field를 비활성화합니다.
boolean
true로 설정하면 ZIP code field를 비활성화합니다.
string
Payment currency입니다. 예: USD.
boolean
기본값:"true"
Currency selector를 표시하거나 숨깁니다.
number
청구 금액을 major currency unit으로 고정합니다. 예를 들어 $12.50의 경우 12.5입니다. Pay What You Want product에서만 작동하며 product의 minimum price보다 낮으면 무시됩니다.
boolean
기본값:"true"
Discounts section을 표시하거나 숨깁니다.
string
metadata_로 시작하는 모든 query parameter는 metadata로 checkout에 전달됩니다. 예: metadata_orderId=123.
disable flag는 true이고 일치하는 field에 값이 있을 때만 적용됩니다. 예를 들어 disableEmail가 포함된 email입니다. handler는 이러한 parameter를 static payment link에 전달합니다.
productId가 없으면 handler는 400 response를 반환합니다. 잘못된 query parameter나 account에 존재하지 않는 product도 400 response를 발생시킵니다.

Response Format

Static checkout은 checkout URL을 포함한 JSON response를 반환합니다:
  • POST request의 JSON body로 parameter를 전송합니다.
  • 일회성 payment와 recurring payment를 모두 지원합니다. handler는 product를 조회한 후 recurring product이면 subscription을 생성하고, 그렇지 않으면 일회성 payment를 생성합니다.
  • body에는 billing( street, city, state, country 및 zipcode 포함)와 customer가 필요합니다. 또한 선택적인 quantity가 포함된 product_id 또는 product_cart가 필요합니다. Subscription에는 product_id가 필요합니다.
  • handler는 metadata, allowed_payment_method_types, billing_currency, discount_codes(또는 deprecated된 discount_code), return_url, show_saved_payment_methods 및 tax_id도 전달합니다. Subscription의 경우 addons, on_demand 및 trial_period_days도 전달합니다. 다른 field는 무시합니다.
  • field 세부 정보는 다음을 참조하세요:
Dynamic Checkout은 deprecated된 POST /payments 및 POST /subscriptions endpoint를 호출합니다. 새 통합에는 Checkout Sessions를 사용하세요.

Response Format

Dynamic checkout은 payment link를 checkout URL로 포함한 JSON response를 반환합니다:
checkout session payload를 JSON body로 전송합니다. handler는 일회성 구매와 subscription의 전체 payment flow를 처리하는 checkout session을 생성하고 해당 checkout_url를 반환합니다. product_cart는 필수이며 product를 하나 이상 포함해야 합니다.각 checkout_url는 한 번만 작동하며 24시간 후 만료됩니다. 단, confirm: true를 전달하면 15분 후 만료됩니다. payment_method_id로 생성한 session은 checkout_url를 반환하지 않으므로 handler는 400을 응답합니다.자세한 내용과 지원되는 field의 전체 목록은 Checkout Sessions Integration Guide를 참조하세요.

Response Format

Checkout session은 checkout URL을 포함한 JSON response를 반환합니다:

Customer Portal Route Handler

Customer Portal Route Handler는 customer_id의 customer를 위한 Customer Portal session을 생성하고 request를 portal link로 redirect합니다. CustomerPortal는 checkoutHandler와 동일하게 bearerToken 및 environment option을 사용합니다. Dodo Payments가 session을 생성하지 못하면 handler는 500을 반환합니다.

Query Parameter

string
필수
Portal session의 customer ID입니다. 예: ?customer_id=cus_123.
boolean
true로 설정하면 customer에게 portal link가 포함된 email을 보냅니다.
customer_id가 없으면 400을 반환합니다. handler는 request를 authenticate하지 않으며 수신한 모든 customer_id에 대해 portal을 엽니다. 따라서 route를 자체 authentication 뒤에 배치하고 로그인한 사용자의 customer ID만 전달하세요.

Webhook Route Handler

webhook handler는 webhookKey로 전달된 webhook secret을 사용하여 각 request를 검증한 다음 event handler를 호출합니다.
webhook route보다 먼저 express.json()를 등록하세요. handler는 req.body에 대해 signature를 검증하므로 body가 parsed JSON이 아니면 모든 request를 거부합니다. 이 route에는 express.raw()를 사용하지 마세요.
  • Method: POST request만 지원됩니다. 다른 method는 405를 반환합니다.
  • Signature Verification: Standard Webhooks specification에 따라 webhookKey를 사용하여 webhook-id, webhook-timestamp 및 webhook-signature header를 검증합니다. 검증에 실패하면 401을 반환합니다.
  • Payload Validation: Zod로 검증합니다. payload가 유효하지 않으면 400을 반환합니다.
  • Error Handling:
    • 401: 유효하지 않은 signature
    • 400: 유효하지 않은 payload
    • 500: 검증 중 internal error
  • Event Routing: 모든 event에 대해 onPayload를 호출한 다음 event type에 해당하는 handler를 호출하고, 완료되면 200을 반환합니다. handler는 event handler가 발생시킨 error를 catch하지 않습니다.

지원되는 Webhook Event Handler

모든 handler는 선택 사항이며 async입니다. 각 event의 payload는 Webhook Event Guide를 참조하세요.

LLM용 Prompt

마지막 수정일 2026년 9월 26일