M2_AuthorizeNetXMLResponse

Base class for the AuthorizeNet ARB & CIM Responses.

Defined (1)

The class is defined in the following location(s).

/lib/authorize.net/lib/shared/AuthorizeNetXMLResponse.php  
  1. class M2_AuthorizeNetXMLResponse 
  2.  
  3. public $xml; // Holds a SimpleXML Element with response. 
  4.  
  5. /** 
  6. * Constructor. Parses the AuthorizeNet response string. 
  7. * @param string $response The response from the AuthNet server. 
  8. */ 
  9. public function __construct($response) 
  10. $this->response = $response; 
  11. if ($response) { 
  12. $this->xml = @simplexml_load_string($response); 
  13.  
  14. // Remove namespaces for use with XPath. 
  15. $this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/', '', $response)); 
  16.  
  17. /** 
  18. * Was the transaction successful? 
  19. * @return bool 
  20. */ 
  21. public function isOk() 
  22. return ($this->getResultCode() == "Ok"); 
  23.  
  24. /** 
  25. * Run an xpath query on the cleaned XML response 
  26. * @param string $path 
  27. * @return array Returns an array of SimpleXMLElement objects or FALSE in case of an error. 
  28. */ 
  29. public function xpath($path) 
  30. return $this->xpath_xml->xpath($path); 
  31.  
  32. /** 
  33. * Was there an error? 
  34. * @return bool 
  35. */ 
  36. public function isError() 
  37. return ($this->getResultCode() == "Error"); 
  38.  
  39. /** 
  40. * @return string 
  41. */  
  42. public function getErrorMessage() 
  43. return "Error: {$this->getResultCode()}  
  44. Message: {$this->getMessageText()} 
  45. {$this->getMessageCode()}";  
  46.  
  47. /** 
  48. * @return string 
  49. */ 
  50. public function getRefID() 
  51. return $this->_getElementContents("refId"); 
  52.  
  53. /** 
  54. * @return string 
  55. */ 
  56. public function getResultCode() 
  57. return $this->_getElementContents("resultCode"); 
  58.  
  59. /** 
  60. * @return string 
  61. */ 
  62. public function getMessageCode() 
  63. return $this->_getElementContents("code"); 
  64.  
  65. /** 
  66. * @return string 
  67. */ 
  68. public function getMessageText() 
  69. return $this->_getElementContents("text"); 
  70.  
  71. /** 
  72. * Grabs the contents of a unique element. 
  73. * @param string 
  74. * @return string 
  75. */ 
  76. protected function _getElementContents($elementName)  
  77. $start = "<$elementName>"; 
  78. $end = "</$elementName>"; 
  79. if (strpos($this->response, $start) === false || strpos($this->response, $end) === false) { 
  80. return false; 
  81. } else { 
  82. $start_position = strpos($this->response, $start)+strlen($start); 
  83. $end_position = strpos($this->response, $end); 
  84. return substr($this->response, $start_position, $end_position-$start_position); 
  85.