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
// 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/stripe-rust/")] #![recursion_limit = "128"] //! This crate provides Rust bindings to the Stripe HTTP API. //! //! ## Getting Started //! //! To get started, we need to create a client: //! //! ```rust //! 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. //! //! ```rust,no_run //! /* Creating a Stripe Charge */ //! //! # let client = stripe::Client::new("sk_test_YOUR_STRIPE_SECRET"); //! 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, .. } //! ``` //! //! ```rust,no_run //! /* Listing Stripe Charges */ //! //! # let client = stripe::Client::new("sk_test_YOUR_STRIPE_SECRET"); //! let params = stripe::ListCharges::new(); //! let charges = stripe::Charge::list(&client, params).unwrap(); //! println!("{:?}", charges); // => List { data: [Charge { id: "ch_12345", .. }] } //! ``` #![allow(clippy::map_clone)] // N.B. not sure if this rule will break compatibility with older rust versions we might want to support #![allow(clippy::needless_pass_by_value)] #![allow(clippy::large_enum_variant)] mod client { pub mod r#async; #[cfg(all(feature = "blocking", not(feature = "async")))] pub mod blocking; } // Re-export `pub mod async` to be backward-compatible with 0.11.x #[cfg(feature = "async")] pub use client::r#async; 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::{Error, ErrorCode, ErrorType, RequestError, WebhookError}; pub use crate::ids::*; pub use crate::params::{ Expandable, Headers, IdOrCreate, List, Metadata, Object, RangeBounds, RangeQuery, Timestamp, }; pub use crate::resources::*; #[cfg(all(feature = "blocking", not(feature = "async")))] 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(not(feature = "blocking"), feature = "async"))] mod config { pub(crate) use crate::client::r#async::{err, ok}; pub type Client = crate::client::r#async::Client; pub type Response<T> = crate::client::r#async::Response<T>; } pub use self::config::Client; pub use self::config::Response;