Sha256: a3434a11be80bd354d678fc733814a6ae82cd7732add32fdd135e21a4d5a1317

Contents?: true

Size: 841 Bytes

Versions: 1

Compression:

Stored size: 841 Bytes

Contents

module BraintreeRails
  class Subscriptions < SimpleDelegator
    include CollectionAssociation

    def initialize(belongs_to)
      case belongs_to
      when BraintreeRails::CreditCard
        @credit_card = belongs_to
      when BraintreeRails::Plan
        @plan = belongs_to
      end
      super([])
    end

    def default_options
      if @credit_card.present?
        {:payment_method_token => @credit_card.token}
      elsif @plan.present?
        {:plan_id => @plan.id}
      else
        {}
      end
    end

    protected
    def load!
      self.collection = if @credit_card.present?
        @credit_card.raw_object.subscriptions
      elsif @plan.present?
        Braintree::Subscription.search {|search| search.plan_id.is @plan.id}
      else
        Braintree::Subscription.search
      end
      super
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
braintree-rails-1.1.0 lib/braintree_rails/subscriptions.rb