Module: Spree::Order::StoreCredit
- Included in:
- Spree::Order
- Defined in:
- app/models/spree/order/store_credit.rb
Instance Method Summary collapse
- #add_store_credit_payments(amount = nil) ⇒ Object
- #could_use_store_credit? ⇒ Boolean
- #covered_by_store_credit? ⇒ Boolean (also: #covered_by_store_credit)
- #display_order_total_after_store_credit ⇒ Object
- #display_store_credit_remaining_after_capture ⇒ Object
- #display_total_applicable_store_credit ⇒ Object
- #display_total_applied_store_credit ⇒ Object
- #display_total_available_store_credit ⇒ Object
- #order_total_after_store_credit ⇒ Object
- #remove_store_credit_payments ⇒ Object
- #total_applicable_store_credit ⇒ Object
- #total_applied_store_credit ⇒ Object
- #total_available_store_credit ⇒ Object
- #using_store_credit? ⇒ Boolean
Instance Method Details
#add_store_credit_payments(amount = nil) ⇒ Object
4 5 6 |
# File 'app/models/spree/order/store_credit.rb', line 4 def add_store_credit_payments(amount = nil) Spree::Dependencies.checkout_add_store_credit_service.constantize.call(order: self, amount: amount) end |
#could_use_store_credit? ⇒ Boolean
25 26 27 28 29 |
# File 'app/models/spree/order/store_credit.rb', line 25 def could_use_store_credit? return false if Spree::PaymentMethod::StoreCredit.available.empty? total_available_store_credit > 0 end |
#covered_by_store_credit? ⇒ Boolean Also known as: covered_by_store_credit
12 13 14 15 16 |
# File 'app/models/spree/order/store_credit.rb', line 12 def covered_by_store_credit? return false unless user user.total_available_store_credit >= total end |
#display_order_total_after_store_credit ⇒ Object
59 60 61 |
# File 'app/models/spree/order/store_credit.rb', line 59 def display_order_total_after_store_credit Spree::Money.new(order_total_after_store_credit, currency: currency) end |
#display_store_credit_remaining_after_capture ⇒ Object
67 68 69 |
# File 'app/models/spree/order/store_credit.rb', line 67 def display_store_credit_remaining_after_capture Spree::Money.new(total_available_store_credit - total_applicable_store_credit, currency: currency) end |
#display_total_applicable_store_credit ⇒ Object
51 52 53 |
# File 'app/models/spree/order/store_credit.rb', line 51 def display_total_applicable_store_credit Spree::Money.new(-total_applicable_store_credit, currency: currency) end |
#display_total_applied_store_credit ⇒ Object
55 56 57 |
# File 'app/models/spree/order/store_credit.rb', line 55 def display_total_applied_store_credit Spree::Money.new(-total_applied_store_credit, currency: currency) end |
#display_total_available_store_credit ⇒ Object
63 64 65 |
# File 'app/models/spree/order/store_credit.rb', line 63 def display_total_available_store_credit Spree::Money.new(total_available_store_credit, currency: currency) end |
#order_total_after_store_credit ⇒ Object
31 32 33 |
# File 'app/models/spree/order/store_credit.rb', line 31 def order_total_after_store_credit total - total_applicable_store_credit end |
#remove_store_credit_payments ⇒ Object
8 9 10 |
# File 'app/models/spree/order/store_credit.rb', line 8 def remove_store_credit_payments Spree::Dependencies.checkout_remove_store_credit_service.constantize.call(order: self) end |
#total_applicable_store_credit ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/models/spree/order/store_credit.rb', line 35 def total_applicable_store_credit if payment? || confirm? || complete? total_applied_store_credit else [total, (user.try(:total_available_store_credit) || 0.0)].min end end |
#total_applied_store_credit ⇒ Object
43 44 45 |
# File 'app/models/spree/order/store_credit.rb', line 43 def total_applied_store_credit payments.store_credits.valid.sum(:amount) end |
#total_available_store_credit ⇒ Object
19 20 21 22 23 |
# File 'app/models/spree/order/store_credit.rb', line 19 def total_available_store_credit return 0.0 unless user user.total_available_store_credit(currency, store) end |
#using_store_credit? ⇒ Boolean
47 48 49 |
# File 'app/models/spree/order/store_credit.rb', line 47 def using_store_credit? total_applied_store_credit > 0 end |