Async Stripe

Client Configuration

Configuring the client runtime, authentication, and Connect account settings.

async-stripe is runtime-agnostic but provides convenient defaults. You must select a runtime feature flag in the async-stripe crate.

Runtime Selection

  • runtime-tokio-hyper: (Recommended) Uses tokio and hyper. Best for general-purpose async applications.
  • runtime-async-std-surf: Uses async-std and surf.
  • blocking: A synchronous blocking client. Note that this wraps Tokio internally to provide a synchronous API.

Initialization

Basic initialization uses your secret key and default settings.

let secret_key = std::env::var("STRIPE_SECRET_KEY").expect("Missing STRIPE_SECRET_KEY in env");
let client = Client::new(secret_key);

Advanced Configuration

You can use the ClientBuilder to configure headers, app info, or specific account masquerading (for Connect platforms).

let secret_key = std::env::var("STRIPE_SECRET_KEY").expect("Missing STRIPE_SECRET_KEY in env");

let client = ClientBuilder::new(secret_key)
    // Identify your app to Stripe (useful for analytics and support)
    .app_info("MyApp", Some("1.0.0".to_string()), Some("https://myapp.com".to_string()))
    // Acts as this connected account (Stripe Connect)
    .account_id(stripe::AccountId::from("acct_12345"))
    .build()?;

println!("Client configured with app info and account masquerading");
Have feedback? Let us know here