A cargo extension for adding Stripe API components to your Rust projects.
cargo install cargo-stripecargo stripe initThis command sets up the basic Stripe SDK structure in your project's src/stripe directory. It creates the following files:
mod.rs: Main module file that exports all componentsclient.rs: The Stripe API client with authenticationerror.rs: Error types and handlingtypes.rs: Common types used across components
cargo stripe add customerThis command adds a specific Stripe API component to your project. For example, cargo stripe add customer will add the Customer API in src/stripe/customer.rs.
Available components:
customer: Customer APIcharge: Charge APIpayment_intent: Payment Intent APIpayment_method: Payment Method APIrefund: Refund APIproduct: Product APIprice: Price APIsubscription: Subscription APIinvoice: Invoice APIcheckout: Checkout APIwebhook: Webhook handling
After initializing the SDK and adding the components you need, you can use them in your code like this:
use stripe::{Client, CreateCustomer};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new client with your API key
let client = Client::new("sk_test_your_api_key")?;
// Create a new customer
let customer_params = CreateCustomer {
email: Some("[email protected]".to_string()),
name: Some("John Doe".to_string()),
..Default::default()
};
let customer = client.create_customer(&customer_params).await?;
println!("Created customer: {:?}", customer);
Ok(())
}- Modular, component-based approach - only include what you need
- Idiomatic Rust API design
- Type-safe request and response handling
- Comprehensive error handling
- Asynchronous API using tokio
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License