/** * Validate the repsonse from Intacct to see if we successfully created a session * * @param String $response The XML response from Intacct * * @throws Exception * @return null */ private static function validateConnection($response) { $simpleXml = simplexml_load_string($response); if ($simpleXml === false) { throw new Exception("Invalid XML response: \n" . var_export($response, true)); } if ((string) $simpleXml->control->status == 'failure') { throw new Exception(api_util::xmlErrorToString($simpleXml->errormessage)); } if (!isset($simpleXml->operation)) { if (isset($simpleXml->errormessage)) { throw new Exception(api_util::xmlErrorToString($simpleXml->errormessage->error[0])); } } if (isset($simpleXml->operation->authentication->status)) { if ($simpleXml->operation->authentication->status != 'success') { $error = $simpleXml->operation->errormessage; throw new Exception(" [Error] " . (string) $error->error[0]->description2); } } $status = $simpleXml->operation->result->status; if ((string) $status != 'success') { $error = $simpleXml->operation->result->errormessage; throw new Exception(" [Error] " . (string) $error->error[0]->description2); } else { return; // no error found. } }
/** * @return mixed */ public function __toString() { $argXml = new SimpleXMLElement("<arguments/>"); self::constructElement($argXml); return api_util::xmlElementToSnippet($argXml->asXML()); }
/** * Process results from any of the read methods and convert into the appropriate structure * * @param String $response result from post to Intacct Web Services * @param Integer &$count by reference count of records returned * @param string $returnFormat valid returnFormat value * * @throws Exception * @return Mixed string or object depending on return format */ private static function processReadResults($response, &$count, $returnFormat = api_returnFormat::PHPOBJ) { $objAry = array(); $csv = ''; $json = ''; $xml = ''; if ($returnFormat == api_returnFormat::PHPOBJ) { $objAry = api_util::csvToPhp($response); $count = count($objAry); return $objAry; } elseif ($returnFormat == api_returnFormat::JSON) { // this seems really expensive $objAry = json_decode($response); // todo: JSON doesn't work because we don't know what object to refer to throw new Exception("The JSON return format is not implemented yet."); } elseif ($returnFormat == api_returnFormat::XML) { $xmlObj = simplexml_load_string($response); foreach ($xmlObj->operation->result->data->attributes() as $attribute => $value) { if ($attribute == 'count') { $count = $value; break; } } $xml = $xmlObj->operation->result->data->view->asXml(); return $xml; } elseif ($returnFormat == api_returnFormat::CSV) { $objAry = api_util::csvToPhp($response); $count = count($objAry); $csv = $response; return $csv; } else { throw new Exception("Unknown return format {$returnFormat}. Refer to the api_returnFormat class."); } }