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, #message, #params, #test

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Response

#fraud_review?, #test?

Constructor Details

#initializeMultiResponse

Returns a new instance of MultiResponse.



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

def initialize
  @responses = []
  @primary_response = :last
end

Instance Attribute Details

#primary_responseObject



72
73
74
# File 'lib/active_merchant/billing/response.rb', line 72

def primary_response
  success? && @primary_response == :first ? @responses.first : @responses.last
end

#responsesObject (readonly)

Returns the value of attribute responses.



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

def responses
  @responses
end

Class Method Details

.run(primary_response = :last, &block) ⇒ Object



42
43
44
45
46
# File 'lib/active_merchant/billing/response.rb', line 42

def self.run(primary_response = :last, &block)
  response = new.tap(&block)
  response.primary_response = primary_response
  response
end

Instance Method Details

#<<(response) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/active_merchant/billing/response.rb', line 60

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

#processObject



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

def process
  self << yield if(responses.empty? || success?)
end

#success?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/active_merchant/billing/response.rb', line 68

def success?
  @responses.all?{|r| r.success?}
end