### Install and Run Local Development Server Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/cloudflare-worker/README.md Use these commands to install dependencies and start the local development server for the Cloudflare Worker. ```bash npm install npm run dev ``` -------------------------------- ### Add and Run an Example Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Create a new TypeScript file in the examples directory and run it using the provided command. Ensure the file is executable. ```ts // add an example to examples/.ts #!/usr/bin/env -S npm run tsn -T … ``` ```sh $ chmod +x examples/.ts # run the example against your api $ yarn tsn -T examples/.ts ``` -------------------------------- ### Install Dependencies and Build Project Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Run these commands to install all necessary dependencies and build the project's output files. ```sh $ yarn $ yarn build ``` -------------------------------- ### Install from Git Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Use this command to install the repository directly from its Git URL. ```sh $ npm install git+ssh://git@github.com:dodopayments/dodopayments-typescript.git ``` -------------------------------- ### Start Mock Server Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Run this script to set up a mock server, which is often required for running tests against the OpenAPI spec. ```sh $ ./scripts/mock ``` -------------------------------- ### Install dodopayments npm package Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Install the library using npm. This is the first step to using the Dodo Payments API in your project. ```sh npm install dodopayments ``` -------------------------------- ### Bun package.json Dependencies Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md Install the `@types/bun` package for Bun environments. Ensure the version is `1.2.0` or higher. ```json { "devDependencies": { "@types/bun": ">= 1.2.0" } } ``` -------------------------------- ### MCP Server Configuration JSON Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/README.md Example configuration JSON for clients that use a configuration file to set up MCP servers. This includes command, arguments, and environment variables. ```json { "mcpServers": { "dodopayments_api": { "command": "npx", "args": ["-y", "dodopayments-mcp"], "env": { "DODO_PAYMENTS_API_KEY": "My Bearer Token", "DODO_PAYMENTS_WEBHOOK_KEY": "My Webhook Key", "DODO_PAYMENTS_ENVIRONMENT": "live_mode" } } } } ``` -------------------------------- ### Install MCP Server via npx Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/README.md Run the MCP Server directly using npx. Ensure environment variables for API key, webhook key, and environment are set. ```sh export DODO_PAYMENTS_API_KEY="My Bearer Token" export DODO_PAYMENTS_WEBHOOK_KEY="My Webhook Key" export DODO_PAYMENTS_ENVIRONMENT="live_mode" npx -y dodopayments-mcp@latest ``` -------------------------------- ### Configure Node.js Proxy with Undici Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Set up a proxy for Node.js requests by providing an `undici.ProxyAgent` instance within `fetchOptions.dispatcher`. Ensure `undici` is installed. ```typescript import DodoPayments from 'dodopayments'; import * as undici from 'undici'; const proxyAgent = new undici.ProxyAgent('http://localhost:8888'); const client = new DodoPayments({ fetchOptions: { dispatcher: proxyAgent, }, }); ``` -------------------------------- ### Install MCP Server for Claude Code Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/README.md Command to add the MCP server for Claude Code. Environment variables are set directly in the command. Configuration is stored in `.claude.json`. ```sh claude mcp add dodopayments_mcp_api --env DODO_PAYMENTS_API_KEY="My Bearer Token" DODO_PAYMENTS_WEBHOOK_KEY="My Bearer Token" -- npx -y dodopayments-mcp ``` -------------------------------- ### Claude Desktop MCP Server Configuration Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/cloudflare-worker/static/home.md Configure Claude Desktop to connect to a remote MCP server. Ensure Node.js is installed and the mcp-remote package is available. ```json { "mcpServers": { "dodopayments-mcp": { "command": "npx", "args": ["-y", "mcp-remote@latest", "{{cloudflareWorkerUrl}}"] } } } ``` -------------------------------- ### Node.js package.json Dependencies Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md Install the appropriate `@types/node` package for Node.js environments to resolve type errors. Ensure the version is 20 or higher. ```json { "devDependencies": { "@types/node": ">= 20" } } ``` -------------------------------- ### Initialize DodoPayments client and create checkout session Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Instantiate the DodoPayments client with an API key and environment. Then, create a checkout session by providing product details. The session ID is logged to the console. ```js 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: 'pdt_example', quantity: 1 }], }); console.log(checkoutSessionResponse.session_id); ``` -------------------------------- ### Configure Deno Proxy Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Set up a proxy for Deno by creating a `Deno.HttpClient` with proxy configuration and passing it via `fetchOptions.client`. Use `npm:dodopayments` for Deno compatibility. ```typescript import DodoPayments from 'npm:dodopayments'; const httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } }); const client = new DodoPayments({ fetchOptions: { client: httpClient, }, }); ``` -------------------------------- ### Cloudflare Workers package.json Dependencies Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md Install the `@cloudflare/workers-types` package for Cloudflare Workers environments. Use a version greater than or equal to `0.20221111.0`. ```json { "devDependencies": { "@cloudflare/workers-types": ">= 0.20221111.0" } } ``` -------------------------------- ### create Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a new discount. ```APIDOC ## POST /discounts ### Description Creates a new discount. ### Method POST ### Endpoint /discounts ### Parameters #### Request Body - **params** (object) - Required - Discount creation parameters. ### Response #### Success Response (200) - **discount** (Discount) - The created discount object. ``` -------------------------------- ### LicenseKeyInstances API Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Methods for managing license key instances. ```APIDOC ## GET /license_key_instances ### Description Retrieves a paginated list of license key instances. ### Method GET ### Endpoint /license_key_instances ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **LicenseKeyInstancesDefaultPageNumberPagination** - The response object containing a list of license key instances. ``` ```APIDOC ## GET /license_key_instances/{id} ### Description Retrieves a specific license key instance by its ID. ### Method GET ### Endpoint /license_key_instances/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the license key instance to retrieve. ### Response #### Success Response (200) - **LicenseKeyInstance** - The retrieved license key instance object. ``` ```APIDOC ## PATCH /license_key_instances/{id} ### Description Updates a specific license key instance by its ID. ### Method PATCH ### Endpoint /license_key_instances/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the license key instance to update. #### Request Body - **params** (object) - Required - An object containing the fields to update. ``` -------------------------------- ### Configure Fetch Options on Client Instantiation Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Provide custom `fetchOptions` during client initialization to set default request configurations. These can be overridden by request-specific options. ```typescript import DodoPayments from 'dodopayments'; const client = new DodoPayments({ fetchOptions: { // `RequestInit` options }, }); ``` -------------------------------- ### Configure Claude Desktop to Connect to Local MCP Server Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/cloudflare-worker/README.md Replace your Claude Desktop configuration with this JSON to enable connection to your local MCP server via a proxy. This allows Claude to interact with your MCP server over HTTP. ```json { "mcpServers": { "dodopayments_api": { "command": "npx", "args": ["mcp-remote", "http://localhost:8787/sse"] } } } ``` -------------------------------- ### Configure Bun Proxy Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Configure a proxy for Bun environments by setting the `fetchOptions.proxy` property to the proxy URL. This is a Bun-specific option. ```typescript import DodoPayments from 'dodopayments'; const client = new DodoPayments({ fetchOptions: { proxy: 'http://localhost:8888', }, }); ``` -------------------------------- ### Pass Custom Fetch Client to DodoPayments Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Instantiate `DodoPayments` with a custom `fetch` implementation by passing it in the constructor options. This avoids modifying the global scope. ```typescript import DodoPayments from 'dodopayments'; import fetch from 'my-fetch'; const client = new DodoPayments({ fetch }); ``` -------------------------------- ### Create Product Collection Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a new product collection with the provided parameters. ```APIDOC ## POST /product-collections ### Description Creates a new product collection. ### Method POST ### Endpoint /product-collections ### Parameters #### Request Body - **params** (object) - Required - Parameters for creating the product collection. ### Response #### Success Response (200) - **ProductCollection** - The newly created product collection object. ``` -------------------------------- ### Run Tests Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Execute the project's test suite using the yarn test command. ```sh $ yarn run test ``` -------------------------------- ### Create Webhook Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a new webhook configuration. Specify the URL to receive events and the events to subscribe to. ```APIDOC ## POST /webhooks ### Description Creates a new webhook configuration. Specify the URL to receive events and the events to subscribe to. ### Method POST ### Endpoint /webhooks ### Parameters #### Request Body - **url** (string) - Required - The URL to send webhook events to. - **description** (string) - Optional - A description for the webhook. - **events** (array) - Optional - A list of webhook event types to subscribe to. If not provided, all events will be sent. ### Request Example ```json { "url": "https://example.com/webhook", "description": "My first webhook", "events": [ "payment.succeeded", "payment.failed" ] } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the webhook. - **url** (string) - The URL of the webhook. - **description** (string) - The description of the webhook. - **events** (array) - The list of subscribed event types. - **created_at** (string) - The timestamp when the webhook was created. - **updated_at** (string) - The timestamp when the webhook was last updated. ``` -------------------------------- ### Create License Key Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a new license key with the provided parameters. ```APIDOC ## POST /license_keys ### Description Creates a new license key. ### Method POST ### Endpoint /license_keys ### Parameters #### Request Body - **params** (object) - Required - The parameters for creating the new license key. ### Response #### Success Response (200) - **LicenseKey** (object) - The newly created license key details. ``` -------------------------------- ### Create License Key Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a new license key with the provided parameters. Returns the created LicenseKey object. ```typescript client.licenseKeys.create({ ...params }) ``` -------------------------------- ### Activate License Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Activates a license with the provided parameters. ```APIDOC ## POST /licenses/activate ### Description Activates a license. ### Method POST ### Endpoint /licenses/activate ### Parameters #### Request Body - **params** (object) - Required - Parameters for license activation. ### Response #### Success Response (200) - **LicenseActivateResponse** (object) - The response object after license activation. ``` -------------------------------- ### Create Subscription Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a new subscription with the provided details. Returns the details of the newly created subscription. ```APIDOC ## POST /subscriptions ### Description Creates a new subscription with the provided details. Returns the details of the newly created subscription. ### Method POST ### Endpoint /subscriptions ### Parameters #### Request Body - **params** (object) - Required - Subscription creation parameters. ### Response #### Success Response (200) - **SubscriptionCreateResponse** (object) - The response object containing details of the created subscription. ``` -------------------------------- ### List License Keys Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Retrieves a paginated list of license keys with optional parameters for filtering and pagination. ```typescript client.licenseKeys.list({ ...params }) ``` -------------------------------- ### Connect MCP Inspector to Remote Server Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/cloudflare-worker/README.md Command to launch the MCP inspector to connect to a deployed remote MCP server. ```bash npx @modelcontextprotocol/inspector@latest ``` -------------------------------- ### Activate License Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Activates a license with the provided parameters. Returns LicenseActivateResponse. ```typescript client.licenses.activate({ ...params }) ``` -------------------------------- ### Simplify Manual Pagination Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md The interface for manual pagination has been simplified. Use 'nextPageRequestOptions()' instead of 'nextPageParams()' and 'nextPageInfo()'. ```typescript // Before page.nextPageParams(); page.nextPageInfo(); // Required manually handling { url } | { params } type // After page.nextPageRequestOptions(); ``` -------------------------------- ### Products API Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Methods for managing products, including listing, creating, retrieving, updating, archiving, and unarchiving. ```APIDOC ## GET /products ### Description Retrieves a list of products with pagination support. ### Method GET ### Endpoint /products ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **ProductListResponsesDefaultPageNumberPagination** (object) - The list of products. ### Response Example { "example": "ProductListResponsesDefaultPageNumberPagination" } ``` ```APIDOC ## POST /products ### Description Creates a new product. ### Method POST ### Endpoint /products ### Parameters #### Request Body - **params** (object) - Required - Product details for creation. ### Response #### Success Response (200) - **Product** (object) - The newly created product. ### Response Example { "example": "Product" } ``` ```APIDOC ## GET /products/{id} ### Description Retrieves a specific product by its ID. ### Method GET ### Endpoint /products/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the product to retrieve. ### Response #### Success Response (200) - **Product** (object) - The requested product. ### Response Example { "example": "Product" } ``` ```APIDOC ## PATCH /products/{id} ### Description Updates an existing product. ### Method PATCH ### Endpoint /products/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the product to update. #### Request Body - **params** (object) - Required - The updated product details. ### Response #### Success Response (200) - **void** - Indicates successful update. ### Response Example { "example": "void" } ``` ```APIDOC ## DELETE /products/{id} ### Description Archives a product by its ID. ### Method DELETE ### Endpoint /products/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the product to archive. ### Response #### Success Response (200) - **void** - Indicates successful archiving. ### Response Example { "example": "void" } ``` ```APIDOC ## POST /products/{id}/unarchive ### Description Unarchives a product by its ID. ### Method POST ### Endpoint /products/{id}/unarchive ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the product to unarchive. ### Response #### Success Response (200) - **void** - Indicates successful unarchiving. ### Response Example { "example": "void" } ``` ```APIDOC ## PUT /products/{id}/files ### Description Updates the files associated with a product. ### Method PUT ### Endpoint /products/{id}/files ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the product whose files are to be updated. #### Request Body - **params** (object) - Required - The files to update. ### Response #### Success Response (200) - **ProductUpdateFilesResponse** (object) - The response containing updated file information. ### Response Example { "example": "ProductUpdateFilesResponse" } ``` -------------------------------- ### List License Keys Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Retrieves a paginated list of license keys with optional filtering parameters. ```APIDOC ## GET /license_keys ### Description Retrieves a list of license keys. ### Method GET ### Endpoint /license_keys ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **LicenseKeysDefaultPageNumberPagination** (object) - A paginated list of license keys. ``` -------------------------------- ### Publish NPM Package Manually Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Manually release a package by running the bin/publish-npm script. Ensure the NPM_TOKEN environment variable is set. ```sh bin/publish-npm ``` -------------------------------- ### Link Local Repository with pnpm Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Clone the repository and use pnpm to link it globally to another package. This is an alternative to yarn for local development. ```sh # With pnpm $ pnpm link --global $ cd ../my-package $ pnpm link --global dodopayments ``` -------------------------------- ### Link Local Repository with Yarn Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Clone the repository and use yarn to link it locally to another package. This is useful for development and testing changes. ```sh # Clone $ git clone https://www.github.com/dodopayments/dodopayments-typescript $ cd dodopayments-typescript # With yarn $ yarn link $ cd ../my-package $ yarn link dodopayments ``` -------------------------------- ### Replace APIClient Import Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md The 'APIClient' base class has been removed. Import the main 'DodoPayments' client class instead. ```typescript // Before import { APIClient } from 'dodopayments/core'; // After import { DodoPayments } from 'dodopayments'; ``` -------------------------------- ### List Webhooks Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Retrieves a paginated list of webhook configurations. Supports filtering and sorting. ```APIDOC ## GET /webhooks ### Description Retrieves a paginated list of webhook configurations. Supports filtering and sorting. ### Method GET ### Endpoint /webhooks ### Parameters #### Query Parameters - **limit** (number) - Optional - The maximum number of webhooks to return. - **after** (string) - Optional - The cursor for the next page of results. - **before** (string) - Optional - The cursor for the previous page of results. - **sort** (string) - Optional - The field to sort by. Possible values: `created_at`, `updated_at`. - **order** (string) - Optional - The order of sorting. Possible values: `asc`, `desc`. ### Response #### Success Response (200) - **data** (array) - A list of webhook configurations. - **meta** (object) - Pagination metadata. - **has_more** (boolean) - Indicates if there are more results. - **next_cursor** (string) - The cursor for the next page. - **prev_cursor** (string) - The cursor for the previous page. ``` -------------------------------- ### list Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Retrieves a paginated list of discounts with optional filtering parameters. ```APIDOC ## GET /discounts ### Description Retrieves a paginated list of discounts with optional filtering parameters. ### Method GET ### Endpoint /discounts ### Parameters #### Query Parameters - **params** (object) - Optional - Filtering and pagination parameters. ### Response #### Success Response (200) - **data** (Discount[]) - A list of discounts. - **pagination** (DiscountsDefaultPageNumberPagination) - Pagination details. ``` -------------------------------- ### Configure Claude Desktop MCP Server Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/cloudflare-worker/README.md JSON configuration for Claude Desktop to connect to a remote MCP server deployed on Cloudflare Workers. ```json { "mcpServers": { "dodopayments_api": { "command": "npx", "args": ["mcp-remote", "https://worker-name.account-name.workers.dev/sse"] } } } ``` -------------------------------- ### Product Images API Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Methods for managing product images. ```APIDOC ## PUT /products/{id}/images ### Description Updates the images for a specific product. ### Method PUT ### Endpoint /products/{id}/images ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the product to update images for. #### Request Body - **params** (object) - Required - The image data to update. ### Response #### Success Response (200) - **ImageUpdateResponse** (object) - The response indicating the status of the image update. ### Response Example { "example": "ImageUpdateResponse" } ``` -------------------------------- ### Replace httpAgent with fetchOptions for Proxy Support Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md The httpAgent client option is removed. Use the platform-specific fetchOptions property with a dispatcher for proxy support. This change is due to httpAgent's reliance on node:http agents, which are not supported by built-in fetch implementations. ```typescript import DodoPayments from 'dodopayments'; import http from 'http'; import { HttpsProxyAgent } from 'https-proxy-agent'; // Configure the default for all requests: const client = new DodoPayments({ httpAgent: new HttpsProxyAgent(process.env.PROXY_URL), }); ``` ```typescript import DodoPayments from 'dodopayments'; import * as undici from 'undici'; const proxyAgent = new undici.ProxyAgent(process.env.PROXY_URL); const client = new DodoPayments({ fetchOptions: { dispatcher: proxyAgent, }, }); ``` -------------------------------- ### Create Cloudflare KV Namespace Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/cloudflare-worker/README.md Command to create a new KV namespace for the remote MCP server. Ensure the ID is added to wrangler.jsonc. ```bash npx wrangler@latest kv namespace create remote-mcp-server-oauth-kv ``` -------------------------------- ### Usage Events Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Ingest, list, and retrieve usage events. ```APIDOC ## POST /events/ingest ### Description Ingests a new usage event. ### Method POST ### Endpoint /events/ingest ### Parameters #### Request Body - **params** (object) - Required - An object containing the event data. ### Response #### Success Response (200) - **UsageEventIngestResponse** (object) - The response from ingesting the event. ``` ```APIDOC ## GET /events ### Description Lists all usage events. ### Method GET ### Endpoint /events ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **EventsDefaultPageNumberPagination** (object) - A paginated list of usage events. ``` ```APIDOC ## GET /events/{event_id} ### Description Retrieves a specific usage event by its ID. ### Method GET ### Endpoint /events/{event_id} ### Parameters #### Path Parameters - **event_id** (string) - Required - The ID of the event. ### Response #### Success Response (200) - **Event** (object) - The usage event details. ``` -------------------------------- ### Manually Paginate Through Payment List Responses Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Demonstrates fetching a single page of results and manually navigating to subsequent pages using `hasNextPage` and `getNextPage`. ```typescript let page = await client.payments.list(); for (const paymentListResponse of page.items) { console.log(paymentListResponse); } // Convenience methods are provided for manually paginating: while (page.hasNextPage()) { page = await page.getNextPage(); // ... } ``` -------------------------------- ### Configure Custom Logger with Pino Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Provide a custom logger instance, such as one from the `pino` library, to the client constructor. The `logLevel` option still determines which messages are emitted. ```typescript import DodoPayments from 'dodopayments'; import pino from 'pino'; const logger = pino(); const client = new DodoPayments({ logger: logger.child({ name: 'DodoPayments' }), logLevel: 'debug', // Send all messages to pino, allowing it to filter }); ``` -------------------------------- ### List Product Collections Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Retrieves a list of product collections with optional pagination parameters. ```APIDOC ## GET /product-collections ### Description Retrieves a paginated list of product collections. ### Method GET ### Endpoint /product-collections ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **ProductCollectionListResponsesDefaultPageNumberPagination** - The response contains a list of product collections. ``` -------------------------------- ### Polyfill Global Fetch Client Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Replace the default global `fetch` function with a custom implementation. Ensure the custom fetch is imported and assigned to `globalThis.fetch`. ```typescript import fetch from 'my-fetch'; globalThis.fetch = fetch; ``` -------------------------------- ### Configure Client Logging Level Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Set the `logLevel` option during client initialization to control the verbosity of log messages. This overrides the `DODO_PAYMENTS_LOG` environment variable. ```typescript import DodoPayments from 'dodopayments'; const client = new DodoPayments({ logLevel: 'debug', // Show all log messages }); ``` -------------------------------- ### Update Imports from 'dodopayments/src' Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md The 'dodopayments/src' directory is no longer intended for runtime imports. Replace any imports from 'dodopayments/src/*' with 'dodopayments/*'. ```typescript // Before import DodoPayments from 'dodopayments/src'; // After import DodoPayments from 'dodopayments'; ``` -------------------------------- ### Meters Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md List, create, retrieve, and archive meters. ```APIDOC ## GET /meters ### Description Lists all meters. ### Method GET ### Endpoint /meters ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **MetersDefaultPageNumberPagination** (object) - A paginated list of meters. ``` ```APIDOC ## POST /meters ### Description Creates a new meter. ### Method POST ### Endpoint /meters ### Parameters #### Request Body - **params** (object) - Required - An object containing the meter details. ### Response #### Success Response (200) - **Meter** (object) - The created meter details. ``` ```APIDOC ## GET /meters/{id} ### Description Retrieves a specific meter by its ID. ### Method GET ### Endpoint /meters/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the meter. ### Response #### Success Response (200) - **Meter** (object) - The meter details. ``` ```APIDOC ## DELETE /meters/{id} ### Description Archives a specific meter by its ID. ### Method DELETE ### Endpoint /meters/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the meter. ### Response #### Success Response (200) - **void** ``` ```APIDOC ## POST /meters/{id}/unarchive ### Description Unarchives a specific meter by its ID. ### Method POST ### Endpoint /meters/{id}/unarchive ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the meter. ### Response #### Success Response (200) - **void** ``` -------------------------------- ### Product Short Links API Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Methods for managing short links associated with products. ```APIDOC ## GET /products/short_links ### Description Retrieves a list of short links for products. ### Method GET ### Endpoint /products/short_links ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **ShortLinkListResponsesDefaultPageNumberPagination** (object) - The list of short links. ### Response Example { "example": "ShortLinkListResponsesDefaultPageNumberPagination" } ``` ```APIDOC ## POST /products/{id}/short_links ### Description Creates a short link for a specific product. ### Method POST ### Endpoint /products/{id}/short_links ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the product to create a short link for. #### Request Body - **params** (object) - Required - The details for the short link. ### Response #### Success Response (200) - **ShortLinkCreateResponse** (object) - The response containing the created short link details. ### Response Example { "example": "ShortLinkCreateResponse" } ``` -------------------------------- ### Preview Subscription Plan Change Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Previews the impact of changing a subscription's plan without actually applying the change. ```APIDOC ## POST /subscriptions/{subscription_id}/change-plan/preview ### Description Previews the impact of changing a subscription's plan without actually applying the change. ### Method POST ### Endpoint /subscriptions/{subscription_id}/change-plan/preview ### Parameters #### Path Parameters - **subscriptionID** (string) - Required - The ID of the subscription to preview the plan change for. #### Request Body - **params** (object) - Required - Parameters for the plan change preview. ### Response #### Success Response (200) - **SubscriptionPreviewChangePlanResponse** (object) - The response object containing the preview details. ``` -------------------------------- ### List Credit Entitlements Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Lists all credit entitlements. ```APIDOC ## GET /credit-entitlements ### Description Lists all credit entitlements. ### Method GET ### Endpoint /credit-entitlements ### Parameters #### Query Parameters - **params** (object) - Required - Parameters for pagination and filtering. ``` -------------------------------- ### Create Credit Entitlement Balance Ledger Entry Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a ledger entry for a customer's balance within a credit entitlement. ```APIDOC ## POST /credit-entitlements/{credit_entitlement_id}/balances/{customer_id}/ledger-entries ### Description Creates a ledger entry for a customer's balance within a credit entitlement. ### Method POST ### Endpoint /credit-entitlements/{credit_entitlement_id}/balances/{customer_id}/ledger-entries ### Parameters #### Path Parameters - **credit_entitlement_id** (string) - Required - The ID of the credit entitlement. - **customer_id** (string) - Required - The ID of the customer. #### Request Body - **params** (object) - Required - Details for the ledger entry. ``` -------------------------------- ### Create Entitlement Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a new entitlement. Accepts parameters to define the entitlement's properties. ```APIDOC ## POST /entitlements ### Description Creates a new entitlement. ### Method POST ### Endpoint /entitlements ### Parameters #### Request Body - **params** (object) - Required - Parameters to define the entitlement's properties. ``` -------------------------------- ### Lint Code Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Run the lint command to check for code style issues and potential errors. ```sh $ yarn lint ``` -------------------------------- ### Iterate Through All Paginated Payment List Responses Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Use the `for await...of` loop to automatically fetch and process all items across paginated API responses. ```typescript 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; } ``` -------------------------------- ### Addons API Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Provides methods to manage addons, including listing, creating, retrieving, updating, and updating images. ```APIDOC ## GET /addons ### Description Retrieves a paginated list of addons. ### Method GET ### Endpoint /addons ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **AddonResponsesDefaultPageNumberPagination** - The response contains a list of addons. ## POST /addons ### Description Creates a new addon. ### Method POST ### Endpoint /addons ### Parameters #### Request Body - **params** (object) - Required - Parameters for the new addon. ### Response #### Success Response (200) - **AddonResponse** - The newly created addon. ## GET /addons/{id} ### Description Retrieves a specific addon by its ID. ### Method GET ### Endpoint /addons/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the addon to retrieve. ### Response #### Success Response (200) - **AddonResponse** - The requested addon. ## PATCH /addons/{id} ### Description Updates an existing addon by its ID. ### Method PATCH ### Endpoint /addons/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the addon to update. #### Request Body - **params** (object) - Required - The updated fields for the addon. ### Response #### Success Response (200) - **AddonResponse** - The updated addon. ## PUT /addons/{id}/images ### Description Updates the images for a specific addon by its ID. ### Method PUT ### Endpoint /addons/{id}/images ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the addon whose images are to be updated. ### Response #### Success Response (200) - **AddonUpdateImagesResponse** - The response indicates the success of the image update operation. ``` -------------------------------- ### Access Resource Classes Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md Resource classes like CheckoutSessions are no longer directly exportable from the root. Access them via the main client class or import them directly from their respective files. ```typescript // Before const { CheckoutSessions } = require('dodopayments'); // After const { DodoPayments } = require('dodopayments'); DodoPayments.CheckoutSessions; // or import directly from dodopayments/resources/checkout-sessions ``` -------------------------------- ### Update Named Path Parameters in Dodo Payments SDK Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md Methods with multiple path parameters now use named arguments for clarity. Ensure you pass the last parameter positionally and others as named arguments. ```typescript // Before client.parents.children.retrieve('p_123', 'c_456'); // After client.parents.children.retrieve('c_456', { parent_id: 'p_123' }); ``` -------------------------------- ### listSupportedCountries Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Retrieves a list of countries supported by the DodoPayments system. ```APIDOC ## GET /checkout/supported_countries ### Description Retrieves a list of countries supported by the DodoPayments system. ### Method GET ### Endpoint /checkout/supported_countries ### Response #### Success Response (200) - **countries** (CountryCode[]) - A list of supported country codes. ``` -------------------------------- ### Deploy Remote MCP Server Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/packages/mcp-server/cloudflare-worker/README.md Command to deploy the MCP server to Cloudflare Workers after configuring the KV namespace. ```bash npm run deploy ``` -------------------------------- ### Create Credit Entitlement Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a new credit entitlement. ```APIDOC ## POST /credit-entitlements ### Description Creates a new credit entitlement. ### Method POST ### Endpoint /credit-entitlements ### Parameters #### Request Body - **params** (object) - Required - Details for the new credit entitlement. ``` -------------------------------- ### LedgerEntries API Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Methods for managing ledger entries within customer wallets. ```APIDOC ## GET /customers/{customer_id}/wallets/ledger-entries ### Description Retrieves a paginated list of ledger entries for a customer's wallet. ### Method GET ### Endpoint /customers/{customer_id}/wallets/ledger-entries ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer. #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **CustomerWalletTransactionsDefaultPageNumberPagination** - The response object containing a list of ledger entries. ``` ```APIDOC ## POST /customers/{customer_id}/wallets/ledger-entries ### Description Creates a ledger entry for a customer's wallet. ### Method POST ### Endpoint /customers/{customer_id}/wallets/ledger-entries ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer. #### Request Body - **params** (object) - Required - An object containing the details for the ledger entry. ### Response #### Success Response (200) - **CustomerWallet** - The updated customer wallet object after the ledger entry creation. ``` -------------------------------- ### Wallets API Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Methods for managing customer wallets. ```APIDOC ## GET /customers/{customer_id}/wallets ### Description Retrieves a list of wallets for a specific customer. ### Method GET ### Endpoint /customers/{customer_id}/wallets ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer. ### Response #### Success Response (200) - **WalletListResponse** - The response object containing a list of customer wallets. ``` -------------------------------- ### Format and Fix Lint Issues Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/CONTRIBUTING.md Use this command to automatically format the code and fix any linting issues found. ```sh $ yarn fix ``` -------------------------------- ### List Credit Entitlement Balances Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Lists balances for a specific credit entitlement. ```APIDOC ## GET /credit-entitlements/{credit_entitlement_id}/balances ### Description Lists balances for a specific credit entitlement. ### Method GET ### Endpoint /credit-entitlements/{credit_entitlement_id}/balances ### Parameters #### Path Parameters - **credit_entitlement_id** (string) - Required - The ID of the credit entitlement. #### Query Parameters - **params** (object) - Required - Parameters for pagination and filtering. ``` -------------------------------- ### Create Checkout Session Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Creates a new checkout session. This is the primary method for initiating a payment flow. ```APIDOC ## POST /checkouts ### Description Creates a new checkout session. ### Method POST ### Endpoint /checkouts ### Request Body - **params** (CheckoutSessionRequest) - Required - The parameters for creating the checkout session. ### Response #### Success Response (200) - **checkoutSession** (CheckoutSessionResponse) - The response object containing details of the created checkout session. ``` -------------------------------- ### Preview Checkout Session Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Generates a preview of a checkout session without actually creating it. Useful for validation and display purposes. ```APIDOC ## POST /checkouts/preview ### Description Previews a checkout session. ### Method POST ### Endpoint /checkouts/preview ### Request Body - **params** (CheckoutSessionRequest) - Required - The parameters for previewing the checkout session. ### Response #### Success Response (200) - **checkoutSessionPreview** (CheckoutSessionPreviewResponse) - The response object containing the preview details of the checkout session. ``` -------------------------------- ### retrieve Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Retrieves a specific discount by its ID. ```APIDOC ## GET /discounts/{discount_id} ### Description Retrieves a specific discount by its ID. ### Method GET ### Endpoint /discounts/{discount_id} ### Parameters #### Path Parameters - **discount_id** (string) - Required - The ID of the discount to retrieve. ### Response #### Success Response (200) - **discount** (Discount) - The requested discount object. ``` -------------------------------- ### Customers API Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Methods for managing customer information and related resources. ```APIDOC ## GET /customers ### Description Retrieves a paginated list of customers. ### Method GET ### Endpoint /customers ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for pagination and filtering. ### Response #### Success Response (200) - **CustomersDefaultPageNumberPagination** - The response object containing a list of customers. ``` ```APIDOC ## GET /customers/{customer_id} ### Description Retrieves a specific customer by their ID. ### Method GET ### Endpoint /customers/{customer_id} ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer to retrieve. ### Response #### Success Response (200) - **Customer** - The retrieved customer object. ``` ```APIDOC ## POST /customers ### Description Creates a new customer. ### Method POST ### Endpoint /customers ### Parameters #### Request Body - **params** (object) - Required - An object containing the customer details. ### Response #### Success Response (200) - **Customer** - The newly created customer object. ``` ```APIDOC ## PATCH /customers/{customer_id} ### Description Updates a specific customer by their ID. ### Method PATCH ### Endpoint /customers/{customer_id} ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer to update. #### Request Body - **params** (object) - Required - An object containing the fields to update. ### Response #### Success Response (200) - **Customer** - The updated customer object. ``` ```APIDOC ## GET /customers/{customer_id}/payment-methods ### Description Retrieves the payment methods for a specific customer. ### Method GET ### Endpoint /customers/{customer_id}/payment-methods ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer. ### Response #### Success Response (200) - **CustomerRetrievePaymentMethodsResponse** - The response object containing the customer's payment methods. ``` ```APIDOC ## GET /customers/{customer_id}/credit-entitlements ### Description Retrieves the credit entitlements for a specific customer. ### Method GET ### Endpoint /customers/{customer_id}/credit-entitlements ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer. ### Response #### Success Response (200) - **CustomerListCreditEntitlementsResponse** - The response object containing the customer's credit entitlements. ``` ```APIDOC ## DELETE /customers/{customer_id}/payment-methods/{payment_method_id} ### Description Deletes a specific payment method for a customer. ### Method DELETE ### Endpoint /customers/{customer_id}/payment-methods/{payment_method_id} ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer. - **payment_method_id** (string) - Required - The ID of the payment method to delete. #### Query Parameters - **params** (object) - Optional - Additional parameters for the deletion request. ### Response #### Success Response (200) - **void** - Indicates successful deletion. ``` ```APIDOC ## GET /customers/{customer_id}/entitlements ### Description Retrieves the entitlements for a specific customer. ### Method GET ### Endpoint /customers/{customer_id}/entitlements ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer. ### Response #### Success Response (200) - **CustomerListEntitlementsResponse** - The response object containing the customer's entitlements. ``` -------------------------------- ### CustomerPortal API Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Methods for managing customer portal sessions. ```APIDOC ## POST /customers/{customer_id}/customer-portal/session ### Description Creates a customer portal session for a given customer. ### Method POST ### Endpoint /customers/{customer_id}/customer-portal/session ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer. #### Request Body - **params** (object) - Required - An object containing parameters for the session creation. ### Response #### Success Response (200) - **CustomerPortalSession** - The created customer portal session object. ``` -------------------------------- ### Use TypeScript types for checkout session creation Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/README.md Utilize TypeScript definitions for request parameters and response types when creating a checkout session. This enhances type safety and provides better editor support. ```ts 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 params: DodoPayments.CheckoutSessionCreateParams = { product_cart: [{ product_id: 'pdt_example', quantity: 1 }], }; const checkoutSessionResponse: DodoPayments.CheckoutSessionResponse = await client.checkoutSessions.create(params); ``` -------------------------------- ### Retrieve Ledger Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Retrieves ledger entries for balances. ```APIDOC ## GET /balances/ledger ### Description Retrieves ledger entries for balances. ### Method GET ### Endpoint /balances/ledger ### Parameters #### Query Parameters - **params** (object) - Required - Parameters for pagination and filtering. ``` -------------------------------- ### Retrieve License Key Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/api.md Retrieves a specific license key by its ID. ```APIDOC ## GET /license_keys/{id} ### Description Retrieves a specific license key. ### Method GET ### Endpoint /license_keys/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier for the license key. ### Response #### Success Response (200) - **LicenseKey** (object) - The details of the license key. ``` -------------------------------- ### Import Uploadable Types Source: https://github.com/dodopayments/dodopayments-typescript/blob/main/MIGRATION.md The 'Uploadable' type and 'toFile' function are still exported from 'dodopayments/core/uploads'. ```typescript import { type Uploadable, toFile } from 'dodopayments/core/uploads'; ```