Phase 3 Plan 04 subscription write surface (BILL-03/04/06/07/08/09/10).
Every function here is exposed on Accrue.Billing via defdelegate
(wired in Plan 01 Task 4). All public functions follow the dual-API
foo/n + foo!/n pattern and emit an accrue_events row inside the
same Repo.transact/2 as the DB mutation (EVT-04 invariant).
The intent_result tagged return (D3-06..12) is used for ops that can
surface a requires_action PaymentIntent (subscribe, swap_plan,
cancel when invoice_now: true). Non-intent ops return plain
{:ok, %Subscription{}}.
Summary
Functions
Creates a free-tier ("comped") subscription with a 100%-off coupon applied. Skips the payment_method guard since there is nothing to charge.
Raising variant of comp_subscription/3.
Creates a subscription for the given billable (or %Customer{}) against
the configured processor. Returns intent_result(Subscription.t()).
Raising variant of subscribe/3.
Functions
@spec cancel( Accrue.Billing.Subscription.t(), keyword() ) :: {:ok, Accrue.Billing.Subscription.t()} | {:ok, :requires_action, map()} | {:error, term()}
@spec cancel!( Accrue.Billing.Subscription.t(), keyword() ) :: Accrue.Billing.Subscription.t()
@spec cancel_at_period_end( Accrue.Billing.Subscription.t(), keyword() ) :: {:ok, Accrue.Billing.Subscription.t()} | {:error, term()}
@spec cancel_at_period_end!( Accrue.Billing.Subscription.t(), keyword() ) :: Accrue.Billing.Subscription.t()
@spec comp_subscription(term(), term(), keyword()) :: {:ok, Accrue.Billing.Subscription.t()} | {:error, term()}
Creates a free-tier ("comped") subscription with a 100%-off coupon applied. Skips the payment_method guard since there is nothing to charge.
The coupon referenced by coupon_id must exist in the processor's
dashboard. Defaults to "accrue_comp_100_forever"; host apps create
this once via Accrue.Billing.create_coupon/2 (landed in 04-05) or
the Stripe Dashboard.
@spec comp_subscription!(term(), term(), keyword()) :: Accrue.Billing.Subscription.t()
Raising variant of comp_subscription/3.
@spec get_subscription( String.t(), keyword() ) :: {:ok, Accrue.Billing.Subscription.t()} | {:error, :not_found}
@spec get_subscription!( String.t(), keyword() ) :: Accrue.Billing.Subscription.t()
@spec pause( Accrue.Billing.Subscription.t(), keyword() ) :: {:ok, Accrue.Billing.Subscription.t()} | {:error, term()}
@spec pause!( Accrue.Billing.Subscription.t(), keyword() ) :: Accrue.Billing.Subscription.t()
@spec preview_upcoming_invoice( Accrue.Billing.Subscription.t() | Accrue.Billing.Customer.t(), keyword() ) :: {:ok, Accrue.Billing.UpcomingInvoice.t()} | {:error, term()}
@spec preview_upcoming_invoice!( Accrue.Billing.Subscription.t() | Accrue.Billing.Customer.t(), keyword() ) :: Accrue.Billing.UpcomingInvoice.t()
@spec resume( Accrue.Billing.Subscription.t(), keyword() ) :: {:ok, Accrue.Billing.Subscription.t()} | {:error, term()}
@spec resume!( Accrue.Billing.Subscription.t(), keyword() ) :: Accrue.Billing.Subscription.t()
@spec subscribe(term(), term(), keyword()) :: {:ok, Accrue.Billing.Subscription.t()} | {:ok, :requires_action, map()} | {:error, term()}
Creates a subscription for the given billable (or %Customer{}) against
the configured processor. Returns intent_result(Subscription.t()).
@spec subscribe!(term(), term(), keyword()) :: Accrue.Billing.Subscription.t()
Raising variant of subscribe/3.
@spec swap_plan(Accrue.Billing.Subscription.t(), String.t(), keyword()) :: {:ok, Accrue.Billing.Subscription.t()} | {:ok, :requires_action, map()} | {:error, term()}
@spec swap_plan!(Accrue.Billing.Subscription.t(), String.t(), keyword()) :: Accrue.Billing.Subscription.t()
@spec unpause( Accrue.Billing.Subscription.t(), keyword() ) :: {:ok, Accrue.Billing.Subscription.t()} | {:error, term()}
@spec unpause!( Accrue.Billing.Subscription.t(), keyword() ) :: Accrue.Billing.Subscription.t()
@spec update_quantity(Accrue.Billing.Subscription.t(), pos_integer(), keyword()) :: {:ok, Accrue.Billing.Subscription.t()} | {:error, term()}
@spec update_quantity!(Accrue.Billing.Subscription.t(), pos_integer(), keyword()) :: Accrue.Billing.Subscription.t()