recurly v0.2.2 Recurly.Subscription

Module for handling subscriptions in Recurly. See the developer docs on subscriptions for more details

TODO implement postpone and reactivate

Summary

Functions

Cancels a given subscription. See docs on canceling a subscription

Gives the count of subscriptions on the server given options

Creates a subscription from a changeset. Supports nesting the account

Finds a subscription given a subscription uuid. Returns the subscription or an error

Gives the first subscription returned given options

Generates the path to a subscription given the uuid

Creates a stream of subscriptions given some options

Terminates a given subscription. See docs on terminating a subscription

Functions

cancel(subscription)

Cancels a given subscription. See docs on canceling a subscription.

TODO more docs

count(options \\ [])

Gives the count of subscriptions on the server given options

Parameters

Examples

# suppose we want to count all subscriptions
case Recurly.Subscription.count() do
  {:ok, count} ->
    # count => 176 (or some integer)
  {:error, err} ->
    # error occurred
end

# or maybe we wan to count just active subscriptions
case Recurly.Subscription.count(state: :active) do
  {:ok, count} ->
    # count => 83 (or some integer)
  {:error, err} ->
    # error occurred
end
create(changeset)

Creates a subscription from a changeset. Supports nesting the account.

Parameters

  • changeset Keyword list changeset

Examples

alias Recurly.ValidationError

changeset = [
  plan_code: "gold",
  currency: "USD",
  account: [
    account_code: "b6f5783",
    email: "verena@example.com",
    first_name: "Verena",
    last_name: "Example",
    billing_info: [
      number: "4111-1111-1111-1111",
      month: 12,
      year: 2019,
      verification_value: "123",
      address1: "400 Alabama St",
      city: "San Francisco",
      state: "CA",
      country: "US",
      zip: "94110"
    ]
  ]
]

case Recurly.Subscription.create(changeset) do
  {:ok, subscription} ->
    # created the subscription
  {:error, %ValidationError{errors: errors}} ->
    # will give you a list of validation errors
end
find(uuid)

Finds a subscription given a subscription uuid. Returns the subscription or an error.

Parameters

  • uuid String subscription uuid

Examples

alias Recurly.NotFoundError

case Recurly.Subscription.find("36ce107b00244abd107f4e4397a19e95") do
  {:ok, subscription} ->
    # Found the subscription
  {:error, %NotFoundError{}} ->
    # 404 subscription was not found
end
first(options \\ [])

Gives the first subscription returned given options

Parameters

Examples

# suppose we want the latest, active subscription
case Recurly.Subscription.first(state: :active) do
  {:ok, subscription} ->
    # subscription => the newest active subscription
  {:error, err} ->
    # error occurred
end

# or maybe want the oldest, active subscription
case Recurly.Subscription.first(state: :active, order: :asc) do
  {:ok, subscription} ->
    # subscription => the oldest active subscription
  {:error, err} ->
    # error occurred
end
path(uuid)

Generates the path to a subscription given the uuid

Parameters

  • uuid String subscription uuid
stream(options \\ [])

Creates a stream of subscriptions given some options.

Parameters

Examples

See Recurly.Resource.stream/3 for more detailed examples of working with resource streams.

# stream of active subscriptions sorted from most recently
# updated to least recently updated
stream = Recurly.Subscription.stream(state: :active, sort: :updated_at)
terminate(subscription)

Terminates a given subscription. See docs on terminating a subscription.

TODO more docs