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: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.
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 staticwith constructor with named parameters:
["productID" => "pdt_123", "quantity" => 1]. Response properties use camelCase names too, for example $session->checkoutURL.
Configuration
TheClient 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
maxRetries in requestOptions, on the client or on a single request:
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 returnedcheckoutURL:
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.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:
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 ofDodopayments\Core\Exceptions\APIException:
Error Types
The exception class depends on the cause. All classes are in theDodopayments\Core\Exceptions namespace:
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 inrequestOptions:
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:config/services.php:
Symfony
Create a service that receives the API key through its constructor: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:- Discord: Join the community server for real-time help.
- Email: Contact support@dodopayments.com.
- GitHub: Open an issue on the repository.