Class: AuthorizeNet::XmlResponse
- 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.
Direct Known Subclasses
ARB::Response, ARB::SubscriptionListResponse, CIM::Response, Reporting::Response
Constant Summary
Constants included from TypeConversions
TypeConversions::API_FIELD_PREFIX
Instance Method Summary collapse
-
#connection_failure? ⇒ Boolean
Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
-
#initialize(raw_response, transaction) ⇒ XmlResponse
constructor
DO NOT USE.
-
#message_code ⇒ Object
Returns the messageCode from the XML response.
-
#message_text ⇒ Object
Returns the messageText from the XML response.
-
#raw ⇒ Object
Returns the underlying Net::HTTPResponse object.
-
#reference_id ⇒ Object
Returns the refId from the response if there is one.
-
#response_code ⇒ Object
Alias for result_code.
-
#response_reason_code ⇒ Object
Alias for message_code.
-
#response_reason_text ⇒ Object
Alias for message_text.
-
#result_code ⇒ Object
Returns the resultCode from the XML response.
-
#success? ⇒ Boolean
Check to see if the response indicated success.
-
#xml ⇒ Object
Returns a deep-copy of the XML object received from the payment gateway.
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.
35 36 37 |
# File 'lib/authorize_net/xml_response.rb', line 35 def connection_failure? !@raw_response.kind_of?(Net::HTTPOK) end |
#message_code ⇒ Object
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 end |
#message_text ⇒ Object
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 end |
#raw ⇒ Object
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_id ⇒ Object
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_code ⇒ Object
Alias for result_code.
69 70 71 |
# File 'lib/authorize_net/xml_response.rb', line 69 def response_code result_code end |
#response_reason_code ⇒ Object
Alias for message_code.
74 75 76 |
# File 'lib/authorize_net/xml_response.rb', line 74 def response_reason_code end |
#response_reason_text ⇒ Object
Alias for message_text.
79 80 81 |
# File 'lib/authorize_net/xml_response.rb', line 79 def response_reason_text end |
#result_code ⇒ Object
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’.
30 31 32 |
# File 'lib/authorize_net/xml_response.rb', line 30 def success? !connection_failure? && @result_code == 'Ok' end |
#xml ⇒ Object
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 |