Skip to main content
The TypeScript SDK provides convenient server-side access to the Dodo Payments REST API for TypeScript and JavaScript applications. It features comprehensive type definitions, error handling, retries, timeouts, and auto-pagination for seamless payment processing.

Installation

Install the SDK using your package manager of choice:

Quick Start

Initialize the client with your API key and start processing payments:
Always store your API keys securely using environment variables. Never commit them to version control or expose them in client-side code.

Core Features

TypeScript First

Full TypeScript support with comprehensive type definitions for all API endpoints

Auto-Pagination

Automatic pagination for list responses makes working with large datasets effortless

Error Handling

Built-in error types with detailed messages for different failure scenarios

Smart Retries

Configurable automatic retries with exponential backoff for transient errors

Configuration

Environment Variables

Set environment variables for secure configuration:
.env

Timeout Configuration

Configure request timeouts globally or per-request:

Retry Configuration

Configure automatic retry behavior:
The SDK automatically retries requests that fail due to network errors or server issues (5xx responses) with exponential backoff.

Common Operations

Create a Checkout Session

Generate a checkout session for collecting payment information:

Manage Customers

Create and retrieve customer information:

Handle Subscriptions

Create and manage recurring subscriptions:
POST /subscriptions (phương thức subscriptions.create của SDK) đã deprecated. Phương thức này vẫn hoạt động đối với các integration hiện có, nhưng các integration mới nên tạo subscription thông qua Checkout Session.
billing yêu cầu tối thiểu mã quốc gia ISO gồm hai chữ cái. customer là một union của { customer_id } (để liên kết customer hiện có) hoặc { email, name? } (để tạo customer mới). product_price được biểu thị theo mệnh giá thấp nhất của currency.

Thanh toán dựa trên mức sử dụng

Tiếp nhận sự kiện sử dụng

Theo dõi các event tùy chỉnh cho thanh toán dựa trên mức sử dụng:
Các event phải có giá trị event_id duy nhất để đảm bảo tính idempotency. Các ID trùng lặp trong cùng một request sẽ bị từ chối, còn các request tiếp theo có ID đã tồn tại sẽ bị bỏ qua.

Truy xuất sự kiện sử dụng

Lấy thông tin chi tiết về các event sử dụng:

Cấu hình proxy

Cấu hình các thiết lập proxy cho các runtime khác nhau:

Node.js (sử dụng undici)

Bun

Deno

Logging

Kiểm soát mức độ chi tiết của log bằng environment variables hoặc các tùy chọn của client:
Các mức log khả dụng:
  • 'debug' - Hiển thị các debug message, info, warning và error
  • 'info' - Hiển thị các info message, warning và error
  • 'warn' - Hiển thị warning và error (mặc định)
  • 'error' - Chỉ hiển thị error
  • 'off' - Tắt toàn bộ logging
Ở mức debug, tất cả HTTP request và response đều được ghi log, bao gồm header và body. Một số authentication header được ẩn, nhưng dữ liệu nhạy cảm trong body vẫn có thể hiển thị.

Migration từ Node.js SDK

Nếu bạn đang nâng cấp từ Node.js SDK cũ, TypeScript SDK cung cấp khả năng type safety và các tính năng được cải thiện:

View Migration Guide

Tìm hiểu cách migration từ Node.js SDK sang TypeScript SDK

Tự động phân trang

Các phương thức list trong DodoPayments API được phân trang. Bạn có thể sử dụng cú pháp for await … of để lặp qua các item trên tất cả các page:
Ngoài ra, bạn có thể yêu cầu từng page riêng lẻ:

Yêu cầu

Các runtime sau được hỗ trợ:
  • Trình duyệt web (Chrome, Firefox, Safari, Edge và các trình duyệt khác phiên bản mới nhất)
  • Node.js 20 LTS trở lên, với các phiên bản (non-EOL)
  • Deno v1.28.0 trở lên
  • Bun 1.0 trở lên
  • Cloudflare Workers
  • Vercel Edge Runtime
  • Jest 28 trở lên với environment "node"
  • Nitro v2.6 trở lên
TypeScript >= 4.9 được hỗ trợ.

Tài nguyên

GitHub Repository

Xem source code và đóng góp

API Reference

Tài liệu API đầy đủ

Discord Community

Nhận trợ giúp và kết nối với các developer

Report Issues

Báo cáo bug hoặc yêu cầu tính năng

Hỗ trợ

Cần trợ giúp với TypeScript SDK?

Đóng góp

Chúng tôi hoan nghênh các đóng góp! Xem hướng dẫn đóng góp để bắt đầu.
Lần sửa đổi cuối 17 tháng 8, 2026