Class: Effective::OrderItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::OrderItem
- Defined in:
- app/models/effective/order_item.rb
Instance Method Summary collapse
- #price=(value) ⇒ Object
-
#seller ⇒ Object
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.
- #stripe_connect_application_fee ⇒ Object
- #subtotal ⇒ Object
- #tax ⇒ Object
- #to_s ⇒ Object
- #total ⇒ Object
Instance Method Details
#price=(value) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/models/effective/order_item.rb', line 52 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 raise 'expected price to be an Integer representing the number of cents.' end end |
#seller ⇒ Object
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
65 66 67 |
# File 'app/models/effective/order_item.rb', line 65 def seller @seller ||= Effective::Customer.for_buyer(purchasable.seller) end |
#stripe_connect_application_fee ⇒ Object
69 70 71 72 73 74 75 |
# File 'app/models/effective/order_item.rb', line 69 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 "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 |
#subtotal ⇒ Object
36 37 38 |
# File 'app/models/effective/order_item.rb', line 36 def subtotal price * quantity end |
#tax ⇒ Object
40 41 42 43 44 |
# File 'app/models/effective/order_item.rb', line 40 def tax return 0 if tax_exempt? raise 'parent Effective::Order must have a tax_rate to compute order item tax' unless order.try(:tax_rate).present? (subtotal * order.tax_rate / 100.0).round(0).to_i end |
#to_s ⇒ Object
32 33 34 |
# File 'app/models/effective/order_item.rb', line 32 def to_s (quantity || 0) > 1 ? "#{quantity}x #{title}" : title end |
#total ⇒ Object
46 47 48 49 50 |
# File 'app/models/effective/order_item.rb', line 46 def total return subtotal if tax_exempt? raise 'parent Effective::Order must have a tax_rate to compute order item total' unless order.try(:tax_rate).present? subtotal + tax end |