livery_stripe (livery_stripe v0.1.0)
View SourcePublic 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
Functions
-spec client() -> livery_client:client().
The cached shared client (raises if not configured).
-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.
-spec configure() -> livery_client:client().
Build and cache the shared client from config/0.
-spec configure(map()) -> livery_client:client().
Build and cache the shared client from an explicit config map.
-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).
-spec set_client(livery_client:client()) -> ok.
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.
Params requires customer, plan, billing_period, success_url,
cancel_url; optional metadata, quantity.