Class: ActiveMerchant::Billing::MultiResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/active_merchant/billing/response.rb

Instance Attribute Summary collapse

Attributes inherited from Response

#authorization, #avs_result, #cvv_result, #emv_authorization, #error_code, #message, #network_transaction_id, #params, #test

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Response

#failure?, #fraud_review?, #test?

Constructor Details

#initialize(use_first_response = false) ⇒ MultiResponse

Returns a new instance of MultiResponse.



55
56
57
58
59
# File 'lib/active_merchant/billing/response.rb', line 55

def initialize(use_first_response = false)
  @responses = []
  @use_first_response = use_first_response
  @primary_response = nil
end

Instance Attribute Details

#primary_responseObject (readonly)

Returns the value of attribute primary_response.



53
54
55
# File 'lib/active_merchant/billing/response.rb', line 53

def primary_response
  @primary_response
end

#responsesObject (readonly)

Returns the value of attribute responses.



53
54
55
# File 'lib/active_merchant/billing/response.rb', line 53

def responses
  @responses
end

Class Method Details

.run(use_first_response = false, &block) ⇒ Object



49
50
51
# File 'lib/active_merchant/billing/response.rb', line 49

def self.run(use_first_response = false, &block)
  new(use_first_response).tap(&block)
end

Instance Method Details

#<<(response) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/active_merchant/billing/response.rb', line 76

def <<(response)
  if response.is_a?(MultiResponse)
    response.responses.each { |r| @responses << r }
  else
    @responses << response
  end
end

#process(ignore_result = false) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_merchant/billing/response.rb', line 61

def process(ignore_result = false)
  return unless success?

  response = yield
  self << response

  unless ignore_result
    if @use_first_response && response.success?
      @primary_response ||= response
    else
      @primary_response = response
    end
  end
end

#success?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/active_merchant/billing/response.rb', line 84

def success?
  (primary_response ? primary_response.success? : true)
end