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 Attribute Summary collapse

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.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/authorize_net/xml_response.rb', line 6

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 StandardError
      @raw_response = $ERROR_INFO
    end
  end
end

Instance Attribute Details

#message_codeObject (readonly)

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



55
56
57
# File 'lib/authorize_net/xml_response.rb', line 55

def message_code
  @message_code
end

#message_textObject (readonly)

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



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

def message_text
  @message_text
end

#reference_idObject (readonly)

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



76
77
78
# File 'lib/authorize_net/xml_response.rb', line 76

def reference_id
  @reference_id
end

#result_codeObject (readonly)

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



51
52
53
# File 'lib/authorize_net/xml_response.rb', line 51

def result_code
  @result_code
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)


33
34
35
# File 'lib/authorize_net/xml_response.rb', line 33

def connection_failure?
  !@raw_response.is_a?(Net::HTTPOK)
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.



41
42
43
# File 'lib/authorize_net/xml_response.rb', line 41

def raw
  @raw_response
end

#response_codeObject

Alias for result_code.



61
62
63
# File 'lib/authorize_net/xml_response.rb', line 61

def response_code
  result_code
end

#response_reason_codeObject

Alias for message_code.



66
67
68
# File 'lib/authorize_net/xml_response.rb', line 66

def response_reason_code
  message_code
end

#response_reason_textObject

Alias for message_text.



71
72
73
# File 'lib/authorize_net/xml_response.rb', line 71

def response_reason_text
  message_text
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)


28
29
30
# File 'lib/authorize_net/xml_response.rb', line 28

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.



46
47
48
# File 'lib/authorize_net/xml_response.rb', line 46

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