Class: AuthorizeNet::XmlResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/authorize_net/xml_response.rb

Overview

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

Constant Summary

Constants included from TypeConversions

TypeConversions::API_FIELD_PREFIX

Instance Method Summary collapse

Methods included from TypeConversions

#boolean_to_value, #date_to_value, #datetime_to_value, #decimal_to_value, #integer_to_value, #to_external_field, #to_internal_field, #to_param, #value_to_boolean, #value_to_date, #value_to_datetime, #value_to_decimal, #value_to_integer

Constructor Details

#initialize(raw_response, transaction) ⇒ XmlResponse

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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

Instance Method Details

#connection_failure?Boolean

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

Returns:

  • (Boolean)


35
36
37
# File 'lib/authorize_net/xml_response.rb', line 35

def connection_failure?
  !@raw_response.kind_of?(Net::HTTPOK)
end

#message_codeObject

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



59
60
61
# File 'lib/authorize_net/xml_response.rb', line 59

def message_code
  @message_code
end

#message_textObject

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



64
65
66
# File 'lib/authorize_net/xml_response.rb', line 64

def message_text
  @message_text
end

#rawObject

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.



43
44
45
# File 'lib/authorize_net/xml_response.rb', line 43

def raw
  @raw_response
end

#reference_idObject

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



84
85
86
# File 'lib/authorize_net/xml_response.rb', line 84

def reference_id
  @reference_id
end

#response_codeObject

Alias for result_code.



69
70
71
# File 'lib/authorize_net/xml_response.rb', line 69

def response_code
  result_code
end

#response_reason_codeObject

Alias for message_code.



74
75
76
# File 'lib/authorize_net/xml_response.rb', line 74

def response_reason_code
  message_code
end

#response_reason_textObject

Alias for message_text.



79
80
81
# File 'lib/authorize_net/xml_response.rb', line 79

def response_reason_text
  message_text
end

#result_codeObject

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



53
54
55
# File 'lib/authorize_net/xml_response.rb', line 53

def result_code
  @result_code
end

#success?Boolean

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/authorize_net/xml_response.rb', line 30

def success?
  !connection_failure? && @result_code == 'Ok'
end

#xmlObject

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



48
49
50
# File 'lib/authorize_net/xml_response.rb', line 48

def xml
  @root.dup unless @root.nil?
end