The Dodo Payments API library provides a convenient way to interact with the Dodo Payments REST API from your server-side JavaScript or TypeScript applications. This easy-to-use package lets you process payments, manage customers, and integrate payment functionality into your Node.js applications.
To install the Dodo Payments library, run:
npm install dodopayments
Here's how to create a payment using the Dodo Payments client:
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'
});
async function main() {
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);
}
main();
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',
});
async function main() {
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);
}
main();
When the API returns a non-success status code, the library throws a subclass of APIError
:
async function main() {
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 (connection issues, timeouts, rate limits, and internal server 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,
}
);
Requests time out after 1 minute by default:
// 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 list methods that return multiple items, you can use auto-pagination:
async function fetchAllPayments(params) {
const allPayments = [];
// Automatically fetches more pages as needed
for await (const paymentListResponse of client.payments.list()) {
allPayments.push(paymentListResponse);
}
return allPayments;
}
Or fetch a single page at a time:
let page = await client.payments.list();
for (const paymentListResponse of page.items) {
console.log(paymentListResponse);
}
// Manually navigate through pages
while (page.hasNextPage()) {
page = await page.getNextPage();
// Process items in the new page
}
You can access the raw HTTP response:
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'));
// Or get both parsed data and 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();
You can configure the HTTP agent to use a proxy:
import { HttpsProxyAgent } from 'https-proxy-agent';
const client = new DodoPayments({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
});
You can provide a custom fetch implementation:
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;
},
});
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 > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.