Class: Adyen::API::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/adyen/api/response.rb

Overview

The base class of all responses returned by API calls to Adyen.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response



16
17
18
# File 'lib/adyen/api/response.rb', line 16

def initialize(http_response)
  @http_response = http_response
end

Instance Attribute Details

#http_responseNet::HTTPResponse (readonly)



13
14
15
# File 'lib/adyen/api/response.rb', line 13

def http_response
  @http_response
end

Class Method Details

.response_attrs(*attrs) ⇒ Object

Defines shortcut accessor methods, to #params, for the given parameters.



6
7
8
9
10
# File 'lib/adyen/api/response.rb', line 6

def self.response_attrs(*attrs)
  attrs.each do |attr|
    define_method(attr) { params[attr] }
  end
end

Instance Method Details

#bodyString



21
22
23
# File 'lib/adyen/api/response.rb', line 21

def body
  @http_response.body
end

#fault_messageString?



53
54
55
56
57
58
# File 'lib/adyen/api/response.rb', line 53

def fault_message
  @fault_message ||= begin
    message = xml_querier.text('//soap:Fault/faultstring')
    message unless message.empty?
  end
end

#http_failure?Boolean



31
32
33
# File 'lib/adyen/api/response.rb', line 31

def http_failure?
  !@http_response.is_a?(Net::HTTPSuccess)
end

#paramsHash



48
49
50
# File 'lib/adyen/api/response.rb', line 48

def params
  raise "The Adyen::API::Response#params method should be overridden in a subclass."
end

#server_error?Boolean

Adyen returns a 500 status code for e.g. failed CC validation and in this case, we don't want to throw a server error but rather treat it as something normal.



38
39
40
# File 'lib/adyen/api/response.rb', line 38

def server_error?
  @http_response.is_a?(Net::HTTPServerError) && fault_message.nil?
end

#success?Boolean



26
27
28
# File 'lib/adyen/api/response.rb', line 26

def success?
  !http_failure?
end

#xml_querierXMLQuerier



43
44
45
# File 'lib/adyen/api/response.rb', line 43

def xml_querier
  @xml_querier ||= XMLQuerier.xml(@http_response.body)
end