Class: ActiveMerchant::Billing::MultiResponse
- Inherits:
-
Response
- Object
- Response
- ActiveMerchant::Billing::MultiResponse
show all
- Defined in:
- lib/active_merchant/billing/response.rb
Instance Attribute Summary collapse
Attributes inherited from Response
#auth_code, #authorization, #emv_authorization, #error_code, #message, #network_transaction_id, #params, #request_body, #request_endpoint, #request_id, #request_method, #response_http_code, #response_type, #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.
65
66
67
68
69
|
# File 'lib/active_merchant/billing/response.rb', line 65
def initialize(use_first_response = false)
@responses = []
@use_first_response = use_first_response
@primary_response = nil
end
|
Instance Attribute Details
#primary_response ⇒ Object
Returns the value of attribute primary_response.
63
64
65
|
# File 'lib/active_merchant/billing/response.rb', line 63
def primary_response
@primary_response
end
|
#responses ⇒ Object
Returns the value of attribute responses.
63
64
65
|
# File 'lib/active_merchant/billing/response.rb', line 63
def responses
@responses
end
|
Class Method Details
.run(use_first_response = false, &block) ⇒ Object
59
60
61
|
# File 'lib/active_merchant/billing/response.rb', line 59
def self.run(use_first_response = false, &block)
new(use_first_response).tap(&block)
end
|
Instance Method Details
#<<(response) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/active_merchant/billing/response.rb', line 86
def <<(response)
if response.is_a?(MultiResponse)
response.responses.each { |r| @responses << r }
else
@responses << response
end
end
|
#avs_result ⇒ Object
98
99
100
101
102
103
|
# File 'lib/active_merchant/billing/response.rb', line 98
def avs_result
return @primary_response.try(:avs_result) if @use_first_response
result = responses.reverse.find { |r| r.avs_result['code'].present? }
result.try(:avs_result) || responses.last.try(:avs_result)
end
|
#cvv_result ⇒ Object
105
106
107
108
109
110
|
# File 'lib/active_merchant/billing/response.rb', line 105
def cvv_result
return @primary_response.try(:cvv_result) if @use_first_response
result = responses.reverse.find { |r| r.cvv_result['code'].present? }
result.try(:cvv_result) || responses.last.try(:cvv_result)
end
|
#process(ignore_result = false) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/active_merchant/billing/response.rb', line 71
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
94
95
96
|
# File 'lib/active_merchant/billing/response.rb', line 94
def success?
(primary_response ? primary_response.success? : true)
end
|