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

- (Response) initialize(http_response)



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

def initialize(http_response)
  @http_response = http_response
end

Instance Attribute Details

- (Net::HTTPResponse) http_response (readonly)



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

def http_response
  @http_response
end

Class Method Details

+ (Object) response_attrs(*attrs)

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

- (String) body



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

def body
  @http_response.body
end

- (String?) fault_message



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

- (Boolean) http_failure?



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

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

- (Hash) params



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

- (Boolean) server_error?

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

- (Boolean) success?



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

def success?
  !http_failure?
end

- (XMLQuerier) xml_querier



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

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