View Source Stripe.API behaviour (stripity_stripe v3.2.0)

Low-level utilities for interacting with the Stripe API.

Usually the utilities in Stripe.Request are a better way to write custom interactions with the API.

Summary

Functions

Returns backoff in milliseconds.

A low level utility function to generate a new idempotency key for Idempotency-Key request header value.

In config.exs your implicit or explicit configuration is: config :stripity_stripe,

A low level utility function to make an OAuth request to the Stripe API

A low level utility function to make a direct request to the Stripe API

A low level utility function to make a direct request to the files Stripe API

Checks if an error is a problem that we should retry on. This includes both socket errors that may represent an intermittent problem and some special HTTP statuses.

Types

@type body() :: iodata() | {:multipart, list()}
@type headers() :: %{required(String.t()) => String.t()} | %{}
@type method() :: :get | :post | :put | :delete | :patch

Callbacks

Link to this callback

oauth_request(method, t, map)

View Source
@callback oauth_request(method(), String.t(), map()) :: {:ok, map()}

Functions

Link to this function

backoff(attempts, config)

View Source
@spec backoff(attempts :: non_neg_integer(), config :: Keyword.t()) ::
  non_neg_integer()

Returns backoff in milliseconds.

Link to this function

generate_idempotency_key()

View Source
@spec generate_idempotency_key() :: binary()

A low level utility function to generate a new idempotency key for Idempotency-Key request header value.

@spec json_library() :: module()

In config.exs your implicit or explicit configuration is: config :stripity_stripe,

json_library: Poison # defaults to Jason but can be configured to Poison
Link to this function

oauth_request(method, endpoint, body, api_key \\ nil, opts \\ [])

View Source

A low level utility function to make an OAuth request to the Stripe API

Link to this function

request(body, method, endpoint, headers, opts)

View Source
@spec request(map(), method(), String.t(), headers(), list()) ::
  {:ok, map()} | {:error, Stripe.Error.t()}

A low level utility function to make a direct request to the Stripe API

Setting the api key

request(%{}, :get, "/customers", %{}, api_key: "bogus key")

Setting api version

The api version defaults to 2022-11-15 but a custom version can be passed in as follows:

request(%{}, :get, "/customers", %{}, api_version: "2018-11-04")

Connect Accounts

If you'd like to make a request on behalf of another Stripe account utilizing the Connect program, you can pass the other Stripe account's ID to the request function as follows:

request(%{}, :get, "/customers", %{}, connect_account: "acc_134151")
Link to this function

request_file_upload(body, method, endpoint, headers, opts)

View Source
@spec request_file_upload(map(), method(), String.t(), headers(), list()) ::
  {:ok, map()} | {:error, Stripe.Error.t()}

A low level utility function to make a direct request to the files Stripe API

Link to this function

should_retry?(response, attempts \\ 0, config \\ [])

View Source
@spec should_retry?(
  http_success() | http_failure(),
  attempts :: non_neg_integer(),
  config :: Keyword.t()
) :: boolean()

Checks if an error is a problem that we should retry on. This includes both socket errors that may represent an intermittent problem and some special HTTP statuses.