Sha256: 2df24c0284dac68579bc930c9f8bd1ad90d7e4446bbb1f2d79f10c775affee72

Contents?: true

Size: 1.12 KB

Versions: 32

Compression:

Stored size: 1.12 KB

Contents

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

    # Singular because the endpoint is /usage not /usages
    # @return [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

32 entries across 32 versions & 1 rubygems

Version Path
recurly-2.9.3 lib/recurly/subscription_add_on.rb
recurly-2.8.3 lib/recurly/subscription_add_on.rb
recurly-2.7.9 lib/recurly/subscription_add_on.rb
recurly-2.6.4 lib/recurly/subscription_add_on.rb
recurly-2.5.5 lib/recurly/subscription_add_on.rb
recurly-2.9.2 lib/recurly/subscription_add_on.rb
recurly-2.8.2 lib/recurly/subscription_add_on.rb
recurly-2.7.8 lib/recurly/subscription_add_on.rb
recurly-2.6.3 lib/recurly/subscription_add_on.rb
recurly-2.5.4 lib/recurly/subscription_add_on.rb
recurly-2.9.1 lib/recurly/subscription_add_on.rb
recurly-2.8.1 lib/recurly/subscription_add_on.rb
recurly-2.7.7 lib/recurly/subscription_add_on.rb
recurly-2.6.2 lib/recurly/subscription_add_on.rb
recurly-2.5.3 lib/recurly/subscription_add_on.rb
recurly-2.10.1 lib/recurly/subscription_add_on.rb
recurly-2.10.0 lib/recurly/subscription_add_on.rb
recurly-2.9.0 lib/recurly/subscription_add_on.rb
recurly-2.8.0 lib/recurly/subscription_add_on.rb
recurly-2.8.0.rc3 lib/recurly/subscription_add_on.rb