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 ⇒ 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
- #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 ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/spree/order/store_credit.rb', line 4 def add_store_credit_payments payments.store_credits.where(state: 'checkout').map(&:invalidate!) remaining_total = outstanding_balance if user && user.store_credits.any? payment_method = Spree::PaymentMethod::StoreCredit.available.first raise "Store credit payment method could not be found" unless payment_method user.store_credits.order_by_priority.each do |credit| break if remaining_total.zero? next if credit.amount_remaining.zero? amount_to_take = store_credit_amount(credit, remaining_total) create_store_credit_payment(payment_method, credit, amount_to_take) remaining_total -= amount_to_take end end end |
#could_use_store_credit? ⇒ Boolean
35 36 37 |
# File 'app/models/spree/order/store_credit.rb', line 35 def could_use_store_credit? total_available_store_credit > 0 end |
#covered_by_store_credit? ⇒ Boolean Also known as: covered_by_store_credit
24 25 26 27 |
# File 'app/models/spree/order/store_credit.rb', line 24 def covered_by_store_credit? return false unless user user.total_available_store_credit >= total end |
#display_order_total_after_store_credit ⇒ Object
67 68 69 |
# File 'app/models/spree/order/store_credit.rb', line 67 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
75 76 77 |
# File 'app/models/spree/order/store_credit.rb', line 75 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
59 60 61 |
# File 'app/models/spree/order/store_credit.rb', line 59 def display_total_applicable_store_credit Spree::Money.new(-total_applicable_store_credit, currency: currency) end |
#display_total_applied_store_credit ⇒ Object
63 64 65 |
# File 'app/models/spree/order/store_credit.rb', line 63 def display_total_applied_store_credit Spree::Money.new(-total_applied_store_credit, currency: currency) end |
#display_total_available_store_credit ⇒ Object
71 72 73 |
# File 'app/models/spree/order/store_credit.rb', line 71 def display_total_available_store_credit Spree::Money.new(total_available_store_credit, currency: currency) end |
#order_total_after_store_credit ⇒ Object
39 40 41 |
# File 'app/models/spree/order/store_credit.rb', line 39 def order_total_after_store_credit total - total_applicable_store_credit end |
#total_applicable_store_credit ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/models/spree/order/store_credit.rb', line 43 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
51 52 53 |
# File 'app/models/spree/order/store_credit.rb', line 51 def total_applied_store_credit payments.store_credits.valid.sum(:amount) end |
#total_available_store_credit ⇒ Object
30 31 32 33 |
# File 'app/models/spree/order/store_credit.rb', line 30 def total_available_store_credit return 0.0 unless user user.total_available_store_credit end |
#using_store_credit? ⇒ Boolean
55 56 57 |
# File 'app/models/spree/order/store_credit.rb', line 55 def using_store_credit? total_applied_store_credit > 0 end |