Optional fluent builder for LatticeStripe.SubscriptionSchedule creation params.
This is a companion to the raw map API — not a replacement. Developers who
prefer to construct deeply-nested phase params via a pipe chain can use this
builder to avoid manually typing string keys and prevent typos. The output of
build/1 is a plain string-keyed map that passes directly to
LatticeStripe.SubscriptionSchedule.create/3.
Usage
Mode 1: customer + phases
Build a new schedule from scratch with an explicit phase timeline.
alias LatticeStripe.Builders.SubscriptionSchedule, as: SSBuilder
params =
SSBuilder.new()
|> SSBuilder.customer("cus_1234567890")
|> SSBuilder.start_date(:now)
|> SSBuilder.end_behavior(:release)
|> SSBuilder.add_phase(
SSBuilder.phase_new()
|> SSBuilder.phase_items([%{"price" => "price_1234567890", "quantity" => 1}])
|> SSBuilder.phase_iterations(12)
|> SSBuilder.phase_proration_behavior(:create_prorations)
|> SSBuilder.phase_build()
)
|> SSBuilder.build()
# Pass to the resource layer
LatticeStripe.SubscriptionSchedule.create(client, params)Mode 2: from_subscription
Convert an existing Subscription into a schedule whose first phase captures the subscription's current state.
params =
SSBuilder.new()
|> SSBuilder.from_subscription("sub_1234567890")
|> SSBuilder.build()
LatticeStripe.SubscriptionSchedule.create(client, params)Important: The two modes are mutually exclusive. Mixing customer/phases
fields with from_subscription produces a Stripe 400 error. The builder does
not client-side-validate this constraint — Stripe's error is already actionable.
Nil omission
build/1 and phase_build/1 automatically strip fields with nil values,
so setting only the fields you need is safe — unused fields do not appear in
the output map.
Atom values
Stripe enum fields (:release, :create_prorations, :resume, etc.) are
automatically converted to their string equivalents in build/1 and
phase_build/1 output.
Summary
Functions
Append a phase to the schedule.
Produce the final string-keyed params map.
Set the customer ID (Mode 1 — customer + phases).
Set the end behavior atom or string (e.g. :release, :cancel).
Set the source subscription ID (Mode 2 — from_subscription).
Set schedule-level metadata map.
Create a new empty SubscriptionSchedule builder accumulator.
Set the add_invoice_items list on a phase.
Set the application fee percent for this phase.
Set the automatic_tax map for this phase.
Set the billing cycle anchor behavior.
Set the billing_thresholds map for this phase.
Produce the final string-keyed map for a phase.
Set the collection method (e.g. :charge_automatically, :send_invoice).
Set the currency code for this phase.
Set the default payment method ID for this phase.
Set the default_tax_rates list for this phase.
Set the description for this phase.
Set the discounts list for this phase.
Set the end date for this phase. Accepts :now, a Unix timestamp integer, or a string.
Set the invoice_settings map for this phase.
Set the items list on a phase.
Set the number of iterations for this phase.
Set metadata map for this phase.
Create a new empty Phase accumulator.
Set the on_behalf_of account ID for this phase.
Set the pause_collection map for this phase.
Set the prebilling map for this phase.
Set proration behavior atom or string (e.g. :create_prorations, :none).
Set the start date for this phase. Accepts :now, a Unix timestamp integer, or a string.
Set the transfer_data map for this phase.
Set trial_continuation behavior (e.g. :resume, :none).
Set the trial end date (Unix timestamp) for this phase.
Set the schedule start date. Accepts :now, a Unix timestamp integer, or a string.
Types
Functions
Append a phase to the schedule.
Accepts either a plain string-keyed map (output of phase_build/1) or a
%Phase{} struct (the result of phase_new/0 plus setter calls). If given a
struct, phase_build/1 is called internally before appending.
Produce the final string-keyed params map.
Nil values are omitted. Atom enum values are converted to strings. The
"phases" key is omitted when no phases have been added.
Set the customer ID (Mode 1 — customer + phases).
Set the end behavior atom or string (e.g. :release, :cancel).
Set the source subscription ID (Mode 2 — from_subscription).
Set schedule-level metadata map.
@spec new() :: t()
Create a new empty SubscriptionSchedule builder accumulator.
@spec phase_add_invoice_items( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), list() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the add_invoice_items list on a phase.
@spec phase_application_fee_percent( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), number() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the application fee percent for this phase.
@spec phase_automatic_tax( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), map() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the automatic_tax map for this phase.
@spec phase_billing_cycle_anchor( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), atom() | String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the billing cycle anchor behavior.
@spec phase_billing_thresholds( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), map() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the billing_thresholds map for this phase.
@spec phase_build(LatticeStripe.Builders.SubscriptionSchedule.Phase.t()) :: map()
Produce the final string-keyed map for a phase.
Nil values are omitted. Atom enum values are converted to strings. Empty
items and add_invoice_items lists are omitted.
@spec phase_collection_method( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), atom() | String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the collection method (e.g. :charge_automatically, :send_invoice).
@spec phase_currency( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the currency code for this phase.
@spec phase_default_payment_method( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the default payment method ID for this phase.
@spec phase_default_tax_rates( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), list() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the default_tax_rates list for this phase.
@spec phase_description( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the description for this phase.
@spec phase_discounts(LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), list()) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the discounts list for this phase.
@spec phase_end_date( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), :now | integer() | String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the end date for this phase. Accepts :now, a Unix timestamp integer, or a string.
@spec phase_invoice_settings( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), map() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the invoice_settings map for this phase.
@spec phase_items(LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), list()) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the items list on a phase.
@spec phase_iterations( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), integer() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the number of iterations for this phase.
@spec phase_metadata(LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), map()) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set metadata map for this phase.
@spec phase_new() :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Create a new empty Phase accumulator.
@spec phase_on_behalf_of( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the on_behalf_of account ID for this phase.
@spec phase_pause_collection( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), map() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the pause_collection map for this phase.
@spec phase_prebilling(LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), map()) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the prebilling map for this phase.
@spec phase_proration_behavior( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), atom() | String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set proration behavior atom or string (e.g. :create_prorations, :none).
@spec phase_start_date( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), :now | integer() | String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the start date for this phase. Accepts :now, a Unix timestamp integer, or a string.
@spec phase_transfer_data( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), map() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the transfer_data map for this phase.
@spec phase_trial_continuation( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), atom() | String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set trial_continuation behavior (e.g. :resume, :none).
@spec phase_trial_end( LatticeStripe.Builders.SubscriptionSchedule.Phase.t(), integer() | String.t() ) :: LatticeStripe.Builders.SubscriptionSchedule.Phase.t()
Set the trial end date (Unix timestamp) for this phase.
Set the schedule start date. Accepts :now, a Unix timestamp integer, or a string.