Skip to main content

Prerequisites

To integrate the Dodo Payments API, you’ll need:
  • A Dodo Payments merchant account
  • API Credentials (API key and webhook secret key) from dashboard

Dashboard Setup

  1. Navigate to the Dodo Payments Dashboard
  2. Create a product (one-time payment or subscription)
  3. Generate your API key:
    • Go to Developer > API
    • Detailed Guide
    • Copy the API key the in env named DODO_PAYMENTS_API_KEY
  4. Configure webhooks:
    • Go to Developer > Webhooks
    • Create a webhook URL for payment notifications
    • Copy the webhook secret key in env

Integration

Choose the integration path that fits your use case:
  • Checkout Sessions (recommended): Best for most integrations. Create a session on your server and redirect customers to a secure, hosted checkout.
  • Overlay Checkout (embedded): Use when you need an in-page experience that embeds the hosted checkout on your site.
  • Static Payment Links: No-code, instantly shareable URLs for quick payment collection.
  • Dynamic Payment Links: Programmatically created links. However, Checkout Sessions are recommended and provide more flexibility.

1. Checkout Sessions

Use Checkout Sessions to create a secure, hosted checkout experience for one-time payments or subscriptions. You create a session on your server, then redirect the customer to the returned checkout_url.
Checkout sessions are valid for 24 hours by default. If you pass confirm=true, sessions are valid for 15 minutes and all required fields must be provided.
1

Create a checkout session

Choose your preferred SDK or call the REST API.
  • Node.js SDK
  • Python SDK
  • REST API
import DodoPayments from 'dodopayments';

const client = new DodoPayments({
  bearerToken: process.env.DODO_PAYMENTS_API_KEY,
});

const session = await client.checkoutSessions.create({
  product_cart: [{ product_id: 'prod_123', quantity: 1 }],
  customer: { email: 'customer@example.com', name: 'John Doe' },
  return_url: 'https://yourapp.com/checkout/success',
});
2

Redirect customer to checkout

After session creation, redirect to the checkout_url to start the hosted flow.
// Example in a browser context
window.location.href = session.checkout_url;
Prefer Checkout Sessions for the fastest, most reliable way to start taking payments. For advanced customization, see the full Checkout Sessions guide and the API Reference.

2. Overlay Checkout

For a seamless in-page checkout experience, explore our Overlay Checkout integration that allows customers to complete payments without leaving your website. Static payment links let you quickly accept payments by sharing a simple URL. You can customize the checkout experience by passing query parameters to pre-fill customer details, control form fields, and add custom metadata.
1

Construct your payment link

Start with the base URL and append your product ID:
https://checkout.dodopayments.com/buy/{productid}
2

Add core parameters

Include essential query parameters:
  • quantity
    integer
    default:"1"
    Number of items to purchase.
  • redirect_url
    string
    required
    URL to redirect after payment completion.
The redirect URL will include payment details as query parameters, for example:
https://example.com/?payment_id=pay_ts2ySpzg07phGeBZqePbH&status=succeeded
3

Pre-fill customer information (optional)

Add customer or billing fields as query parameters to streamline checkout.
  • fullName
    string
    Customer’s full name (ignored if firstName or lastName is provided).
  • firstName
    string
    Customer’s first name.
  • lastName
    string
    Customer’s last name.
  • email
    string
    Customer’s email address.
  • country
    string
    Customer’s country.
  • addressLine
    string
    Street address.
  • city
    string
    City.
  • state
    string
    State or province.
  • zipCode
    string
    Postal/ZIP code.
  • showDiscounts
    boolean
    true or false
4

Control form fields (optional)

You can disable specific fields to make them read-only for the customer. This is useful when you already have the customer’s details (e.g., logged-in users).
To disable a field, provide its value and set the corresponding disable… flag to true:
&email=alice@example.com&disableEmail=true
  • Disable Flags Table
FieldDisable FlagRequired Parameter
Full NamedisableFullNamefullName
First NamedisableFirstNamefirstName
Last NamedisableLastNamelastName
EmaildisableEmailemail
CountrydisableCountrycountry
Address LinedisableAddressLineaddressLine
CitydisableCitycity
StatedisableStatestate
ZIP CodedisableZipCodezipCode
Disabling fields helps prevent accidental changes and ensures data consistency.
5

Add advanced controls (optional)

  • paymentCurrency
    string
    Specifies the payment currency. Defaults to the billing country’s currency.
  • showCurrencySelector
    boolean
    default:"true"
    Show or hide the currency selector.
  • paymentAmount
    integer
    Amount in cents (for Pay What You Want pricing only).
  • metadata_*
    string
    Custom metadata fields (e.g., metadata_orderId=123).
6

Share the link

Send the completed payment link to your customer. When they visit, all query parameters are collected and stored with a session ID. The URL is then simplified to include just the session parameter (e.g., ?session=sess_1a2b3c4d). The stored information persists through page refreshes and is accessible throughout the checkout process.
The customer’s checkout experience is now streamlined and personalized based on your parameters.
Prefer Checkout Sessions for most use cases, they offer more flexibility and control.
Created via API call or our SDK with customer details. Here’s an example: There are two APIs for creating dynamic payment links: The guide below is for one-time payment link creation. For detailed instructions on integrating subscriptions, refer to this Subscription Integration Guide.
Make sure you are passing payment_link = true to get payment link
  • Node.js SDK
  • Python SDK
  • Go SDK
  • Api Reference
import DodoPayments from 'dodopayments';

const client = new DodoPayments({
bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});

async function main() {
const payment = await client.payments.create({
payment_link: true,
billing: { city: 'city', country: 'AF', state: 'state', street: 'street', zipcode: 0 },
customer: { email: 'email@email.com', name: 'name' },
product_cart: [{ product_id: 'product_id', quantity: 0 }],
});

console.log(payment.payment_id);
}

main();
After creating the payment link, redirect your customers to complete their payment.

Implementing Webhooks

Set up an API endpoint to receive payment notifications. Here’s an example using Next.js:
import { Webhook } from "standardwebhooks";
import { headers } from "next/headers";
import { WebhookPayload } from "@/types/api-types";

const webhook = new Webhook(process.env.DODO_WEBHOOK_KEY!); // Replace with your secret key generated from the Dodo Payments Dashboard

export async function POST(request: Request) {
  const headersList = headers();
  const rawBody = await request.text();

  const webhookHeaders = {
    "webhook-id": headersList.get("webhook-id") || "",
    "webhook-signature": headersList.get("webhook-signature") || "",
    "webhook-timestamp": headersList.get("webhook-timestamp") || "",
  };

  await webhook.verify(rawBody, webhookHeaders);
  const payload = JSON.parse(rawBody) as WebhookPayload;
  
  // Process the payload according to your business logic
}
Our webhook implementation follows the Standard Webhooks specification. For webhook type definitions, refer to our Webhook Event Guide. You can refer to this project with demo implementation on GitHub using Next.js and TypeScript. You can check out the live implementation here.
I