class AuthorizeNet::XmlResponse

The core, xml response class. You shouldn’t instantiate this one. Instead you should use AuthorizeNet::ARB::Response.

Public Class Methods

new(raw_response, transaction) click to toggle source

DO NOT USE. Instantiate AuthorizeNet::ARB::Response or AuthorizeNet::CIM::Response instead.

# File lib/authorize_net/xml_response.rb, line 8
def initialize(raw_response, transaction)
  @raw_response = raw_response
  @transaction = transaction
  unless connection_failure?
    begin
      xml = Nokogiri::XML(@raw_response.body) do |config|
        # confirm noent is the right flag
        config.recover.noent.nonet
      end
      @root = xml.children[0]
      @result_code = node_content_unless_nil(@root.at_css('messages resultCode'))
      @message_code = node_content_unless_nil(@root.at_css('messages message code'))
      @message_text = node_content_unless_nil(@root.at_css('messages message text'))
      @reference_id = node_content_unless_nil(@root.at_css('refId'))
    rescue
      @raw_response = $!
    end
  end
end

Public Instance Methods

connection_failure?() click to toggle source

Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.

# File lib/authorize_net/xml_response.rb, line 35
def connection_failure?
  !@raw_response.kind_of?(Net::HTTPOK)
end
message_code() click to toggle source

Returns the messageCode from the XML response. This is a code indicating the details of an error or success.

# File lib/authorize_net/xml_response.rb, line 59
def message_code
  @message_code
end
message_text() click to toggle source

Returns the messageText from the XML response. This is a text description of the message_code.

# File lib/authorize_net/xml_response.rb, line 64
def message_text
  @message_text
end
raw() click to toggle source

Returns the underlying Net::HTTPResponse object. This has the original response body along with headers and such. Note that if an exception is generated while making the request (which happens if there is no internet connection for example), you will get the exception object here instead of a Net::HTTPResponse object.

# File lib/authorize_net/xml_response.rb, line 43
def raw
  @raw_response
end
reference_id() click to toggle source

Returns the refId from the response if there is one. Otherwise returns nil.

# File lib/authorize_net/xml_response.rb, line 84
def reference_id
  @reference_id
end
response_code() click to toggle source

Alias for result_code.

# File lib/authorize_net/xml_response.rb, line 69
def response_code
  result_code
end
response_reason_code() click to toggle source

Alias for message_code.

# File lib/authorize_net/xml_response.rb, line 74
def response_reason_code
  message_code
end
response_reason_text() click to toggle source

Alias for message_text.

# File lib/authorize_net/xml_response.rb, line 79
def response_reason_text
  message_text
end
result_code() click to toggle source

Returns the resultCode from the XML response. resultCode will be either ‘Ok’ or ‘Error’.

# File lib/authorize_net/xml_response.rb, line 53
def result_code
  @result_code
end
success?() click to toggle source

Check to see if the response indicated success. Success is defined as a 200 OK response with a resultCode of ‘Ok’.

# File lib/authorize_net/xml_response.rb, line 30
def success?
  !connection_failure? && @result_code == 'Ok'
end
xml() click to toggle source

Returns a deep-copy of the XML object received from the payment gateway. Or nil if there was no XML payload.

# File lib/authorize_net/xml_response.rb, line 48
def xml
  @root.dup unless @root.nil?
end