MishkaPay.Subscription.Change (Mishka Pay v0.0.1)

Copy Markdown View Source

A change to a running subscription: a new plan, a new quantity (seats), or both, and how the provider bills the difference. A guarded_struct, given to MishkaPay.change_subscription/1 and MishkaPay.preview_subscription_change/1.

  • :provider, :tenant, :subscription_id: which subscription, with whose keys.
  • :item_id: which of its items changes (si_... at Stripe, MishkaPay.Price's :item_id); left out, its only item.
  • :price_id: the new plan, a catalog price; left out, the plan stays.
  • :quantity: the new quantity; left out, it stays.
  • :proration: how the difference is billed: :create_prorations (the provider's default: credit and charge wait for the next invoice), :always_invoice (bill it now) or :none (no credit, no charge until the next period).
  • :proration_date: the moment the difference is counted from; give the one a preview used, so the change bills exactly what the preview showed. It goes only with prorations, and not with billing_cycle_anchor: :now (a new period has nothing to prorate from).
  • :billing_cycle_anchor: :now starts a new period at once; :unchanged (the default) keeps the dates.
  • :payment_behavior: what happens when charging the difference fails: :allow_incomplete, :error_if_incomplete, :pending_if_incomplete or :default_incomplete; left out, the provider's default.

Every option left out is the provider's own default.

Summary

Types

t()

The struct that builder/1 returns.

Functions

A sample %MishkaPay.Subscription.Change{} populated from defaults + type-based fallbacks.

Types

t()

@type t() :: %MishkaPay.Subscription.Change{
  billing_cycle_anchor: (:now | :unchanged) | nil,
  item_id: String.t() | nil,
  payment_behavior:
    (:allow_incomplete
     | :error_if_incomplete
     | :pending_if_incomplete
     | :default_incomplete)
    | nil,
  price_id: String.t() | nil,
  proration: (:create_prorations | :always_invoice | :none) | nil,
  proration_date: DateTime.t() | nil,
  provider: String.t(),
  quantity: pos_integer() | nil,
  subscription_id: String.t(),
  tenant: term() | nil
}

The struct that builder/1 returns.

FieldTypeRequiredDefaultDescriptionDerives
:providerString.t()yessanitize(trim) validate(not_nil_value, string, not_empty)
:tenantterm() | nilno
:subscription_idString.t()yessanitize(trim) validate(not_nil_value, string, not_empty)
:item_idString.t() | nilnosanitize(trim) validate(string, not_empty)
:price_idString.t() | nilnosanitize(trim) validate(string, not_empty)
:quantitypos_integer() | nilnovalidate(integer, min_len=1)
:proration:create_prorations | :always_invoice | :none | nilnovalidate(enum=Atom[create_prorations::always_invoice::none])<br>validator {MishkaPay.Subscription, :proration}
:proration_dateDateTime.t() | nilnovalidate(struct)
:billing_cycle_anchor:now | :unchanged | nilnovalidate(enum=Atom[now::unchanged])<br>validator {MishkaPay.Subscription, :anchor}
:payment_behavior:allow_incomplete | :error_if_incomplete | :pending_if_incomplete | :default_incomplete | nilnovalidate(enum=Atom[allow_incomplete::error_if_incomplete::pending_if_incomplete::default_incomplete])<br>validator {MishkaPay.Subscription, :payment_behavior}

Functions

builder(attrs_or_input, error \\ false)

enforce_keys()

enforce_keys(field)

example()

A sample %MishkaPay.Subscription.Change{} populated from defaults + type-based fallbacks.

keys()

keys(field)