ssoper (owner)

Revisions

  • 7bfac4 ssoper Tue May 05 11:23:10 -0700 2009
gist: 107102 Download_button fork
public
Public Clone URL: git://gist.github.com/107102.git
Embed All Files: show embed
overwrite_payflow_api.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)