PaperTiger.Connect (PaperTiger v1.1.2)

Copy Markdown View Source

Request-scoped helpers for Stripe Connect behavior.

Stripe's Stripe-Account header is per request. PaperTiger models that by storing the connected account ID in the process dictionary for the duration of a request, then using it as part of the ETS storage namespace for normal resources. Platform-owned resources can temporarily opt back into the base namespace with without_account/1.

Summary

Functions

Returns true when an ID looks like a Stripe connected account ID.

Clears any connected account from the current process.

Returns the connected account ID for the current request, if any.

Sets the connected account for the current process.

Returns the storage namespace for the current sandbox + connected account.

Returns the storage namespace for a base sandbox namespace.

Runs fun with the given connected account ID in the process dictionary.

Runs fun in platform scope even if the request is account-scoped.

Types

account_id()

@type account_id() :: String.t()

storage_namespace()

@type storage_namespace() :: pid() | :global | {pid() | :global, account_id()}

Functions

account_id?(id)

@spec account_id?(term()) :: boolean()

Returns true when an ID looks like a Stripe connected account ID.

clear_account()

@spec clear_account() :: :ok

Clears any connected account from the current process.

current_account()

@spec current_account() :: account_id() | nil

Returns the connected account ID for the current request, if any.

put_account(account_id)

@spec put_account(account_id()) :: :ok

Sets the connected account for the current process.

storage_namespace()

@spec storage_namespace() :: storage_namespace()

Returns the storage namespace for the current sandbox + connected account.

storage_namespace(base_namespace)

@spec storage_namespace(pid() | :global) :: storage_namespace()

Returns the storage namespace for a base sandbox namespace.

with_account(account_id, fun)

@spec with_account(account_id() | nil, (-> result)) :: result when result: term()

Runs fun with the given connected account ID in the process dictionary.

without_account(fun)

@spec without_account((-> result)) :: result when result: term()

Runs fun in platform scope even if the request is account-scoped.