Expand description
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 to determine which fields are required for either request.
Note: We have an extensive collection of examples which are interspersed in the documentation. Any time an API is used in an example it is highlighted in the docs for that item. You can also find all the raw examples in the
examples
directory. Please have a look at those for inspiration or ideas on how to get started.
§Idempotency / Request Strategies
This library provides a few basic request strategies for making requests to the Stripe API. This is currently implemented as an enum with the following variants:
RequestStrategy::Once
: This is the default strategy. It will make a request to the Stripe API and, whether the request fails or not, will simply return the response.RequestStrategy::Idempotent
: This strategy will make a request to stripe api, passing the provided key to Stripe as theIdempotency-Key
header, ensuring that the request is idempotent. If the request fails, you may retry it.RequestStrategy::Retry
: Make a request to the Stripe API and, if the request fails, retry it up to n times with a timeout. The idempotency key is generated automatically and is stable across retries.RequestStrategy::ExponentialBackoff
: Make a request to the Stripe API and, if the request fails, retry it up to n times with exponential backoff. The idempotency key is generated automatically and is stable across retries.
Want to implement your own? If it is a common strategy, please consider opening a PR to add it to the library. Otherwise, we are open to turning this into an open trait so that you can implement your own strategy.
Structs§
- Account
Id - ApiErrors
- Application
Id - Client
- A client for making Stripe API requests.
- Client
Builder - Configuration for a Stripe client.
- Customized
Stripe Request - The request specification used by a compatible Stripe client to make a request.
- Idempotency
Key - Represents valid idempotency key
- List
Paginator - Stream designed to support pagination.
Enums§
- ApiErrors
Code - For some errors that could be handled programmatically, a short string indicating the error code reported.
- ApiErrors
Type - The type of error returned.
One of
api_error
,card_error
,idempotency_error
, orinvalid_request_error
. - Idempotent
KeyError - Error that can be returned when constructing
IdempotencyKey
- Request
Strategy - Possible strategies for sending Stripe API requests, including retry behavior and use of idempotency keys.
- Stripe
Error - An error encountered when communicating with the Stripe API.
Traits§
- Pagination
Ext - An extension trait to allow converting
List<T>
andSearchList<T>
into a type that can be paginated. Not meant to be implemented by any other types. - Stripe
Request - Define how to convert structs into the data required to make a specific Stripe API call.