Skip to main content
The PHP SDK gives PHP 8.1+ applications access to the Dodo Payments REST API. Methods take named parameters, responses are typed objects, and Composer loads the SDK with PSR-4 autoloading.

Installation

Install the SDK with Composer:
The SDK requires PHP 8.1.0 or later and Composer. It sends requests through a PSR-18 HTTP client in your project, such as Guzzle, which it finds with php-http/discovery.

Quick Start

Create a client, then create a checkout session:
If you omit bearerToken, the client reads the DODO_PAYMENTS_API_KEY environment variable. If you omit baseUrl, the client reads DODO_PAYMENTS_BASE_URL, and connects to live mode (https://live.dodopayments.com) when that isn’t set either. A test mode API key works only with the test mode URL, https://test.dodopayments.com.
Keep API keys in environment variables or a secrets manager. Never expose them in your codebase or commit them to version control.

Core Features

PSR-4 Compliant

Composer loads the Dodopayments namespace with PSR-4 autoloading.

Modern PHP

Built for PHP 8.1 or later, with typed parameters and strict types.

Extensive Testing

The SDK repository includes a test suite for the API services.

Exception Handling

An exception class for each HTTP error status, plus timeout and connection exceptions.

Value Objects

Methods take named parameters, and parameters that have a default value must be passed by name. To build a value object, use its static with constructor with named parameters:
Each value object also has a builder:
Methods also accept plain arrays with the same camelCase keys, such as ["productID" => "pdt_123", "quantity" => 1]. Response properties use camelCase names too, for example $session->checkoutURL.

Configuration

The Client constructor takes bearerToken, webhookKey, environment (for example, 'test_mode'), baseUrl, and requestOptions. When you omit them, it reads DODO_PAYMENTS_API_KEY, DODO_PAYMENTS_WEBHOOK_KEY (your webhook signing secret), and DODO_PAYMENTS_BASE_URL from the environment. To verify a webhook, pass the raw request body and headers to $client->webhooks->unwrap($body, headers: $headers). It checks the signature with your webhook key, returns the parsed event, and throws WebhookException if the check fails. If you omit headers, unwrap doesn’t verify the signature. $client->webhooks->unsafeUnwrap($body) parses the body without verifying it, so use it only for testing. See Webhooks.

Retry Configuration

The SDK retries some errors twice by default, with a short exponential backoff. These errors trigger a retry:
  • Connection errors (network connectivity problems)
  • 408 Request Timeout
  • 409 Conflict
  • 429 Rate Limit
  • 500+ Internal errors
  • Timeouts
Set maxRetries in requestOptions, on the client or on a single request:
Requests time out after 60 seconds by default. To change the limit, set timeout, in seconds, in the same requestOptions array.

Common Operations

The examples in this section use the $client from Quick Start.

Create a Checkout Session

Create a checkout session, then redirect the customer to the returned checkoutURL:
Each checkout URL works once and expires after 24 hours. For every session option, see Checkout Sessions.

Manage Customers

Create a customer with an email address and name, then retrieve it by ID:

Handle Subscriptions

Create a subscription, then charge it if it’s an on-demand subscription.
POST /subscriptions (the SDK’s subscriptions->create method) is deprecated. It still works for existing integrations, but new integrations should create subscriptions through a Checkout Session.
billing requires only country, a two-letter ISO country code. Pass AttachExistingCustomer::with(customerID: '...') to attach an existing customer, or NewCustomer::with(email: '...', name: '...') to create one. Both classes are in the Dodopayments\Payments namespace. charge is for on-demand subscriptions, and productPrice is in the smallest currency unit.

Pagination

List methods return a page object. getItems() returns the items on the current page, and pagingEachItem() returns every item from the current page onward, requesting more pages as needed:
To move one page at a time, call hasNextPage() and getNextPage().

Error Handling

When the SDK can’t connect to the API, or the API returns a 4xx or 5xx status, the SDK throws a subclass of Dodopayments\Core\Exceptions\APIException:

Error Types

The exception class depends on the cause. All classes are in the Dodopayments\Core\Exceptions namespace:
Catch these exceptions around API calls so that your application can show a clear message or try again later. For a retryable error, the SDK throws only after its automatic retries fail.

Advanced Usage

Undocumented Endpoints

To call an endpoint that has no SDK method, use $client->request. It applies the same authentication and retries as the SDK methods:

Undocumented Parameters

To send parameters that the SDK doesn’t define, pass them in requestOptions:
An extra* parameter that has the same name as a documented parameter overrides it.

Framework Integration

Laravel

Wrap the client in a service class. This example sets the API URL from the configured environment:
Add the settings to config/services.php:

Symfony

Create a service that receives the API key through its constructor:
Register the service in config/services.yaml:

Resources

GitHub Repository

Source code, releases, and the full method list.

API Reference

Every endpoint, parameter, and response.

Discord Community

Ask questions and talk with other developers.

Report Issues

Report bugs or request features.

Support

For help with the PHP SDK:

Contributing

To contribute, read the contributing guidelines.
Last modified on September 25, 2026