stripe/
lib.rs

1// Copyright 2019 Wyyerd Group, LLC.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9#![doc(html_root_url = "https://docs.rs/async-stripe/")]
10#![recursion_limit = "128"]
11
12//! This crate provides Rust bindings to the Stripe HTTP API.
13//!
14//! ## Getting Started
15//!
16//! To get started, we need to create a [Client]:
17//!
18//! ```
19//! let client = stripe::Client::new("sk_test_YOUR_STRIPE_SECRET");
20//! ```
21//!
22//! Then we can begin making requests as we'd like.  Most Stripe requests accept
23//! many optional parameters, so we usually get the `::new(...)` with any required
24//! params and then set the ones we want from there.
25//!
26//! Most requests for creating or updating a Stripe object use the same Rust struct,
27//! so you may frequently need to refer to the [official API docs](https://stripe.com/docs/api)
28//! to determine which fields are required for either request.
29//!
30//! > **Note:** We have an extensive collection of examples which are interspersed in
31//! > the documentation. Any time an API is used in an example it is highlighted in the
32//! > docs for that item. You can also find all the raw examples in the `examples` directory.
33//! > Please have a look at those for inspiration or ideas on how to get started.
34//!
35//! ## Idempotency / Request Strategies
36//!
37//! This library provides a few basic request strategies for making requests to the Stripe API.
38//! This is currently implemented as an enum with the following variants:
39//!
40//! - [`RequestStrategy::Once`]: This is the default strategy. It will make a request to the Stripe API and,
41//!                              whether the request fails or not, will simply return the response.
42//! - [`RequestStrategy::Idempotent`]: This strategy will make a request to stripe api, passing the provided
43//!                                    key to Stripe as the `Idempotency-Key` header, ensuring that the request
44//!                                    is idempotent. If the request fails, you may retry it.
45//! - [`RequestStrategy::Retry`]: Make a request to the Stripe API and, if the request fails, retry it up to n
46//!                               times with a timeout. The idempotency key is generated  automatically and is
47//!                               stable across retries.
48//! - [`RequestStrategy::ExponentialBackoff`]: Make a request to the Stripe API and, if the request fails, retry
49//!                                            it up to n times with exponential backoff. The idempotency key is
50//!                                            generated automatically and is stable across retries.
51//!
52//! > Want to implement your own? If it is a common strategy, please consider opening a PR to add it to the library.
53//! > Otherwise, we are open to turning this into an open trait so that you can implement your own strategy.
54
55#![allow(clippy::large_enum_variant)]
56#![warn(clippy::missing_panics_doc)]
57#![forbid(unsafe_code)]
58// Workaround
59#![allow(ambiguous_glob_reexports)]
60#![cfg_attr(docsrs, feature(doc_auto_cfg))]
61
62// Give a clear error when a required runtime error is not present. Would be better for this
63// to be a fatal error preventing emission of further compile errors relating to lack of
64// a runtime feature, but that does not seem currently possible:
65// https://github.com/rust-lang/rust/issues/68838
66
67mod client;
68mod error;
69mod ids;
70mod params;
71mod resources;
72
73// N.B. Ideally we would support both a blocking client and
74//      an async client without a feature flag, but the originally
75//      discussed solution requires Generic Associated Types--
76//      instead we provide an async client only a feature flag.
77//
78// See https://github.com/wyyerd/stripe-rs/issues/24#issuecomment-451514187
79// See https://github.com/rust-lang/rust/issues/44265
80pub use crate::client::*;
81pub use crate::error::{ErrorCode, ErrorType, RequestError, StripeError, WebhookError};
82pub use crate::ids::*;
83pub use crate::params::{
84    Expandable, Headers, IdOrCreate, List, Metadata, Object, RangeBounds, RangeQuery, SearchList,
85    Timestamp,
86};
87pub use crate::resources::*;