Class: Adyen::API::Response
- Inherits:
-
Object
- Object
- Adyen::API::Response
- 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::BilletResponse, PaymentService::ModificationResponse, Adyen::API::RecurringService::DisableResponse, Adyen::API::RecurringService::ListResponse, Adyen::API::RecurringService::StoreTokenResponse
Instance Attribute Summary collapse
-
#http_response ⇒ Net::HTTPResponse
readonly
The response object returned by Net::HTTP.
Class Method Summary collapse
-
.response_attrs(*attrs) ⇒ Object
Defines shortcut accessor methods, to #params, for the given parameters.
Instance Method Summary collapse
-
#body ⇒ String
The raw body of the response object.
-
#fault_message ⇒ String?
The SOAP failure message, if there is one.
-
#http_failure? ⇒ Boolean
Whether or not the HTTP request was a success.
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
-
#params ⇒ Hash
Subclasses return the parsed response body.
-
#server_error? ⇒ Boolean
Adyen returns a 500 status code for e.g.
-
#success? ⇒ Boolean
Whether or not the request was successful.
-
#xml_querier ⇒ XMLQuerier
The response body wrapped in a XMLQuerier.
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of 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_response ⇒ Net::HTTPResponse (readonly)
Returns 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
.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
#body ⇒ String
Returns The raw body of the response object.
21 22 23 |
# File 'lib/adyen/api/response.rb', line 21 def body @http_response.body end |
#fault_message ⇒ String?
Returns The SOAP failure message, if there is one.
53 54 55 56 57 58 |
# File 'lib/adyen/api/response.rb', line 53 def ||= begin = xml_querier.text('//soap:Fault/faultstring') unless .empty? end end |
#http_failure? ⇒ Boolean
Returns 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 |
#params ⇒ Hash
Returns 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 |
#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) && .nil? end |
#success? ⇒ Boolean
Returns Whether or not the request was successful.
26 27 28 |
# File 'lib/adyen/api/response.rb', line 26 def success? !http_failure? end |
#xml_querier ⇒ XMLQuerier
Returns 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 |