[![CRATESIO]][CRATESIO_URL] [![DOCS]][DOCS_URL] [![EXAMPLES]][EXAMPLES_URL] [![CHANGELOG]][CHANGELOG_URL] [![BENCHMARKS]][BENCHMARKS_URL]
# Usage
### Installation
```toml
# Cargo.toml
[dependencies]
ezstripe = "0.6.1"
```
or
`cargo add ezstripe`
### Features
All features are enabled by default, but you can only select the features you really need for your project.
```toml
# Cargo.toml
[dependencies]
ezstripe = { version = "0.6.1", default-features = false, features = ["payment_intent", "refund"] }
```
[Check all available features](https://github.com/EntenKoeniq/ezstripe/blob/main/Cargo.toml#L13..L29)
### Example
```toml
# Cargo.toml
[dependencies]
ezstripe = "0.6.1"
env_logger = "0.10.0" # Optional
```
```Rust
// Required to use the `ezbody!` macro
#[macro_use] extern crate ezstripe;
#[tokio::main]
async fn main() {
// To show possible errors (recommended for development)
env_logger::init_from_env(env_logger::Env::default().filter_or("MY_LOG_LEVEL", "debug"));
// We need a client to make requests
let client = ezstripe::Client::new("SECRET_KEY");
// Create a body for the request
let stripe_body = ezbody!(
"amount" => 1500,
"currency" => "eur",
"payment_method_types[]" => "card",
"payment_method_types[]" => "sofort",
"capture_method" => "automatic",
"shipping[name]" => "Your Name",
"shipping[address][city]" => "Test"
);
// Now send a request to Stripe's API
let stripe_response = client.create_payment_intent(stripe_body).send().await;
if let Err((e_msg, e_info)) = stripe_response {
if let Some(r) = e_info {
println!("{}: {} | {} | {}", e_msg, r.r#type, r.code, r.message);
} else { // Such an error only occurs when a request to Stripe failed
println!("{}", e_msg);
}
std::process::exit(1);
}
// No error, so let's unpack the answer
let stripe_result = stripe_response.unwrap();
// Print the unique ID from the created PaymentIntent
println!("Created: {}", stripe_result.id);
}
```
# Status
A list of currently supported and planned features.