Sha256: 45cad1b3b9e165643d394f0feea9e02c4a3f405a1505ccbc80e7a1af910a0707

Contents?: true

Size: 969 Bytes

Versions: 1

Compression:

Stored size: 969 Bytes

Contents

module SpreeSignifyd::OrderConcerns
  extend ActiveSupport::Concern

  included do
    Spree::Order.state_machine.after_transition to: :complete, unless: :approved? do |order, transition|
      if order.send_to_signifyd?
        SpreeSignifyd.create_case(order_number: order.number)
      else
        SpreeSignifyd.approve(order: order)
      end
    end

    has_one :signifyd_order_score, class_name: "SpreeSignifyd::OrderScore"

    prepend(InstanceMethods)
  end

  module InstanceMethods
    def is_risky?
      !(awaiting_approval? || approved?)
    end

    def awaiting_approval?
      !signifyd_order_score
    end

    def send_to_signifyd?
      !approved? &&
      !(SpreeSignifyd::Config[:exclude_store_credit_orders] && paid_completely_with_store_credit?)
    end

    private

    def paid_completely_with_store_credit?
      payments.all? do |payment|
        payment.payment_method.is_a?(Spree::PaymentMethod::StoreCredit)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_signifyd-1.1.0 app/models/spree_signifyd/order_concerns.rb