Class: AuthorizeNet::Response

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



6
7
8
# File 'lib/authorize_net/response.rb', line 6

def errors
  @errors
end

#messagesObject

Returns the value of attribute messages.



7
8
9
# File 'lib/authorize_net/response.rb', line 7

def messages
  @messages
end

#parsed_xmlObject

Returns the value of attribute parsed_xml.



9
10
11
# File 'lib/authorize_net/response.rb', line 9

def parsed_xml
  @parsed_xml
end

#raw_xmlObject

Returns the value of attribute raw_xml.



8
9
10
# File 'lib/authorize_net/response.rb', line 8

def raw_xml
  @raw_xml
end

#resultObject

Returns the value of attribute result.



5
6
7
# File 'lib/authorize_net/response.rb', line 5

def result
  @result
end

Class Method Details

.parseXml(xml) ⇒ Object

Returns a populated response object

Parameters:

  • String

    xml

Returns:

  • AuthorizeNet::Response



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/authorize_net/response.rb', line 18

def parseXml(xml)
  response = new
  response.raw_xml = xml
  response.parsed_xml = Nokogiri::XML.parse(xml)
  response.result = AuthorizeNet::Util.getXmlValue(response.parsed_xml, "resultCode")

  errors = response.parsed_xml.at_css("errors")
  if !errors.nil?
    response.errors = []
    errors.css("error").each do |xml_error|
      response.errors << {
        :code => AuthorizeNet::Util.getXmlValue(xml_error, "errorCode"),
        :text => AuthorizeNet::Util.getXmlValue(xml_error, "errorText"),
      }
    end
  end

  messages = response.parsed_xml.at_css("messages")
  if !messages.nil?
    response.messages = []
    messages.css("message").each do |xml_msg|
      response.messages << {
        :code => AuthorizeNet::Util.getXmlValue(xml_msg, "code"),
        :text => AuthorizeNet::Util.getXmlValue(xml_msg, "text"),
      }
    end
  end

  return response
end