livery_stripe_client (livery_stripe v0.1.0)

View Source

Low-level Stripe request pipeline over livery_client.

build/1 turns a config map into a livery_client value wired with the full resilience stack (timeout, retry with backoff, circuit breaker, and a concurrency gate). Build it once and cache/1 it in persistent_term so the breaker and gate state is shared across all callers.

do_request/4,5 is the single entry every domain module funnels through: it form-encodes parameters, attaches an Idempotency-Key on mutating requests (so a retried POST is deduplicated by Stripe rather than charged twice), runs the call, and maps the response to {ok, map()} or an error.

Errors are one of:

  • {stripe_error, Status, ErrorMap} - Stripe returned a non-2xx with a JSON error object,
  • {decode, Body} - a 2xx body that was not valid JSON,
  • any livery_client stack error as a value: timeout, circuit_open, overloaded, or a transport reason from the adapter.

Summary

Functions

Build a Stripe livery_client from a config map.

Cache a built client for cached/0 (shared, process-independent).

Fetch the cached client, or raise if none was configured.

Map a livery_client response to {ok, map()} or a Stripe error.

Whether a client has been cached.

Types

config()

-type config() :: map().

method()

-type method() :: get | post | put | delete.

params()

-type params() :: none | [{term(), term()}] | map().

result()

-type result() :: {ok, map()} | {error, term()}.

Functions

build(Cfg)

-spec build(config()) -> livery_client:client().

Build a Stripe livery_client from a config map.

cache(Client)

-spec cache(livery_client:client()) -> ok.

Cache a built client for cached/0 (shared, process-independent).

cached()

-spec cached() -> livery_client:client().

Fetch the cached client, or raise if none was configured.

decode(Resp)

-spec decode(livery_client:response()) -> result().

Map a livery_client response to {ok, map()} or a Stripe error.

do_request(Client, Method, Path, Params)

-spec do_request(livery_client:client(), method(), binary(), params()) -> result().

do_request/5

-spec do_request(livery_client:client(), method(), binary(), params(), map()) -> result().

has_client()

-spec has_client() -> boolean().

Whether a client has been cached.