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