Installation
Add the SDK to your project with Cargo:Cargo.toml manually:
The SDK requires Rust 1.75 or later.
Quick Start
Client::from_env() reads your API key from the DODO_PAYMENTS_API_KEY environment variable. Create a client, then create a checkout session:
DODO_PAYMENTS_API_KEY isn’t set, Client::from_env() returns an Error::Config. The client connects to live mode unless you choose another environment, as shown in Environments. A test mode API key works only in test mode.
Core Features
Async First
Built on Tokio and reqwest, with
async/await for every request.Strong Typing
Typed request and response structs for compile-time checks.
Auto-Pagination
Stream every item across pages, or move one page at a time.
Configurable
Set the environment, base URL, timeout, and retry count for each client.
Configuration
Environment Variables
Client::from_env() reads your API key from DODO_PAYMENTS_API_KEY. It uses the live mode URL unless you set DODO_PAYMENTS_BASE_URL:
DODO_PAYMENTS_WEBHOOK_KEY and has no method that verifies webhook signatures. To verify them, follow Webhooks.
You can also configure the client explicitly. Client::new returns a Result, so unwrap it with ? inside a function that returns dodopayments::Result:
Environments
The SDK has two environments:
The default base URL is
https://live.dodopayments.com. To select another environment, use the Environment enum instead of a hard-coded URL:
DODO_PAYMENTS_API_KEY with from_env() but target another environment, override the environment on the config:
Timeouts
The default request timeout is 30 seconds. Override it for a client withwith_timeout:
Retry-After header when the API sends one. To change the retry count, call with_max_retries on the ClientConfig, for example .with_max_retries(0) to turn retries off.
Common Operations
The examples in this section use theclient from Quick Start.
Create a Checkout Session
Create a checkout session with a return URL:session.checkout_url. 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 for an existing customer.billing requires only country, a CountryCode enum variant such as CountryCode::Us. customer is a CustomerRequest enum: pass AttachExistingCustomer for an existing customer or NewCustomer to create one. To charge an on-demand subscription, call client.subscriptions().charge().subscription_id(...) with a SubscriptionsChargeParams body. Amount fields such as product_price are in the smallest currency unit (for example, 2500 is $25.00).Usage-Based Billing
Ingest Usage Events
Send usage events for a customer:event_id is the idempotency key, so give each event a unique value. If timestamp is None, the event uses the current time.
List Usage Events
List events filtered by customer and event name. The filters go in a JSON query object:Pagination
List endpoints return a typed page whoseitems field holds the current page of results. To stream every item across all pages, call into_stream:
get_next_page. It returns None after the last page:
Error Handling
Every method returns adodopayments::Result<T>. Failures are variants of the dodopayments::Error enum: Api for an error status from the API, Http for transport errors, Json for serialization errors, Config for configuration errors, and MissingPathParam or MissingBody for incomplete requests. Match on it to handle API errors separately from transport errors:
Undocumented Endpoints
To call an endpoint that has no typed method, use the low-levelrequest builder. It applies authentication and the base URL. To name reqwest::Method, add reqwest 0.12 to your dependencies:
Resources
GitHub Repository
Source code, releases, and the full method list.
Crates.io
The published crate and its versions.
API Reference
Every endpoint, parameter, and response.
Discord Community
Ask questions and talk with other developers.
Support
For help with the Rust SDK:- Discord: Join the community server for real-time help.
- Email: Contact support@dodopayments.com.
- GitHub: Open an issue on the repository.