Integrate Dodo Payments into your TypeScript and Node.js applications with type safety and modern async/await support
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.
Initialize the client with your API key and start processing payments:
Copy
import DodoPayments from 'dodopayments';const client = new DodoPayments({ bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted environment: 'test_mode', // defaults to 'live_mode'});const checkoutSessionResponse = await client.checkoutSessions.create({ product_cart: [{ product_id: 'product_id', quantity: 1 }],});console.log(checkoutSessionResponse.session_id);
Always store your API keys securely using environment variables. Never commit them to version control or expose them in client-side code.
Events must have unique event_id values for idempotency. Duplicate IDs within the same request are rejected, and subsequent requests with existing IDs are ignored.
// Get a specific eventconst event = await client.usageEvents.retrieve('api_call_12345');// List events with filteringconst events = await client.usageEvents.list({ customer_id: 'cus_abc123', event_name: 'api_request', start: '2024-01-14T10:30:00Z', end: '2024-01-15T10:30:00Z'});
import DodoPayments from 'dodopayments';import * as undici from 'undici';const proxyAgent = new undici.ProxyAgent('http://localhost:8888');const client = new DodoPayments({ fetchOptions: { dispatcher: proxyAgent, },});
Control log verbosity using environment variables or client options:
Copy
// Via client optionconst client = new DodoPayments({ logLevel: 'debug', // Show all log messages});
Copy
# Via environment variableexport DODO_PAYMENTS_LOG=debug
Available log levels:
'debug' - Show debug messages, info, warnings, and errors
'info' - Show info messages, warnings, and errors
'warn' - Show warnings and errors (default)
'error' - Show only errors
'off' - Disable all logging
At the debug level, all HTTP requests and responses are logged, including headers and bodies. Some authentication headers are redacted, but sensitive data in bodies may still be visible.