module OverwritePayflowAPI def self.included(base) base.alias_method_chain :commit, :retry end def commit_with_retry(request_body, request_type = nil) # Payflow Pro purchases by reference have a habit of failing in tests, probably due to speed with which tests are executed. # This ensures that the purchase is attempted a maximum number of times with a 1-sec sleep in between. This feature can be # turned off by calling 'disable_ensure_purchase' in your test. result = commit_without_retry(request_body, request_type) 10.times do return result if result.success? result = commit_without_retry(request_body, request_type) sleep(1) end unless ENV['DISABLE_ENSURE_PURCHASE'] return result end end ActiveMerchant::Billing::PayflowCommonAPI.send(:include, OverwritePayflowAPI)