Use ezstripe to easily communicate with Stripe's API.
Warning
Up to version1.0.0
a lot of the structure can change with each new version!
Therefore, pay attention to the changes in the changelog on Github with every new version!
```toml
[dependencies]
ezstripe = "0.4.0"
``
or
cargo add ezstripe`
All features are enabled by default, but you can only select the features you really need for your project.
```toml
[dependencies] ezstripe = { version = "0.4.0", default-features = false, features = ["payment_intent", "refund"] } ```
List of all available features: - full - - Default. Same as without "default-features = false" - balance - mandate - payment_intent - payout - refund
```toml
[dependencies] ezstripe = "0.4.0" env_logger = "0.10.0" # Optional ```
``Rust
// Required to use the
ezbody!` macro
async fn main() { // To show possible errors (recommended for development) envlogger::initfromenv(envlogger::Env::default().filteror("MYLOG_LEVEL", "debug"));
let client = ezstripe::Client::new("SECRET_KEY");
// Returns: String("amount=1500;currency=eur;paymentmethodtypes[]=card;capturemethod=manual;") let stripebody = ezbody!( "amount" => 1500, "currency" => "eur", "paymentmethodtypes[]" => "card", "capture_method" => "manual" );
// Now send a request to Stripe's API let striperesponse = client.createpaymentintent(stripebody).send().await; if let Err((emsg, einfo)) = striperesponse { if let Some(r) = einfo { println!("{}: {} | {} | {}", emsg, r.r#type, r.code, r.message); } else { // Such an error only occurs when a request to Stripe failed println!("{}", emsg); } std::process::exit(1); }
// No error, so let's unpack the answer let striperesult = striperesponse.unwrap();
// Print the unique ID from the created PaymentIntent println!("Created: {}", stripe_result.id); } ```
This SDK for Stripe is still in a very early version, which is why there can be many changes with each update.
The following is expected from version 1.0.0
:
Complete and stable ...
Description: 6 threads which created a payment intent 20 times
Build: Release (default)
Source code
```Rust
static mut CLIENT: Option
fn createthread(num: u16) { tokio::task::spawn(async move { let client = unsafe { CLIENT.asref().unwrap() };
use std::time::Instant;
let now = Instant::now();
for _ in 0..20 {
let stripe_body = ezbody!(
"amount" => 1500,
"currency" => "eur",
"payment_method_types[]" => "card",
"capture_method" => "manual"
);
let stripe_response = client.create_payment_intent(stripe_body).send().await.unwrap();
}
println!("THREAD {}: {:.2?}", num, now.elapsed());
}); }
async fn main() { unsafe { CLIENT = Some(ezstripe::Client::new("SECRET_KEY")); }
for i in 0..6 { create_thread(i as u16); }
loop {}; } ```
| ezstripe | #0 | #1 | #2 | #3 | #4 | #5 | AVG | | ------- | --- | --- | --- | --- | --- | --- | --- | | First run | 6.26s | 6.38s | 6.38s | 6.43s | 6.19s | 6.39s | 6.34s | | Second run | 6.43s | 6.28s | 6.48s | 6.56s | 6.27s | 6.39s | 6.40s | | Third run | 6.27s | 6.26s | 6.38s | 6.24s | 6.28s | 6.36s | 6.30s |
Source code
```Rust use stripe::{ Client, CreatePaymentIntent, Currency, PaymentIntent, PaymentIntentCaptureMethod };
static mut CLIENT: Option
fn createthread(num: u16) { tokio::task::spawn(async move { let client = unsafe { CLIENT.asref().unwrap() };
use std::time::Instant;
let now = Instant::now();
for _ in 0..20 {
let payment_intent = {
let mut create_intent = CreatePaymentIntent::new(1000, Currency::USD);
create_intent.amount = 1500;
create_intent.currency = Currency::EUR;
create_intent.payment_method_types = Some(vec!["card".to_string()]);
create_intent.capture_method = Some(PaymentIntentCaptureMethod::Manual);
PaymentIntent::create(&client, create_intent).await.unwrap()
};
}
println!("THREAD {}: {:.2?}", num, now.elapsed());
}); }
async fn main() { unsafe { CLIENT = Some(Client::new("SECRET_KEY")); }
for i in 0..6 { create_thread(i as u16); }
loop {}; } ```
| async-stripe | #0 | #1 | #2 | #3 | #4 | #5 | AVG | | ------- | --- | --- | --- | --- | --- | --- | --- | | First run | 6.43s | 6.31s | 6.36s | 6.32s | 6.49s | 6.34s | 6.38s | | Second run | 6.52s | 6.56s | 6.45s | 6.75s | 6.54s | 6.48s | 6.55s | | Third run | 6.40s | 6.45s | 6.46s | 6.50s | 6.47s | 6.45s | 6.46s |
Performance result | ezstripe 0.4.0 | async-stripe 0.15.0 | | --- | --- | | 100% | 98.29% |