安装
使用 Cargo 将 SDK 添加到您的项目中:Cargo.toml 中:
快速开始
客户端默认从DODO_PAYMENTS_API_KEY 环境变量中读取您的 API 密钥。初始化客户端并创建您的第一个结账会话:
核心功能
Built on Tokio and reqwest withasync/await support throughout
Strongly typed requests and responses for compile-time safety
Stream every item across pages or advance one page at a time
Configure environments, timeouts, and base URLs per client
配置
环境变量
默认情况下,Client::from_env() 从 DODO_PAYMENTS_API_KEY 环境变量中读取您的 API 密钥,并使用默认基本 URL,除非您设置 DODO_PAYMENTS_BASE_URL:
Client::new 返回一个 Result,因此在返回 dodopayments::Result 的函数中与 ? 一起解包它:
环境
| 名称 | 基本 URL |
|---|---|
live_mode | https://live.dodopayments.com |
test_mode | https://test.dodopayments.com |
https://live.dodopayments.com。使用 Environment 枚举选择其他环境,而不是硬编码 URL:
from_env() 继续从 DODO_PAYMENTS_API_KEY 读取 API 密钥,同时将目标放在非默认环境中,请在配置中覆盖它:
超时
默认请求超时为 30 秒。为每个客户端覆盖它:常用操作
创建结账会话
生成一个结账会话:管理客户
创建和检索客户信息:处理订阅
创建和管理定期订阅: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).
基于使用量的计费
引入使用事件
跟踪自定义事件:列出使用情况事件
分页
List endpoints return a typed page whoseitems field holds the current page of results. Stream every item across all pages with into_stream:
get_next_page:
错误处理
Every method returns adodopayments::Result<T>. Failures are represented by the dodopayments::Error enum. Match on it to handle API errors distinctly from transport errors:
未记录的端点
要调用尚未作为类型化方法公开的端点,请使用应用身份验证和基本 URL 的低级request 构建器:
资源
View source code and contribute View the published crate and versions Complete API documentation Get help and connect with developers支持
需要 Rust SDK 的帮助吗?- Discord: 加入我们的社区服务器获取实时支持
- Email: 联系我们 support@dodopayments.com
- GitHub: 在 repository 上打开一个 issue