Integrate Dodo Payments into your Rust applications with an async-first, strongly typed SDK built on Tokio and reqwest
The Rust SDK provides convenient, async-first access to the Dodo Payments REST API from applications written in Rust. It offers strongly typed requests and responses, built-in pagination helpers, and configurable timeouts and environments.
The client reads your API key from the DODO_PAYMENTS_API_KEY environment variable by default. Initialize the client and create your first checkout session:
use dodopayments::Client;#[tokio::main]async fn main() -> dodopayments::Result<()> { let client = Client::from_env()?; let result = client .checkout_sessions() .create() .body(dodopayments::models::CheckoutSessionsCreateParams { product_cart: Some(vec![dodopayments::models::ProductItemReq { product_id: "product_id".to_string(), quantity: 1, addons: None, amount: None, credit_entitlements: None, }]), ..Default::default() }) .await?; println!("{result:?}"); Ok(())}
Always store your API keys securely using environment variables. Never hardcode them in your source code.
By default, Client::from_env() reads your API key from the DODO_PAYMENTS_API_KEY environment variable and uses the default base URL unless you set DODO_PAYMENTS_BASE_URL:
The default base URL is https://live.dodopayments.com. Select another environment with the Environment enum instead of hard-coding URLs:
use dodopayments::{Client, ClientConfig, Environment};let client = Client::new( ClientConfig::from_environment(Environment::TestMode).with_api_key("My API Key"),)?;
To keep reading the API key from DODO_PAYMENTS_API_KEY via from_env() while targeting a non-default environment, override it on the config:
use dodopayments::{Client, ClientConfig, Environment};let client = Client::new(ClientConfig::from_env()?.with_environment(Environment::TestMode))?;
billing requires at minimum the two-letter ISO country code. customer is a CustomerRequest enum — pass AttachExisting for an existing customer or New for a new one. Amount fields such as product_price are in the lowest currency denomination (e.g., 2500 = $25.00 USD).
Every method returns a dodopayments::Result<T>. Failures are represented by the dodopayments::Error enum. Match on it to handle API errors distinctly from transport errors: