Skip to content

Instantly share code, notes, and snippets.

@ssoper
Created May 5, 2009 18:22
Show Gist options
  • Save ssoper/107101 to your computer and use it in GitHub Desktop.
Save ssoper/107101 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment