Accrue.Billing.Trial (accrue v0.2.0)

Copy Markdown View Source

Trial end normalization (D3-38).

Accepts the ergonomic Accrue shapes and produces what Stripe's trial_end parameter expects:

  • :now"now" (Stripe magic string — ends trial immediately)
  • %DateTime{} → unix seconds
  • {:days, N} → unix seconds at Accrue.Clock.utc_now/0 + N days
  • %Duration{} → unix seconds at Accrue.Clock.utc_now/0 + duration

Integers are deliberately rejected. A plain 1_800_000_000 is almost always a call-site bug (e.g. DateTime.to_unix(dt) inlined at the call site, making the value impossible to reason about at read time). We raise ArgumentError so the bug surfaces loudly. Likewise for the Stripe-native :trial_period_days atom — Accrue prefers the {:days, N} sugar because it is self-documenting.

Summary

Functions

normalize_trial_end(dt)

@spec normalize_trial_end(term()) :: String.t() | pos_integer()