Sha256: 1e45243ff99a6142e81ec539fa36dcedf414ac68f0958d347ef5da39f5a99048

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

module BraintreeRails
  class Subscription
    include Model

    define_attributes(
      :create => [
        :billing_day_of_month, :first_billing_date, :id, :merchant_account_id, :never_expires, :number_of_billing_cycles,
        :payment_method_token, :plan_id, :price, :trial_duration, :trial_duration_unit, :trial_period, :options, :descriptor
      ],
      :update => [
        :merchant_account_id, :never_expires, :number_of_billing_cycles,
        :payment_method_token, :plan_id, :price, :options
      ],
      :readonly => [
        :balance, :billing_period_end_date, :billing_period_start_date, :current_billing_cycle, :days_past_due,
        :failure_count, :next_billing_date, :next_billing_period_amount, :paid_through_date, :status
      ]
    )

    has_many   :add_ons,      :class => AddOns
    has_many   :discounts,    :class => Discounts
    has_many   :transactions, :class => Transactions
    belongs_to :plan,         :class => Plan,            :foreign_key => :plan_id
    belongs_to :credit_card,  :class => CreditCard,      :foreign_key => :payment_method_token

    def self.cancel(id)
      delete(id)
    end

    def cancel
      destroy
    end

    def price=(val)
      @price = val.blank? ? nil : val
    end

    def never_expires?
      never_expires
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
braintree-rails-1.2.3 lib/braintree_rails/subscription.rb
braintree-rails-1.2.2 lib/braintree_rails/subscription.rb
braintree-rails-1.2.1 lib/braintree_rails/subscription.rb
braintree-rails-1.2.0 lib/braintree_rails/subscription.rb
braintree-rails-1.1.0 lib/braintree_rails/subscription.rb