@dodopayments/express adaptor gives your Express app three route handlers: checkoutHandler returns checkout URLs, CustomerPortal sends a customer to the Customer Portal, and Webhooks verifies webhook requests and calls your event handlers.
Checkout Handler
Create payment links and checkout sessions from your Express app.
Customer Portal
Let customers manage their subscriptions and details.
Webhooks
Verify and process Dodo Payments webhook events.
Installation
1
Install the Package
Run the following command in your project root:
2
Set Up Environment Variables
Create a Create the API key under Developer → API Keys. Add your webhook endpoint under Developer → Webhooks and copy its signing secret into
.env file in your project root:DODO_PAYMENTS_WEBHOOK_KEY. While you build, use a test mode API key with DODO_PAYMENTS_ENVIRONMENT=test_mode, because a test mode key works only against test mode. DODO_PAYMENTS_RETURN_URL is optional.Route Handler Examples
The examples register routes on an Express app created with
express(). The POST checkout handlers and the webhook handler read req.body, so each example registers express.json() before its routes.- Checkout Handler
- Customer Portal Handler
- Webhook Handler
Use this handler to integrate Dodo Payments checkout into your Express app. Supports static (GET), dynamic (POST), and session (POST) payment flows. Register each POST flow on its own path, because the first handler registered for a path answers every request to it.
Checkout Route Handler
The adaptor supports all three Dodo Payments checkout flows. Set
type in the handler config to choose the flow a route serves. Every flow responds with JSON that contains a checkout_url for the customer to open.- Static Payment Links:
type: "static", GET. Builds a payment link for one product from query parameters, after checking that the product exists. - Dynamic Payment Links:
type: "dynamic", POST. Creates a one-time payment or a subscription with a payment link, depending on whether the product is recurring. - Checkout Sessions:
type: "session", POST. Creates a checkout session from a product cart and customer details. Use this flow for new integrations.
checkoutHandler takes these options:
Register the handler for GET when
type is static, and for POST when type is dynamic or session. The handler returns 405 for other methods.
Static Checkout (GET)
Static Checkout (GET)
Supported Query Parameters
string
required
Product identifier, for example
?productId=pdt_nZuwz45WAs64n3l07zpQR.integer
default:"1"
Quantity of the product.
string
Customer’s full name. Ignored if
firstName or lastName is provided.string
Customer’s first name.
string
Customer’s last name.
string
Customer’s email address.
string
Customer’s country, as an ISO 3166-1 alpha-2 code.
string
Customer’s street address.
string
Customer’s city.
string
Customer’s state or province.
string
Customer’s postal or ZIP code.
boolean
Set to
true to disable the full name field.boolean
Set to
true to disable the first name field.boolean
Set to
true to disable the last name field.boolean
Set to
true to disable the email field.boolean
Set to
true to disable the country field.boolean
Set to
true to disable the address line field.boolean
Set to
true to disable the city field.boolean
Set to
true to disable the state field.boolean
Set to
true to disable the ZIP code field.string
The payment currency, for example
USD.boolean
default:"true"
Show or hide the currency selector.
number
Fixes the amount charged, in major currency units, for example
12.5 for $12.50. Works with Pay What You Want products only, and is ignored if it’s below the product’s minimum price.boolean
default:"true"
Show or hide the discounts section.
string
Any query parameter that starts with
metadata_ is passed to checkout as metadata, for example metadata_orderId=123.true and the matching field has a value, for example email with disableEmail. The handler passes these parameters to a static payment link.Response Format
Static checkout returns a JSON response with the checkout URL:Dynamic Checkout (POST)
Dynamic Checkout (POST)
- Send parameters as a JSON body in a POST request.
- Supports both one-time and recurring payments. The handler retrieves the product, then creates a subscription if the product is recurring and a one-time payment otherwise.
- The body needs
billing(withstreet,city,state,country, andzipcode) andcustomer, plusproduct_id(with an optionalquantity) orproduct_cart. Subscriptions needproduct_id. - The handler also forwards
metadata,allowed_payment_method_types,billing_currency,discount_codes(or the deprecateddiscount_code),return_url,show_saved_payment_methods, andtax_id. For subscriptions, it forwardsaddons,on_demand, andtrial_period_daystoo. It ignores other fields. - For field details, refer to:
Response Format
Dynamic checkout returns a JSON response with the payment link as the checkout URL:Checkout Sessions (POST)
Checkout Sessions (POST)
Send a checkout session payload as the JSON body. The handler creates a checkout session, which handles the complete payment flow for one-time purchases and subscriptions, and returns its
checkout_url. product_cart is required and must contain at least one product.Each checkout_url works once and expires after 24 hours, or after 15 minutes when you pass confirm: true. A session created with payment_method_id returns no checkout_url, so the handler responds with 400.Refer to Checkout Sessions Integration Guide for more details and a complete list of supported fields.Response Format
Checkout sessions return a JSON response with the checkout URL:Customer Portal Route Handler
The Customer Portal Route Handler creates a Customer Portal session for the customer incustomer_id and redirects the request to the portal link. CustomerPortal takes the bearerToken and environment options, the same as checkoutHandler. If Dodo Payments can’t create the session, the handler returns 500.
Query Parameters
string
required
The customer ID for the portal session, for example
?customer_id=cus_123.boolean
If set to
true, sends an email to the customer with the portal link.Webhook Route Handler
The webhook handler verifies each request with your webhook secret, passed aswebhookKey, then calls your event handlers.
- Method: Only POST requests are supported. Other methods return 405.
- Signature Verification: Verifies the
webhook-id,webhook-timestamp, andwebhook-signatureheaders withwebhookKey, following the Standard Webhooks specification. 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
onPayloadfor every event, then the handler for the event’s type, and returns 200 when they finish. The handler doesn’t catch errors that your event handlers throw.