1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
// Copyright 2019 Wyyerd Group, LLC.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![doc(html_root_url = "https://docs.rs/async-stripe/")]
#![recursion_limit = "128"]
//! This crate provides Rust bindings to the Stripe HTTP API.
//!
//! ## Getting Started
//!
//! To get started, we need to create a client:
//!
//! ```
//! let client = stripe::Client::new("sk_test_YOUR_STRIPE_SECRET");
//! ```
//!
//! Then we can begin making requests as we'd like. Most Stripe requests accept
//! many optional parameters, so we usually get the `::new(...)` with any required
//! params and then set the ones we want from there.
//!
//! Most requests for creating or updating a Stripe object use the same Rust struct,
//! so you may frequently need to refer to the [official API docs](https://stripe.com/docs/api)
//! to determine which fields are required for either request.
//!
//! ```
//! /* Creating a Stripe Charge */
//! # #[cfg(feature = "blocking")]
//! # {
//! # let client = stripe::Client::from_url("http://localhost:12111", "sk_test_123");
//! let token = "tok_ID_FROM_CHECKOUT".parse().unwrap();
//! let mut params = stripe::CreateCharge::new();
//! // NOTE: Stripe represents currency in the lowest denominations (e.g. cents)
//! params.amount = Some(1095); // e.g. $10.95
//! params.source = Some(stripe::ChargeSourceParams::Token(token));
//!
//! // Example: Override currency to be in Canadian Dollars
//! params.currency = Some(stripe::Currency::CAD);
//! let charge = stripe::Charge::create(&client, params).unwrap();
//! println!("{:?}", charge); // => Charge { id: "ch_12345", amount: 1095, .. }
//! # }
//! ```
//!
//! ```
//! /* Listing Stripe Charges */
//! # #[cfg(feature = "blocking")]
//! # {
//! # let client = stripe::Client::from_url("http://localhost:12111", "sk_test_123");
//! let params = stripe::ListCharges::new();
//! let charges = stripe::Charge::list(&client, params).unwrap();
//! println!("{:?}", charges); // => List { data: [Charge { id: "ch_12345", .. }] }
//! # }
//! ```
//!
//! > **A note about creating card tokens**: Stripe introduced the [PaymentIntent](crate::PaymentIntent) api
//! > to replace the old token and charge API. This library only supports the former. To migrate, you can
//! > have a look at [the official migration guide](https://stripe.com/docs/payments/payment-intents/migration).
#![allow(clippy::map_clone)]
#![allow(clippy::large_enum_variant)]
#![warn(clippy::unwrap_used)]
#![forbid(unsafe_code)]
mod client {
#[cfg(any(
feature = "runtime-tokio-hyper",
feature = "runtime-tokio-hyper-rustls",
feature = "runtime-blocking",
feature = "runtime-blocking-rustls",
))]
pub mod tokio;
#[cfg(feature = "runtime-async-std-surf")]
pub mod async_std;
#[cfg(any(feature = "runtime-blocking", feature = "runtime-blocking-rustls"))]
pub mod blocking;
}
mod error;
mod ids;
mod params;
mod resources;
// N.B. Ideally we would support both a blocking client and
// an async client without a feature flag, but the originally
// discussed solution requires Generic Associated Types--
// instead we provide an async client only a feature flag.
//
// See https://github.com/wyyerd/stripe-rs/issues/24#issuecomment-451514187
// See https://github.com/rust-lang/rust/issues/44265
pub use crate::error::{ErrorCode, ErrorType, RequestError, StripeError, WebhookError};
pub use crate::ids::*;
pub use crate::params::{
Expandable, Headers, IdOrCreate, List, Metadata, Object, RangeBounds, RangeQuery, Timestamp,
};
pub use crate::resources::*;
#[cfg(any(feature = "runtime-blocking", feature = "runtime-blocking-rustls"))]
mod config {
pub(crate) use crate::client::blocking::{err, ok};
pub type Client = crate::client::blocking::Client;
/// An alias for `Result`.
///
/// If `blocking` is enabled, defined as:
///
/// ```rust,ignore
/// type Response<T> = Result<T, Error>;
/// ```
///
/// If the `async` feature is enabled, this type is defined as:
///
/// ```rust,ignore
/// type Response<T> = Box<dyn Future<Result<T, Error>>>;
/// ```
///
pub type Response<T> = crate::client::blocking::Response<T>;
}
#[cfg(any(feature = "runtime-tokio-hyper", feature = "runtime-tokio-hyper-rustls"))]
mod config {
pub(crate) use crate::client::tokio::{err, ok};
pub type Client = crate::client::tokio::Client;
pub type Response<T> = crate::client::tokio::Response<T>;
}
#[cfg(feature = "runtime-async-std-surf")]
mod config {
pub(crate) use crate::client::async_std::{err, ok};
pub type Client = crate::client::async_std::Client;
pub type Response<T> = crate::client::async_std::Response<T>;
}
pub use self::config::Client;
pub use self::config::Response;