Skip to main content
The @dodopayments/convex component adds Dodo Payments to your Convex backend. It provides a checkout function that creates checkout sessions, a customerPortal function that opens the Customer Portal for the signed-in user, and createDodoWebhookHandler, which verifies webhooks in a Convex HTTP action. It requires Convex 1.26 or later.

Checkout Function

Create checkout sessions from Convex actions.

Customer Portal

Let customers manage their subscriptions and details.

Webhooks

Receive and process Dodo Payments webhook events.

Installation

1

Install the Package

Run this command in your project root:
2

Add Component to Convex Config

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

Set Up Environment Variables

Set environment variables in your Convex dashboard under Settings → Environment Variables. To open the dashboard, run:
Add these environment variables:
  • DODO_PAYMENTS_API_KEY: Your Dodo Payments API key, from Developer → API Keys in the Dodo Payments dashboard.
  • DODO_PAYMENTS_ENVIRONMENT: test_mode or live_mode.
  • DODO_PAYMENTS_WEBHOOK_SECRET: Your webhook secret, from Developer → Webhooks. Required for webhook handling. The webhook handler reads this exact variable name.
Store secrets as Convex environment variables. Convex backend functions don’t read .env files. Never commit secrets to version control.

Component Setup Examples

1

Create Internal Query

Create an internal query that finds a customer in your database by auth ID. The identify function in the next step uses it to get the signed-in user’s Dodo Payments customer ID for the customer portal.
The component doesn’t define a schema. Before you use this query, define a customers table with a by_auth_id index in convex/schema.ts, or change the query to match your existing schema.
2

Configure DodoPayments Component

Create the client. identify maps the signed-in Convex user to a Dodo Payments customer ID. It returns null if no user is signed in or no customer matches.
Then add the functions you need:
Use this function to add Dodo Payments checkout to your Convex app. It creates a checkout session from the fields accepted by the component’s checkout payload validator.

Checkout Function

The Convex component creates checkout sessions, the recommended checkout flow for all payments. A session holds the product cart, customer details, and checkout options.

Usage

Call checkout from a Convex action, with the checkout session fields in payload:
checkout doesn’t call identify. To attach an existing customer, pass customer: { customer_id } in the payload. For more details and a complete list of supported fields, see Checkout Sessions. A session created with payment_method_id returns no checkout URL, so checkout throws an error for it.

Response Format

The checkout function returns an object with the checkout URL:

Customer Portal Function

The customer portal function returns a Customer Portal URL for the signed-in user.

Usage

It returns an object with a portal_url field.

Parameters

boolean
default:"false"
If set to true, Dodo Payments also emails the portal link to the customer.
customerPortal gets the customer from the identify function in your DodoPayments setup, which must return the customer’s dodoCustomerId. If identify returns null, customerPortal throws a User is not authenticated. error.

Webhook Handler

createDodoWebhookHandler verifies each request before it runs your code:
  • Method: Register the route with method: "POST". Requests with other methods don’t reach the handler.
  • Signature Verification: Verifies the Standard Webhooks signature with the DODO_PAYMENTS_WEBHOOK_SECRET environment variable. Returns 400 if verification fails.
  • Payload Validation: Validated with Zod. Returns 400 for invalid payloads.
  • Error Handling:
    • 400: Invalid signature, invalid payload, or an error thrown by one of your handlers
    • 200: All handlers finished
    • If DODO_PAYMENTS_WEBHOOK_SECRET isn’t set, the handler throws an error and the request fails.
  • Event Routing: Calls onPayload for every event, then the handler for the event’s type.

Supported Webhook Event Handlers

Each handler receives the Convex ActionCtx and the verified payload for its event type:

Frontend Usage

Call the checkout and portal actions from your React components with the useAction hook from convex/react.

Prompt for LLM

Copy this prompt into your AI coding assistant to have it add the component to your project. To give your agent the Dodo Payments docs and skills as well, install the Agent Plugin.
Last modified on September 25, 2026