Sha256: 358ab2e900f1e21a898535d1e1c58292f66fa855cdaa8bc20347f376d7dc9a54

Contents?: true

Size: 1.1 KB

Versions: 34

Compression:

Stored size: 1.1 KB

Contents

module Spree
  class StoreCreditEvent < Spree::Base
    acts_as_paranoid

    belongs_to :store_credit
    belongs_to :originator, polymorphic: true

    scope :exposed_events, -> { where.not(action: [Spree::StoreCredit::ELIGIBLE_ACTION, Spree::StoreCredit::AUTHORIZE_ACTION]) }
    scope :reverse_chronological, -> { order(created_at: :desc) }

    delegate :currency, to: :store_credit

    def display_amount
      Spree::Money.new(amount, currency: currency)
    end

    def display_user_total_amount
      Spree::Money.new(user_total_amount, currency: currency)
    end

    def display_action
      case action
      when Spree::StoreCredit::CAPTURE_ACTION
        Spree.t('store_credit.captured')
      when Spree::StoreCredit::AUTHORIZE_ACTION
        Spree.t('store_credit.authorized')
      when Spree::StoreCredit::ALLOCATION_ACTION
        Spree.t('store_credit.allocated')
      when Spree::StoreCredit::VOID_ACTION, Spree::StoreCredit::CREDIT_ACTION
        Spree.t('store_credit.credit')
      end
    end

    def order
      Spree::Payment.find_by_response_code(authorization_code).try(:order)
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
spree_core-3.2.9 app/models/spree/store_credit_event.rb
spree_core-3.1.14 app/models/spree/store_credit_event.rb
spree_core-3.2.8 app/models/spree/store_credit_event.rb
spree_core-3.1.13 app/models/spree/store_credit_event.rb
spree_core-3.2.7 app/models/spree/store_credit_event.rb
spree_core-3.1.12 app/models/spree/store_credit_event.rb
spree_core-3.2.6 app/models/spree/store_credit_event.rb
spree_core-3.1.11 app/models/spree/store_credit_event.rb
spree_core-3.1.10 app/models/spree/store_credit_event.rb
spree_core-3.2.5 app/models/spree/store_credit_event.rb
spree_core-3.1.9 app/models/spree/store_credit_event.rb
spree_core-3.2.4 app/models/spree/store_credit_event.rb
spree_core-3.1.8 app/models/spree/store_credit_event.rb
spree_core-3.1.7 app/models/spree/store_credit_event.rb
spree_core-3.2.3 app/models/spree/store_credit_event.rb
spree_core-3.2.2 app/models/spree/store_credit_event.rb
spree_core-3.3.0.rc2 app/models/spree/store_credit_event.rb
spree_core-3.1.6 app/models/spree/store_credit_event.rb
spree_core-3.3.0.rc1 app/models/spree/store_credit_event.rb
spree_core-3.1.5 app/models/spree/store_credit_event.rb