Sha256: f6a47aa9758e575f713c2a8076dc2fd3e7e2c8950f13384d937bf3c2bc4e8c57

Contents?: true

Size: 1.74 KB

Versions: 20

Compression:

Stored size: 1.74 KB

Contents

module Recurly
  class Account < Resource
    # @macro [attach] scope
    #   @scope class
    #   @return [Pager<Account>] A pager that yields +$1+ accounts.
    scope :active,         :state => :active
    scope :closed,         :state => :closed
    scope :subscriber,     :state => :subscriber
    scope :non_subscriber, :state => :non_subscriber
    scope :past_due,       :state => :past_due

    # @macro [attach] has_many
    #   @return [Pager<Resource>, []] A pager that yields $1 for persisted
    #     accounts; an empty array otherwise.
    has_many :adjustments
    has_many :invoices
    has_many :subscriptions
    has_many :transactions

    # @return [BillingInfo, nil]
    has_one :billing_info, :readonly => false

    # @return [Redemption, nil]
    has_one :redemption

    define_attribute_methods %w(
      account_code
      state
      username
      email
      first_name
      last_name
      company_name
      accept_language
      hosted_login_token
      created_at
    )
    alias to_param account_code

    # @return [Invoice] A newly-created invoice.
    # @raise [Invalid] Raised if the account cannot be invoiced.
    def invoice!
      Invoice.from_response API.post(invoices.uri)
    rescue Recurly::API::UnprocessableEntity => e
      raise Invalid, e.message
    end

    # Reopen an account.
    #
    # @return [true, false] +true+ when successful, +false+ when unable to
    #   (e.g., the account is already opwn), and may raise an exception if the
    #   attempt fails.
    def reopen
      return false unless self[:reopen]
      reload self[:reopen].call
      true
    end

    private

    def xml_keys
      keys = super
      keys << 'account_code' if account_code? && !account_code_changed?
      keys.sort
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
recurly-2.1.12 lib/recurly/account.rb
recurly-2.0.14 lib/recurly/account.rb
recurly-2.1.11 lib/recurly/account.rb
recurly-2.0.13 lib/recurly/account.rb
recurly-2.1.10 lib/recurly/account.rb
recurly-2.0.12 lib/recurly/account.rb
recurly-2.1.9 lib/recurly/account.rb
recurly-2.1.8 lib/recurly/account.rb
recurly-2.1.7 lib/recurly/account.rb
recurly-2.1.5 lib/recurly/account.rb
recurly-2.1.4 lib/recurly/account.rb
recurly-2.1.3 lib/recurly/account.rb
recurly-2.1.2 lib/recurly/account.rb
recurly-2.1.1 lib/recurly/account.rb
recurly-2.1.0 lib/recurly/account.rb
recurly-2.0.11 lib/recurly/account.rb
recurly-2.0.10 lib/recurly/account.rb
recurly-2.0.9 lib/recurly/account.rb
recurly-2.0.8 lib/recurly/account.rb
recurly-2.0.6 lib/recurly/account.rb