Sha256: f7c07e71c4b914a2166f64d411a3c7ea13f4a5ed91ea184d4e85bd114464b25d

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

module Workarea
  decorate Order, with: :kount do
    decorated do
      field :kount_session_id, type: String
      field :kount_decision, type: Symbol

      scope :not_under_review, -> { where(:kount_decision.ne => :review) }

      before_save :set_kount_decision, if: :fraud_decision?
    end

    class_methods do
      # Query for orders which have expired in checkout, meaning they have been
      # not been placed or updated for longer than the
      # +Workarea.config.order_expiration_period+, but have started
      # checkout. Contrast this with +Order.expired+, which does not
      # factor in orders that have started checkout.
      #
      # Doesn't include orders under review or declined by kount
      #
      # @return [Mongoid::Criteria]
      def expired_in_checkout
        super.nin(kount_decision: [:review, :decline])
      end

      # Overriding method from core/models/order/queries.rb module
      def need_reminding
        super.where(kount_decision: nil)
      end

      # Find a current cart for a session. Returns a new order if one cannot be found.
      #
      # @param params [Hash]
      # @return [Order]
      #
      def find_current(params = {})
        if params[:id].present? || params[:user_id].present?
          with_scope(not_under_review) { super }
        else
          super
        end
      end
    end

    # Whether the FraudDecision#decision is `:review`.
    def under_review?
      !placed? && !canceled? && kount_decision == :review
    end

    def abandoned?
      super && kount_decision.nil?
    end

    def set_kount_decision
      self.kount_decision = fraud_decision.decision
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-kount-3.3.1 app/models/workarea/order.decorator