This repository was archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAuthorizeNetXMLResponse.php
More file actions
131 lines (115 loc) · 2.93 KB
/
AuthorizeNetXMLResponse.php
File metadata and controls
131 lines (115 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
namespace Problematic\AuthNetBundle\AuthorizeNet\Shared;
/**
* Base class for the AuthorizeNet ARB & CIM Responses.
*
* @package AuthorizeNet
* @subpackage AuthorizeNetXML
*/
/**
* Base class for the AuthorizeNet ARB & CIM Responses.
*
* @package AuthorizeNet
* @subpackage AuthorizeNetXML
*/
class AuthorizeNetXMLResponse
{
public $xml; // Holds a SimpleXML Element with response.
/**
* Constructor. Parses the AuthorizeNet response string.
*
* @param string $response The response from the AuthNet server.
*/
public function __construct($response)
{
$this->response = $response;
if ($response) {
$this->xml = @simplexml_load_string($response);
// Remove namespaces for use with XPath.
$this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/','',$response));
}
}
/**
* Was the transaction successful?
*
* @return bool
*/
public function isOk()
{
return ($this->getResultCode() == "Ok");
}
/**
* Run an xpath query on the cleaned XML response
*
* @param string $path
* @return array Returns an array of SimpleXMLElement objects or FALSE in case of an error.
*/
public function xpath($path)
{
return $this->xpath_xml->xpath($path);
}
/**
* Was there an error?
*
* @return bool
*/
public function isError()
{
return ($this->getResultCode() == "Error");
}
/**
* @return string
*/
public function getErrorMessage()
{
return "Error: {$this->getResultCode()}
Message: {$this->getMessageText()}
{$this->getMessageCode()}";
}
/**
* @return string
*/
public function getRefID()
{
return $this->_getElementContents("refId");
}
/**
* @return string
*/
public function getResultCode()
{
return $this->_getElementContents("resultCode");
}
/**
* @return string
*/
public function getMessageCode()
{
return $this->_getElementContents("code");
}
/**
* @return string
*/
public function getMessageText()
{
return $this->_getElementContents("text");
}
/**
* Grabs the contents of a unique element.
*
* @param string
* @return string
*/
protected function _getElementContents($elementName)
{
$start = "<$elementName>";
$end = "</$elementName>";
if (strpos($this->response,$start) === false || strpos($this->response,$end) === false) {
return false;
} else {
$start_position = strpos($this->response, $start)+strlen($start);
$end_position = strpos($this->response, $end);
return substr($this->response, $start_position, $end_position-$start_position);
}
}
}