Sha256: f5a559e870e75f972abd52d83ac4c4f0d19419676a2ce7ba52714b5a92954c53

Contents?: true

Size: 1.07 KB

Versions: 47

Compression:

Stored size: 1.07 KB

Contents

module Recurly
  class SubscriptionAddOn < Resource
    # @return [MeasuredUnit]
    has_one :measured_unit

    # @return [Pager<Usage>, []]
    has_many :usage

    define_attribute_methods %w(
      add_on_code
      quantity
      unit_amount_in_cents
      add_on_type
      usage_type
      usage_percentage
    )

    attr_reader :subscription

    def initialize add_on = nil, subscription = nil
      super()

      case add_on
      when AddOn, SubscriptionAddOn
        @add_on = add_on if add_on.is_a? AddOn
        self.add_on_code = add_on.add_on_code
        self.quantity = add_on.quantity
        if add_on.unit_amount_in_cents
          self.unit_amount_in_cents = add_on.unit_amount_in_cents.to_i
        end
      when Hash
        self.attributes = add_on
      when String, Symbol
        self.add_on_code = add_on
      end

      self.add_on_code = add_on_code.to_s

      @subscription = subscription
    end

    def add_on
      @add_on ||= subscription.plan.add_ons.find add_on_code
    end

    def currency
      subscription.currency if subscription
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
recurly-2.17.1 lib/recurly/subscription_add_on.rb
recurly-2.17.0 lib/recurly/subscription_add_on.rb
recurly-2.16.2 lib/recurly/subscription_add_on.rb
recurly-2.16.1 lib/recurly/subscription_add_on.rb
recurly-2.16.0 lib/recurly/subscription_add_on.rb
recurly-2.15.4 lib/recurly/subscription_add_on.rb
recurly-2.15.3 lib/recurly/subscription_add_on.rb
recurly-2.14.1 lib/recurly/subscription_add_on.rb
recurly-2.13.1 lib/recurly/subscription_add_on.rb
recurly-2.12.2 lib/recurly/subscription_add_on.rb
recurly-2.11.4 lib/recurly/subscription_add_on.rb
recurly-2.10.5 lib/recurly/subscription_add_on.rb
recurly-2.15.2 lib/recurly/subscription_add_on.rb
recurly-2.15.1 lib/recurly/subscription_add_on.rb
recurly-2.15.0 lib/recurly/subscription_add_on.rb
recurly-2.14.0 lib/recurly/subscription_add_on.rb
recurly-2.13.0 lib/recurly/subscription_add_on.rb
recurly-2.12.1 lib/recurly/subscription_add_on.rb
recurly-2.12.1.rc1 lib/recurly/subscription_add_on.rb
recurly-2.12.0 lib/recurly/subscription_add_on.rb