Sha256: 673dee892cc1c352d6bd09b7e1a2fb27bd67197bc218803b397f0c441b99a14c

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module Workarea
  decorate Checkout::CollectPayment, with: :forter do
    def purchase
      collect_result = super

      begin
        fraud_analyzer.decide!

        # Rollback all transactions if the original collection
        # was successful but the forter decision was a decline.
        if collect_result && @order.fraud_suspected?
          payment.rollback!
          payment.fraud_suspected = true

          payment.save!
          false
        else
          # need to re-add errors indicating the payment operation failed
          error_messages = payment.errors.messages.clone
          payment.update_attribute(:fraud_suspected, false)
          error_messages.each do |attribute, message|
            payment.errors.add(attribute, message)
          end
          collect_result
        end

      rescue => e
        Forter.log_error(e)
        return collect_result
      end
    end

    private

    def fraud_analyzer
      @fraud_analyzer ||= Workarea.config.fraud_analyzer.constantize.new(@checkout)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
workarea-forter-1.3.2 app/models/workarea/checkout/collect_payment.decorator
workarea-forter-1.3.1 app/models/workarea/checkout/collect_payment.decorator
workarea-forter-1.3.0 app/models/workarea/checkout/collect_payment.decorator