Prerequisites

To integrate the Dodo Payments API, you’ll need:

  • A Dodo Payments merchant account
  • API credentials (API key and webhook secret key) from the dashboard

If you don’t have an account yet, you can get your business approved by contacting the founder or by filling out this form.

For a more detailed guide on the prerequisites, check this section.

API Integration

Dodo Payments supports two types of payment links:

Detailed Guide

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 focuses on subscription payment link creation.

For detailed instructions on integrating one-time products, refer to this One-time Integration Guide.

Make sure you are passing payment_link = true to get payment link
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 subscription = await client.subscriptions.create({
billing: { city: 'city', country: 'IN', state: 'state', street: 'street', zipcode: 89789 },
customer: { customer_id: 'customer_id' },
product_id: 'product_id',
payment_link: true,
return_url: 'https://example.com/success',
quantity: 1,
});

console.log(subscription.subscription_id);
}

main();

API Response

The following is an example of the response:

{
  "client_secret": "<string>",
  "customer": {
    "customer_id": "<string>",
    "email": "<string>",
    "name": "<string>"
  },
  "metadata": {},
  "payment_link": "<string>",
  "recurring_pre_tax_amount": 1,
  "subscription_id": "<string>"
}

Redirect the customer to payment_link.

I’ll help optimize and restructure this documentation to make it clearer and more professional. I’ll fix the language, improve organization, and maintain consistency.

Webhooks

When integrating subscriptions, you’ll receive webhooks to track the subscription lifecycle. These webhooks help you manage subscription states and payment scenarios effectively.

To set up your webhook endpoint, please follow our Detailed Integration Guide.

Subscription Event Types

The following webhook events track subscription status changes:

  1. subscription.active - Subscription is successfully activated
  2. subscription.on_hold - Subscription is paused due to payment failures
  3. subscription.failed - Subscription creation fails due to mandate failure
  4. subscription.renewed - Subscription is renewed for the next billing period

For reliable subscription lifecycle management, we recommend tracking these subscription events.

Payment Scenarios

Successful Payment Flow

When a payment succeeds, you’ll receive the following webhooks in sequence:

  1. payment.succeeded - Confirms the $0 mandate authorization for future charges
  2. subscription.active - Indicates subscription activation
  3. payment.succeeded - Confirms the initial payment:
    • For immediate billing (0 trial days): Expect within 2-10 minutes
    • For trial days: whenever that ends
    • For Indian cards: Due to RBI regulations, the initial charge occurs after 24 hours, even with 0 trial days

Payment Failure Scenarios

  1. Mandate Success, Recurring Payment Failure

    • payment.succeeded - Initial $0 mandate succeeds
    • subscription.active - Subscription is activated
    • payment.failed - Recurring payment fails
    • subscription.on_hold - Subscription is paused Note: In this case, the customer needs to purchase a new subscription.
  2. Mandate Failure

    • payment.failed - $0 mandate fails
    • subscription.failed - Subscription creation fails
Best Practice: To simplify implementation, we recommend primarily tracking subscription events for managing the subscription lifecycle.

Sample Subscription event payload


PropertyTypeRequiredDescription
business_idstringYesThe unique identifier for the business
timestampstringYesThe timestamp of when the event occurred (not necessarily the same as when it was delivered)
typestringYesThe type of event. See Event Types
dataobjectYesThe main data payload. See Data Object

Data Object

The data object contains the following properties:

PropertyTypeRequiredDescription
created_atstringYesCreation timestamp
currencystringYesThree-letter currency code
customerobjectYesCustomer information
metadataobjectYesAdditional metadata
next_billing_datestringYesNext scheduled billing date
payment_frequency_countintegerYesNumber of payment frequency units
payment_frequency_intervalstringYesPayment frequency unit
product_idstringYesUnique product identifier
quantityintegerYesQuantity of the subscription
recurring_pre_tax_amountintegerYesPre-tax amount for recurring payments
statusstringYesCurrent subscription status
subscription_idstringYesUnique subscription identifier
subscription_period_countintegerYesNumber of subscription period units
subscription_period_intervalstringYesSubscription period unit
trial_period_daysintegerYesNumber of trial days
payload_typestringYesType of payload (always “Subscription”)

Enums

Time Intervals

Both payment_frequency_interval and subscription_period_interval accept the following values:

  • Day
  • Week
  • Month
  • Year

Status

The status field can have the following values:

  • pending - Initial state
  • active - Subscription is active
  • on_hold - Temporarily on hold
  • renewed - New Billing Cycle started
  • paused - Paused by user or system
  • cancelled - Subscription has been cancelled
  • failed - Payment or other failure
  • expired - Subscription has expired

Event Types

Subscription Events

  • subscription.active
  • subscription.on_hold
  • subscription.paused
  • subscription.cancelled
  • subscription.failed
  • subscription.expired