1 | <?php |
||
63 | class AuthnetJsonResponse |
||
64 | { |
||
65 | /** |
||
66 | * @const Indicates the status code of an approved transaction |
||
67 | */ |
||
68 | const STATUS_APPROVED = 1; |
||
69 | |||
70 | /** |
||
71 | * @const Indicates the status code of an declined transaction |
||
72 | */ |
||
73 | const STATUS_DECLINED = 2; |
||
74 | |||
75 | /** |
||
76 | * @const Indicates the status code of an transaction which has encountered an error |
||
77 | */ |
||
78 | const STATUS_ERROR = 3; |
||
79 | |||
80 | /** |
||
81 | * @const Indicates the status code of a transaction held for review |
||
82 | */ |
||
83 | const STATUS_HELD = 4; |
||
84 | |||
85 | /** |
||
86 | * @const Indicates the status code of a transaction held for review |
||
87 | */ |
||
88 | const STATUS_PAYPAL_NEED_CONSENT = 5; |
||
89 | |||
90 | /** |
||
91 | * @var object SimpleXML object representing the API response |
||
92 | */ |
||
93 | private $response; |
||
94 | |||
95 | /** |
||
96 | * @var string JSON string that is the response sent by Authorize.Net |
||
97 | */ |
||
98 | private $responseJson; |
||
99 | |||
100 | /** |
||
101 | * @var object TransactionResponse |
||
102 | */ |
||
103 | private $transactionInfo; |
||
104 | |||
105 | /** |
||
106 | * Creates the response object with the response json returned from the API call |
||
107 | * |
||
108 | * @param string $responseJson Response from Authorize.Net |
||
109 | * @throws \JohnConde\Authnet\AuthnetInvalidJsonException |
||
110 | */ |
||
111 | public function __construct(string $responseJson) |
||
124 | |||
125 | /** |
||
126 | * Outputs the response JSON in a human readable format |
||
127 | * |
||
128 | * @return string HTML table containing debugging information |
||
129 | */ |
||
130 | public function __toString() |
||
141 | |||
142 | /** |
||
143 | * Gets a response variable from the API response |
||
144 | * |
||
145 | * @param string $var unused |
||
146 | * @return string requested variable from the API call response |
||
147 | */ |
||
148 | public function __get(string $var) |
||
152 | |||
153 | /** |
||
154 | * Checks if the API call is not in an error state |
||
155 | * |
||
156 | * @return bool Whether the transaction was in an successful state |
||
157 | */ |
||
158 | public function isSuccessful() : bool |
||
162 | |||
163 | /** |
||
164 | * Checks if the API is reporting an error with the API call |
||
165 | * |
||
166 | * @return bool Whether the transaction was in an error state |
||
167 | */ |
||
168 | public function isError() : bool |
||
172 | |||
173 | /** |
||
174 | * Checks if a transaction was approved |
||
175 | * |
||
176 | * @return bool true if the transaction is approved |
||
177 | */ |
||
178 | public function isApproved() : bool |
||
182 | |||
183 | /** |
||
184 | * Checks if a transaction was declined |
||
185 | * |
||
186 | * @return bool true if the transaction is declined |
||
187 | */ |
||
188 | public function isDeclined() : bool |
||
192 | |||
193 | /** |
||
194 | * Check to see if the ResponseCode matches the expected value |
||
195 | * |
||
196 | * @param integer $status |
||
197 | * @return bool Check to see if the ResponseCode matches the expected value |
||
198 | */ |
||
199 | protected function checkTransactionStatus(int $status) : bool |
||
208 | |||
209 | /** |
||
210 | * Gets the transaction response field for AIM and CIM transactions. |
||
211 | * |
||
212 | * @param mixed $field Name or key of the transaction field to be retrieved |
||
213 | * @return string Transaction field to be retrieved |
||
214 | * @throws \JohnConde\Authnet\AuthnetTransactionResponseCallException |
||
215 | */ |
||
216 | public function getTransactionResponseField($field) : string |
||
223 | |||
224 | /** |
||
225 | * Gets the transaction response from Authorize.Net in JSON format for logging purposes |
||
226 | * |
||
227 | * @return string transaction response from Authorize.Net in JSON format |
||
228 | */ |
||
229 | public function getRawResponse() : string |
||
233 | |||
234 | /** |
||
235 | * An alias of self::getErrorText() |
||
236 | * |
||
237 | * @return string Error response from Authorize.Net |
||
238 | */ |
||
239 | public function getErrorMessage() : string |
||
243 | |||
244 | /** |
||
245 | * If an error has occurred, returns the error message |
||
246 | * |
||
247 | * @return string Error response from Authorize.Net |
||
248 | */ |
||
249 | public function getErrorText() : string |
||
253 | |||
254 | /** |
||
255 | * If an error has occurred, returns the error message |
||
256 | * |
||
257 | * @return string Error response from Authorize.Net |
||
258 | */ |
||
259 | public function getErrorCode() : string |
||
263 | |||
264 | /** |
||
265 | * @param string $type Whether to get the error code or text |
||
266 | * @return string |
||
267 | */ |
||
268 | private function getError(string $type) : string |
||
280 | } |
||
281 |