Class: Effective::OrderItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/order_item.rb

Instance Method Summary collapse

Instance Method Details

#price=(value) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'app/models/effective/order_item.rb', line 43

def price=(value)
  if value.kind_of?(Integer)
    super
  elsif value.kind_of?(String) && !value.include?('.') # Looks like an integer
    super
  else # Could be Float, BigDecimal, or String like 9.99
    ActiveSupport::Deprecation.warn('order_item.price= was passed a non-integer. Expecting an Integer representing the number of cents.  Continuing with (price * 100.0).round(0).to_i conversion') unless EffectiveOrders.silence_deprecation_warnings
    super((value.to_f * 100.0).to_i)
  end
end

#sellerObject

This is going to return an Effective::Customer object that matches the purchasable.user And is the Customer representing who is selling the product This is really only used for StripeConnect



57
58
59
# File 'app/models/effective/order_item.rb', line 57

def seller
  @seller ||= Effective::Customer.for_user(purchasable.try(:seller))
end

#stripe_connect_application_feeObject



61
62
63
64
65
66
67
# File 'app/models/effective/order_item.rb', line 61

def stripe_connect_application_fee
  @stripe_connect_application_fee ||= (
    self.instance_exec(self, &EffectiveOrders.stripe_connect_application_fee_method).to_i.tap do |fee|
      raise ArgumentError.new("expected EffectiveOrders.stripe_connect_application_fee_method to return a value between 0 and the order_item total (#{self.total}).  Received #{fee}.") if (fee > total || fee < 0)
    end
  )
end

#subtotalObject



31
32
33
# File 'app/models/effective/order_item.rb', line 31

def subtotal
  price * quantity
end

#taxObject

This is the total tax, for 3 items if quantity is 3



35
36
37
# File 'app/models/effective/order_item.rb', line 35

def tax  # This is the total tax, for 3 items if quantity is 3
  tax_exempt ? 0 : (subtotal * tax_rate).round(0).to_i
end

#totalObject



39
40
41
# File 'app/models/effective/order_item.rb', line 39

def total
  subtotal + tax
end