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.

Direct Known Subclasses

PaymentService::AuthorisationResponse, PaymentService::ModificationResponse, Adyen::API::RecurringService::DisableResponse, Adyen::API::RecurringService::ListResponse, Adyen::API::RecurringService::StoreTokenResponse

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Response) initialize(http_response)

Returns a new instance of Response

Parameters:

  • http_response (Net::HTTPResponse)

    The response object returned by Net::HTTP.



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)

Returns The response object returned by Net::HTTP.

Returns:

  • (Net::HTTPResponse)

    The response object returned by Net::HTTP.



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

Returns The raw body of the response object.

Returns:

  • (String)

    The raw body of the response object.



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

def body
  @http_response.body
end

- (String?) fault_message

Returns The SOAP failure message, if there is one.

Returns:

  • (String, nil)

    The SOAP failure message, if there is one.



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?

Returns Whether or not the HTTP request was a success.

Returns:

  • (Boolean)

    Whether or not the HTTP request was a success.



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

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

- (Hash) params

Returns Subclasses return the parsed response body.

Returns:

  • (Hash)

    Subclasses return the parsed response body.



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.

Returns:

  • (Boolean)

    Whether or not the SOAP request itself was a success.



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?

Returns Whether or not the request was successful.

Returns:

  • (Boolean)

    Whether or not the request was successful.



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

def success?
  !http_failure?
end

- (XMLQuerier) xml_querier

Returns The response body wrapped in a XMLQuerier.

Returns:

  • (XMLQuerier)

    The response body wrapped in a XMLQuerier.



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

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