Skip to content

Commit

Permalink
Stripe client changes + core types crate
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeitlin11 committed Nov 25, 2023
1 parent 65dbec6 commit 25077cb
Show file tree
Hide file tree
Showing 371 changed files with 1,063 additions and 95,043 deletions.
196 changes: 16 additions & 180 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
[workspace]
members = [
".",
"openapi",
"bench/binary_size"
"async-stripe",
"stripe_types"
]
resolver = "2"
# Makes dependency management simpler to allow codegen crate to use whichever dep versions
# it wants without affecting dependency resolution of the user-facing library crates
exclude = ["openapi"]

[package]
name = "async-stripe"
version = "0.26.0"
[workspace.package]
version = "0.22.2"
description = "API bindings for the Stripe HTTP API"
rust-version = "1.68.0"
rust-version = "1.67.0"
authors = [
"Anna Baldwin <[email protected]>",
"Kevin Stenerson <[email protected]>",
"Alexander Lyon <[email protected]>",
"Anna Baldwin <[email protected]>",
"Kevin Stenerson <[email protected]>",
"Alexander Lyon <[email protected]>",
]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -24,174 +26,8 @@ keywords = ["stripe", "v1", "api", "async"]
categories = ["api-bindings"]
edition = "2021"

[package.metadata.docs.rs]
features = ["runtime-tokio-hyper"]

[lib]
name = "stripe"

[features]
default = ["full", "webhook-events", "uuid", "stream"]
full = [
"checkout",
"billing",
"connect",
"fraud",
"issuing",
"orders",
"sigma",
"terminal",
"webhook-endpoints",
"tax-calculation",
]

stream = []

# stripe feature groups
checkout = ["billing"]
billing = []
connect = []
fraud = []
issuing = []
orders = []
sigma = []
terminal = []
webhook-endpoints = []
tax-calculation = []

# deserialize events from webhooks
webhook-events = ["events", "hmac", "sha2", "chrono", "hex"]
events = []

# runtimes
async = ["futures-util"]
blocking = []

runtime-tokio-hyper = [
"tokio",
"hyper-client",
"hyper-tls",
"async",
]
runtime-tokio-hyper-rustls = [
"tokio",
"hyper-client",
"hyper-rustls",
"hyper-rustls-native",
"async",
]
runtime-tokio-hyper-rustls-webpki = [
"tokio",
"hyper-client",
"hyper-rustls-webpki",
"async",
]
runtime-blocking = [
"tokio",
"tokio/rt",
"hyper-client",
"hyper-tls",
"blocking",
]
runtime-blocking-rustls = [
"tokio",
"tokio/rt",
"hyper-client",
"hyper-rustls-native",
"blocking",
]
runtime-blocking-rustls-webpki = [
"tokio",
"tokio/rt",
"hyper-client",
"hyper-rustls-webpki",
"blocking",
]
runtime-async-std-surf = [
"async-std",
"surf",
"async",
]

# we need the compat crate if using hyper
hyper-client = ["hyper", "http-types/hyperium_http"]

hyper-rustls-native = ["hyper-rustls", "hyper-rustls/native-tokio"]
hyper-rustls-webpki = ["hyper-rustls", "hyper-rustls/webpki-tokio"]

[dependencies]
async-std = {version = "1.8,<1.11", optional = true}

chrono = { version = "0.4", default-features = false, features = ["serde", "clock"], optional = true }
thiserror = "1.0.24"
http-types = { version = "2.12.0", default-features = false }
hyper = { version = "0.14", default-features = false, features = ["http1", "http2", "client", "tcp"], optional = true }
hyper-tls = { version = "0.5", optional = true }
hyper-rustls = { version = "0.24", default-features = false, features = ["http1", "http2", "tls12", "logging"], optional = true }
[workspace.dependencies]
serde = {version = ">=1.0.79", features = ["derive"] } # we use `serde(other)` which was introduced in 1.0.79
serde_json = "1.0"
serde_qs = "0.10.1"
serde_path_to_error = "0.1.8"
smol_str = "0.1"
surf = { version = "2.1", optional = true }
tokio = { version = "1.2", optional = true }
smart-default = "0.6.0"
uuid = { version = "0.8", optional=true, features=["v4"] }

# stream for lists
futures-util = { version = "0.3.21", optional = true }

# webhook support
hmac = { version = "0.12", optional = true }
sha2 = { version = "0.10", optional = true }
hex = { version = "0.4", optional = true }

rocket = { version = "0.4", optional = true }

[dev-dependencies]
async-std = { version = "1.10.0", features = ["attributes"] }
httpmock = "0.6.6"
tokio = { version = "1.24.1", features = ["rt", "macros"] }
axum = { version = "0.6.18", features = ["macros"] }
async-trait = "0.1"
actix-web = "4.2.1"

[[example]]
name = "checkout"
required-features = ["async"]

[[example]]
name = "connect"
required-features = ["async"]

[[example]]
name = "customer"
required-features = ["async"]

[[example]]
name = "payment-intent"
required-features = ["async"]

[[example]]
name = "payment-link"
required-features = ["async"]

[[example]]
name = "strategy"
required-features = ["async"]

[[example]]
name = "subscriptions"
required-features = ["async"]

[[example]]
name = "webhook-axum"
required-features = ["async"]

[[example]]
name = "webhook-actix"
required-features = ["async"]

[[example]]
name = "webhook-rocket"
required-features = ["rocket"]
http-types = { version = "2.12.0", default-features = false }
smol_str = "0.2.0"
serde_json = "1.0"
105 changes: 105 additions & 0 deletions async-stripe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
[package]
name = "async-stripe"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.workspace = true
categories.workspace = true

[package.metadata.docs.rs]
features = ["runtime-tokio-hyper"]

[lib]
name = "stripe"

[features]
default = ["uuid", "stream"]

stream = []

# runtimes
async = ["futures-util"]
blocking = []

runtime-tokio-hyper = [
"tokio",
"hyper-client",
"hyper-tls",
"async",
]
runtime-tokio-hyper-rustls = [
"tokio",
"hyper-client",
"hyper-rustls",
"hyper-rustls-native",
"async",
]
runtime-tokio-hyper-rustls-webpki = [
"tokio",
"hyper-client",
"hyper-rustls-webpki",
"async",
]
runtime-blocking = [
"tokio",
"tokio/rt",
"hyper-client",
"hyper-tls",
"blocking",
]
runtime-blocking-rustls = [
"tokio",
"tokio/rt",
"hyper-client",
"hyper-rustls-native",
"blocking",
]
runtime-blocking-rustls-webpki = [
"tokio",
"tokio/rt",
"hyper-client",
"hyper-rustls-webpki",
"blocking",
]
runtime-async-std-surf = [
"async-std",
"surf",
"async",
]

# we need the compat crate if using hyper
hyper-client = ["hyper", "http-types/hyperium_http"]

hyper-rustls-native = ["hyper-rustls", "hyper-rustls/native-tokio"]
hyper-rustls-webpki = ["hyper-rustls", "hyper-rustls/webpki-tokio"]

[dependencies]
stripe_types = {path = "../stripe_types"}
async-std = {version = "1.8,<1.11", optional = true}

thiserror = "1.0.24"
hyper = { version = "0.14", default-features = false, features = ["http1", "http2", "client", "tcp"], optional = true }
hyper-tls = { version = "0.5", optional = true }
hyper-rustls = { version = "0.23", default-features = false, features = ["http1", "http2", "tls12", "logging"], optional = true }
serde_json.workspace = true
serde_qs = "0.12.0"
serde_path_to_error = "0.1.8"
surf = { version = "2.1", optional = true }
tokio = { version = "1.2", optional = true }
uuid = { version = "1.6.1", optional=true, features=["v4"] }

serde.workspace = true
http-types.workspace = true
smol_str.workspace = true

# stream for lists
futures-util = { version = "0.3.21", optional = true }

[dev-dependencies]
httpmock = "0.6.7"
async-std = { version = "1.10.0", features = ["attributes"] }
tokio = { version = "1.24.1", features = ["rt", "macros"] }
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ use http_types::{Request, StatusCode};
use serde::de::DeserializeOwned;

use crate::client::request_strategy::{Outcome, RequestStrategy};
use crate::error::{ErrorResponse, StripeError};
use crate::error::StripeError;

pub type Response<T> = Pin<Box<dyn Future<Output = Result<T, StripeError>> + Send>>;

#[allow(dead_code)]
#[inline(always)]
pub(crate) fn ok<T: Send + 'static>(ok: T) -> Response<T> {
Box::pin(future::ready(Ok(ok)))
}

#[allow(dead_code)]
#[inline(always)]
pub(crate) fn err<T: Send + 'static>(err: StripeError) -> Response<T> {
Box::pin(future::ready(Err(err)))
Expand Down Expand Up @@ -51,6 +44,12 @@ impl AsyncStdClient {
}
}

impl Default for AsyncStdClient {
fn default() -> Self {
Self::new()
}
}

async fn send_inner(
client: &surf::Client,
mut request: Request,
Expand Down Expand Up @@ -103,10 +102,7 @@ async fn send_inner(
tries += 1;
let json_deserializer = &mut serde_json::Deserializer::from_slice(&bytes);
last_error = serde_path_to_error::deserialize(json_deserializer)
.map(|mut e: ErrorResponse| {
e.error.http_status = status.into();
StripeError::from(e.error)
})
.map(|e: stripe_types::Error| StripeError::Stripe(*e.error, status.into()))
.unwrap_or_else(StripeError::from);
last_status = Some(status);
last_retry_header = retry;
Expand Down
Loading

0 comments on commit 25077cb

Please sign in to comment.