Stripe.Request (stripity_stripe v2.17.2) View Source
A module for working with requests to the Stripe API.
Requests are composed in a functional manner. The request does not happen
until it is configured and passed to make_request/1
.
Currently encompasses only requests to the normal Stripe API. The OAuth endpoint is not yet supported.
Generally intended to be used internally, but can also be used by end-users to work around missing endpoints (if any).
At a minimum, a request must have the endpoint and method specified to be valid.
Link to this section Summary
Functions
Specify that a given path in the parameters should be cast to a simple ID.
Specify that a given set of parameters should be cast to a simple ID.
Normalise the argument to a simple Stripe ID.
Executes the request and returns the response for file uploads
Executes the request and returns the response.
Creates a new request.
Prefixes all :expand
values provided in opts
with the given prefix.
Specifies an endpoint for the request.
Specifies a method to use for the request.
Specify a single param to be included in the request.
Specifies the parameters to be used for the request.
Link to this section Types
Specs
error_code() :: :endpoint_fun_invalid_result | :invalid_endpoint
Specs
Link to this section Functions
Specs
Specify that a given path in the parameters should be cast to a simple ID.
Acts similar to cast_to_id/2
but specifies only one parameter to be cast,
by specifying its path (as in the Access
protocol). Used to cast nested
objects to their IDs.
Specs
Specify that a given set of parameters should be cast to a simple ID.
Sometimes, it may be convenient to allow end-users to pass in structs (say,
the card to charge) but the API requires only the ID of the object. This
function will ensure that before the request is made, the parameters
specified here will be cast to IDs – if the value of a parameter is a
struct with an :id
field, the value of that field will replace the struct
in the parameter list.
If the function is called multiple times, the set of parameters to cast to ID is merged between the multiple calls.
Specs
Normalise the argument to a simple Stripe ID.
Actively extracts the ID, given a struct with an :id
field, or returns the
binary if one is passed in.
Useful for eagerly getting the ID of an object passed in, for example when computing the endpoint to use:
def capture(id, params, opts) do
new_request(opts)
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}/capture")
...
Specs
make_file_upload_request(t()) :: {:ok, struct()} | {:error, Stripe.Error.t()}
Executes the request and returns the response for file uploads
Specs
make_request(t()) :: {:ok, struct()} | {:error, Stripe.Error.t()}
Executes the request and returns the response.
Specs
new_request(Stripe.options(), map()) :: t()
Creates a new request.
Optionally accepts options for the request, such as using a specific API key.
See t:Stripe.options
for details.
Specs
Prefixes all :expand
values provided in opts
with the given prefix.
When using object expansion on a list
function for a resource, the values must
be prefixed with data.
. This is required because the stripe api nests the
returned objects within data: {}
.
For all create
, update
, cancel
and retrieve
functions this is not required.
opts = [expand: ["balance_transaction"]]
request = prefix_expansions(%Request{opts: opts})
request.opts == ["data.balance_transaction"]
Specs
Specifies an endpoint for the request.
The endpoint should not include the v1
prefix or an initial slash, for
example put_endpoint(request, "charges")
.
The endpoint can be a binary or a function which takes the parameters of the query and returns an endpoint. The function is not evaluated until just before the request is made so the actual parameters can be specified after the endpoint.
Specs
put_method(t(), Stripe.API.method()) :: t()
Specifies a method to use for the request.
Accepts any of the standard HTTP methods as atoms, that is :get
, :post
,
:put
, :patch
or :delete
.
Specs
Specify a single param to be included in the request.
Specs
Specifies the parameters to be used for the request.
If the request is a POST request, these are encoded in the request body. Otherwise, they are encoded in the URL.
Calling this function multiple times will merge, not replace, the params currently specified.