The Dodo Payments Node API Library provides convenient access to the Dodo Payments REST API for server-side TypeScript or JavaScript applications. It offers a comprehensive set of tools for processing payments and managing transactions.
Install the Dodo Payments library using npm:
npm install dodopayments
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 payment = await client.payments.create({
billing: { city: 'city', country: 'AF', state: 'state', street: 'street', zipcode: 'zipcode' },
customer: { customer_id: 'customer_id' },
product_cart: [{ product_id: 'product_id', quantity: 0 }],
});
console.log(payment.payment_id);
The library includes TypeScript definitions for all request parameters and response fields:
import DodoPayments from 'dodopayments';
const client = new DodoPayments({
bearerToken: process.env['DODO_PAYMENTS_API_KEY'],
environment: 'test_mode',
});
const params: DodoPayments.PaymentCreateParams = {
billing: { city: 'city', country: 'AF', state: 'state', street: 'street', zipcode: 'zipcode' },
customer: { customer_id: 'customer_id' },
product_cart: [{ product_id: 'product_id', quantity: 0 }],
};
const payment: DodoPayments.PaymentCreateResponse = await client.payments.create(params);
The library throws appropriate error types based on API responses:
const payment = await client.payments
.create({
billing: { city: 'city', country: 'AF', state: 'state', street: 'street', zipcode: 'zipcode' },
customer: { customer_id: 'customer_id' },
product_cart: [{ product_id: 'product_id', quantity: 0 }],
})
.catch(async (err) => {
if (err instanceof DodoPayments.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
Status Code | Error Type |
---|---|
400 | BadRequestError |
401 | AuthenticationError |
403 | PermissionDeniedError |
404 | NotFoundError |
422 | UnprocessableEntityError |
429 | RateLimitError |
>=500 | InternalServerError |
N/A | APIConnectionError |
The library automatically retries certain errors:
// Configure the default for all requests:
const client = new DodoPayments({
maxRetries: 0, // default is 2
});
// Or, configure per-request:
await client.payments.create(
{
billing: { city: 'city', country: 'AF', state: 'state', street: 'street', zipcode: 'zipcode' },
customer: { customer_id: 'customer_id' },
product_cart: [{ product_id: 'product_id', quantity: 0 }]
},
{
maxRetries: 5,
}
);
Configure request timeouts:
// Configure the default for all requests:
const client = new DodoPayments({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});
// Override per-request:
await client.payments.create(
{
billing: { city: 'city', country: 'AF', state: 'state', street: 'street', zipcode: 'zipcode' },
customer: { customer_id: 'customer_id' },
product_cart: [{ product_id: 'product_id', quantity: 0 }]
},
{
timeout: 5 * 1000,
}
);
For paginated endpoints, you can use auto-pagination with modern JavaScript:
async function fetchAllPaymentListResponses(params) {
const allPaymentListResponses = [];
// Automatically fetches more pages as needed
for await (const paymentListResponse of client.payments.list()) {
allPaymentListResponses.push(paymentListResponse);
}
return allPaymentListResponses;
}
Or handle pagination manually:
let page = await client.payments.list();
for (const paymentListResponse of page.items) {
console.log(paymentListResponse);
}
// Convenience methods for manual pagination
while (page.hasNextPage()) {
page = await page.getNextPage();
// Process page...
}
const client = new DodoPayments();
// Get the raw Response object
const response = await client.payments
.create({
billing: { city: 'city', country: 'AF', state: 'state', street: 'street', zipcode: 'zipcode' },
customer: { customer_id: 'customer_id' },
product_cart: [{ product_id: 'product_id', quantity: 0 }],
})
.asResponse();
console.log(response.headers.get('X-My-Header'));
// Get both the parsed data and the raw response
const { data: payment, response: raw } = await client.payments
.create({
billing: { city: 'city', country: 'AF', state: 'state', street: 'street', zipcode: 'zipcode' },
customer: { customer_id: 'customer_id' },
product_cart: [{ product_id: 'product_id', quantity: 0 }],
})
.withResponse();
For proxy support or other custom networking needs:
import { HttpsProxyAgent } from 'https-proxy-agent';
// Configure a proxy for all requests
const client = new DodoPayments({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
});
Implement request/response logging or other middleware:
import { fetch } from 'undici';
import DodoPayments from 'dodopayments';
const client = new DodoPayments({
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
console.log('About to make a request', url, init);
const response = await fetch(url, init);
console.log('Got response', response);
return response;
},
});
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "dodopayments" '{"command":"npx","args":["-y","dodopayments"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"dodopayments": {
"command": "npx",
"args": [
"-y",
"dodopayments"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"dodopayments": {
"command": "npx",
"args": [
"-y",
"dodopayments"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect