Pure Accrue.Money math for platform fee computation.
Caller-inject semantics. This helper computes the platform fee amount
as a value. It does NOT auto-apply to charges or transfers. Callers thread
the result into application_fee_amount: on their own charge/transfer
calls so the fee line is always auditable at the call site.
Computation order
Stripe's documented order of operations for a flat-rate platform fee (percent + fixed, optionally clamped):
- Percent component —
gross * (percent / 100)in minor units, with banker's rounding (:half_even) at integer precision. Minor units are integer across all currencies, so this is currency-exponent agnostic: JPY (0-decimal), USD (2-decimal), and KWD (3-decimal) all round at the same integer boundary. - Fixed component — if present, added verbatim (same currency).
- Floor clamp — if
:minis present and the result is below it, raise to the min. - Ceiling clamp — if
:maxis present and the result exceeds it, lower to the max.
Zero gross short-circuits to zero fee before any math.
Config
Opts override per-call; unset opts fall back to
Accrue.Config.get!(:connect) |> Keyword.get(:platform_fee).
Summary
Functions
Bang variant. Raises on validation failure.
Types
@type opts() :: [ percent: Decimal.t(), fixed: Accrue.Money.t() | nil, min: Accrue.Money.t() | nil, max: Accrue.Money.t() | nil ]
Functions
@spec compute( Accrue.Money.t(), keyword() ) :: {:ok, Accrue.Money.t()} | {:error, Exception.t()}
@spec compute!( Accrue.Money.t(), keyword() ) :: Accrue.Money.t()
Bang variant. Raises on validation failure.