Skip to main content

Checkout Function

Integrate Dodo Payments checkout with session-based flow.

Customer Portal

Allow customers to manage subscriptions and details.

Webhooks

Receive and process Dodo Payments webhook events.

Installation

1

Install the package

Run the following command in your project root:
2

Add Component to Convex Config

Add the Dodo Payments component to your Convex configuration:
After editing convex.config.ts, run npx convex dev once to generate the necessary types.
3

Set up environment variables

Set up environment variables in your Convex dashboard (SettingsEnvironment Variables). You can access the dashboard by running:
Add the following environment variables:
  • DODO_PAYMENTS_API_KEY - Your Dodo Payments API key
  • DODO_PAYMENTS_ENVIRONMENT - Set to test_mode or live_mode
  • DODO_PAYMENTS_WEBHOOK_SECRET - Your webhook secret (required for webhook handling)
Always use Convex environment variables for sensitive information. Never commit secrets to version control.

Component Setup Examples

1

Create Internal Query

First, create an internal query to fetch customers from your database. This will be used in the payment functions to identify customers.
Before using this query, make sure to define the appropriate schema in your convex/schema.ts file or change the query to match your existing schema.
2

Configure DodoPayments Component

Use this function to integrate Dodo Payments checkout into your Convex app. Uses session-based checkout with full feature support.

Checkout Function

The Dodo Payments Convex component uses session-based checkout, providing a secure, customizable checkout experience with pre-configured product carts and customer details. This is the recommended approach for all payment flows.

Usage

Refer Checkout Sessions for more details and a complete list of supported fields.

Response Format

The checkout function returns a JSON response with the checkout URL:

Customer Portal Function

The Customer Portal Function enables you to seamlessly integrate the Dodo Payments customer portal into your Convex application.

Usage

Parameters

send_email
boolean
If set to true, sends an email to the customer with the portal link.
The customer is automatically identified using the identify function configured in your DodoPayments setup. This function should return the customer’s dodoCustomerId.

Webhook Handler

  • Method: Only POST requests are supported. Other methods return 405.
  • Signature Verification: Verifies the webhook signature using DODO_PAYMENTS_WEBHOOK_SECRET. Returns 401 if verification fails.
  • Payload Validation: Validated with Zod. Returns 400 for invalid payloads.
  • Error Handling:
    • 401: Invalid signature
    • 400: Invalid payload
    • 500: Internal error during verification
  • Event Routing: Calls the appropriate event handler based on the payload type.

Supported Webhook Event Handlers

Frontend Usage

Use the checkout function from your React components with Convex hooks.

Prompt for LLM

Last modified on April 20, 2026