Skip to main content
@dodopayments/convex component는 Convex 백엔드에 Dodo Payments를 추가합니다. checkout session을 생성하는 checkout function, 로그인한 사용자의 Customer Portal을 여는 customerPortal function, 그리고 Convex HTTP action에서 webhook을 검증하는 createDodoWebhookHandler를 제공합니다. Convex 1.26 이상이 필요합니다.

Checkout Function

Convex action에서 checkout session을 생성합니다.

Customer Portal

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

Webhooks

Dodo Payments webhook event를 수신하고 처리합니다.

설치

1

Install the Package

프로젝트 루트에서 다음 명령을 실행하세요:
2

Add Component to Convex Config

Convex configuration에 Dodo Payments component를 추가하세요:
convex.config.ts를 수정한 후 npx convex dev를 한 번 실행하여 type을 생성하세요.
3

Set Up Environment Variables

Convex dashboard의 Settings → Environment Variables에서 environment variable을 설정하세요. dashboard를 열려면 다음을 실행하세요:
다음 environment variable을 추가하세요:
  • DODO_PAYMENTS_API_KEY: Dodo Payments API key입니다. Dodo Payments dashboard의 Developer → API Keys에서 확인할 수 있습니다.
  • DODO_PAYMENTS_ENVIRONMENT: test_mode 또는 live_mode입니다.
  • DODO_PAYMENTS_WEBHOOK_SECRET: webhook secret입니다. Developer → Webhooks의 Dodo Payments dashboard에서 확인할 수 있습니다. webhook 처리에 필요합니다. webhook handler는 이 정확한 variable name을 읽습니다.
Secret은 Convex environment variable로 저장하세요. Convex backend function은 .env file을 읽지 않습니다. Secret을 version control에 절대 commit하지 마세요.

Component 설정 예시

1

Create Internal Query

auth ID로 database에서 customer를 찾는 internal query를 생성하세요. 다음 단계의 identify function은 이 query를 사용하여 로그인한 사용자의 Dodo Payments customer ID를 customer portal에서 가져옵니다.
component는 schema를 정의하지 않습니다. 이 query를 사용하기 전에 convex/schema.ts에서 by_auth_id index가 있는 customers table을 정의하거나, 기존 schema에 맞게 query를 변경하세요.
2

Configure DodoPayments Component

Client를 생성하세요. identify는 로그인한 Convex user를 Dodo Payments customer ID에 매핑합니다. 로그인한 user가 없거나 일치하는 customer가 없으면 null를 반환합니다.
필요한 function을 추가하세요:
이 function을 사용하여 Convex app에 Dodo Payments checkout을 추가하세요. component의 checkout payload validator가 허용하는 field로 checkout session을 생성합니다.

Checkout Function

Convex component는 모든 payment에 권장되는 checkout flow인 checkout session을 생성합니다. session에는 product cart, customer details 및 checkout option이 포함됩니다.

사용법

Convex action에서 checkout session field를 payload에 전달하여 checkout를 호출하세요:
checkout는 identify를 호출하지 않습니다. 기존 customer를 연결하려면 payload에 customer: { customer_id }를 전달하세요. 자세한 내용과 지원되는 field의 전체 목록은 Checkout Sessions을 참조하세요. payment_method_id로 생성한 session은 checkout URL을 반환하지 않으므로 checkout는 이에 대해 error를 throw합니다.

Response Format

checkout function은 checkout URL이 포함된 object를 반환합니다:

Customer Portal Function

customer portal function은 로그인한 사용자의 Customer Portal URL을 반환합니다.

사용법

portal_url field가 포함된 object를 반환합니다.

Parameters

boolean
기본값:"false"
true로 설정하면 Dodo Payments는 portal link를 customer에게 email로도 전송합니다.
customerPortal는 DodoPayments setup의 identify function에서 customer를 가져옵니다. 이 function은 customer의 dodoCustomerId를 반환해야 합니다. identify가 null를 반환하면 customerPortal는 User is not authenticated. error를 throw합니다.

Webhook Handler

createDodoWebhookHandler는 code를 실행하기 전에 각 request를 검증합니다:
  • Method: method: "POST"로 route를 등록하세요. 다른 method의 request는 handler에 도달하지 않습니다.
  • Signature Verification: DODO_PAYMENTS_WEBHOOK_SECRET environment variable로 Standard Webhooks signature를 검증합니다. 검증에 실패하면 400을 반환합니다.
  • Payload Validation: Zod로 validation합니다. 유효하지 않은 payload에는 400을 반환합니다.
  • Error Handling:
    • 400: 유효하지 않은 signature, 유효하지 않은 payload 또는 handler 중 하나가 throw한 error
    • 200: 모든 handler가 완료됨
    • DODO_PAYMENTS_WEBHOOK_SECRET가 설정되지 않은 경우 handler가 error를 throw하고 request가 실패합니다.
  • Event Routing: 모든 event에 대해 onPayload를 호출한 다음 event type에 해당하는 handler를 호출합니다.

Supported Webhook Event Handlers

각 handler는 Convex ActionCtx와 해당 event type에 대해 검증된 payload를 받습니다:

Frontend 사용법

convex/react의 useAction hook을 사용하여 React component에서 checkout 및 portal action을 호출하세요.

LLM용 Prompt

이 prompt를 AI coding assistant에 복사하여 project에 component를 추가하도록 하세요. agent에 Dodo Payments docs와 skills도 제공하려면 Agent Plugin을 설치하세요.
마지막 수정일 2026년 9월 26일