livery_stripe (livery_stripe v0.1.0)

View Source

Public facade for the Stripe client.

Configuration is read from the livery_stripe application environment, with secrets overridable from the OS environment (STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET). At app start a shared client is built and cached; the convenience functions here use that cached client. For an explicit client (multi-account, tests) call the domain modules (livery_stripe_customer, livery_stripe_subscription, ...) directly.

{ok, Customer} = livery_stripe:create_customer(#{email => <<"a@b.c">>}),
{ok, Session}  = livery_stripe:subscription_checkout(#{
    customer => maps:get(<<"id">>, Customer),
    plan => pro, billing_period => monthly,
    success_url => <<"https://app/billing?success=1">>,
    cancel_url  => <<"https://app/billing?canceled=1">>
}).

Summary

Functions

The cached shared client (raises if not configured).

The effective config map: livery_stripe app env, with secret_key and webhook_secret overridden by STRIPE_SECRET_KEY / STRIPE_WEBHOOK_SECRET when those OS variables are set.

Build and cache the shared client from config/0.

Build and cache the shared client from an explicit config map.

Resolve a configured price id for a plan and billing period, e.g. price_id(pro, monthly) looks up the pro_monthly key under the prices config map (mirrors friendpaste's plan->price mapping).

Replace the cached shared client.

End-to-end subscription checkout, the friendpaste flow: resolve the price from plan + billing_period, then create a subscription-mode session.

Types

result()

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

Functions

cancel_subscription(Id)

-spec cancel_subscription(binary()) -> result().

client()

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

The cached shared client (raises if not configured).

config()

-spec config() -> map().

The effective config map: livery_stripe app env, with secret_key and webhook_secret overridden by STRIPE_SECRET_KEY / STRIPE_WEBHOOK_SECRET when those OS variables are set.

configure()

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

Build and cache the shared client from config/0.

configure(Cfg)

-spec configure(map()) -> livery_client:client().

Build and cache the shared client from an explicit config map.

create_checkout_session(Params)

-spec create_checkout_session(map() | list()) -> result().

create_customer(Params)

-spec create_customer(map() | list()) -> result().

create_portal_session(Params)

-spec create_portal_session(map()) -> result().

create_subscription(Params)

-spec create_subscription(map() | list()) -> result().

get_customer(Id)

-spec get_customer(binary()) -> result().

get_subscription(Id)

-spec get_subscription(binary()) -> result().

price_id(Plan, Period)

-spec price_id(atom() | binary(), atom() | binary()) ->
                  {ok, binary()} | {error, {price_not_configured, atom()}}.

Resolve a configured price id for a plan and billing period, e.g. price_id(pro, monthly) looks up the pro_monthly key under the prices config map (mirrors friendpaste's plan->price mapping).

set_client(Client)

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

Replace the cached shared client.

subscription_checkout/1

-spec subscription_checkout(map()) -> result().

End-to-end subscription checkout, the friendpaste flow: resolve the price from plan + billing_period, then create a subscription-mode session.

Params requires customer, plan, billing_period, success_url, cancel_url; optional metadata, quantity.

update_customer(Id, Params)

-spec update_customer(binary(), map() | list()) -> result().

update_subscription(Id, Params)

-spec update_subscription(binary(), map() | list()) -> result().