コード例 #1
0
ファイル: api_post.php プロジェクト: jedrennen/intacctws-php
 /**
  * Internal method for posting the invocation to the Intacct XML Gateway
  *
  * @param String      $xml        the XML request document
  * @param api_session $session    an api_session instance with an active connection
  * @param string      $dtdVersion Either "2.1" or "3.0".  Defaults to "3.0"
  * @param boolean     $multiFunc  whether or not this invocation calls multiple methods.  Default is false
  *
  * @throws Exception
  * @return String the XML response document
  */
 private static function post($xml, api_session $session, $dtdVersion = "3.0", $multiFunc = false)
 {
     $sessionId = $session->sessionId;
     $endPoint = $session->endPoint;
     $senderId = $session->senderId;
     $senderPassword = $session->senderPassword;
     $transaction = $session->transaction ? 'true' : 'false';
     $templateHead = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<request>\n    <control>\n        <senderid>{$senderId}</senderid>\n        <password>{$senderPassword}</password>\n        <controlid>foobar</controlid>\n        <uniqueid>false</uniqueid>\n        <dtdversion>{$dtdVersion}</dtdversion>\n        {%validate}\n        <includewhitespace>false</includewhitespace>\n    </control>\n    <operation transaction='{$transaction}'>\n        <authentication>\n            <sessionid>{$sessionId}</sessionid>\n        </authentication>";
     $contentHead = "<content>\n            <function controlid=\"foobar\">";
     $contentFoot = "</function>\n        </content>";
     $templateFoot = "</operation>\n</request>";
     if (is_null($session->getResponseValidation())) {
         $templateHead = str_replace("{%validate}", '', $templateHead);
     } else {
         $templateHead = str_replace("{%validate}", '<validate>' . $session->getResponseValidation() . '</validate>', $templateHead);
     }
     if ($multiFunc) {
         $xml = $templateHead . $xml . $templateFoot;
     } else {
         $xml = $templateHead . $contentHead . $xml . $contentFoot . $templateFoot;
     }
     if (self::$dryRun == true) {
         self::$lastRequest = $xml;
         return null;
     }
     $count = 0;
     // retry five times on too many operations
     $res = "";
     while (true) {
         try {
             $res = api_post::execute($xml, $endPoint);
             api_post::validateResponse($res);
             break;
         } catch (Exception $ex) {
             if (strpos($ex->getMessage(), "too many operations") !== false || strpos($ex->getMessage(), "HTTP Response Code not 200") !== false) {
                 $count++;
                 if ($count >= 5) {
                     throw new Exception($ex);
                 }
             } else {
                 throw new Exception($ex);
             }
         }
     }
     return $res;
 }
コード例 #2
0
 /**
  * Create a session with the Intacct Web Services with an existing session.
  * You'll normally get the sessionid using a merge field (or injection parameter)
  * in an HTTP trigger or integration link
  *
  * @param String $sessionId      a valid Intacct session Id
  * @param String $senderId       Your Intacct partner sender id
  * @param String $senderPassword Your Intacct partner password
  *
  * @throws Exception This method returns no values, but will raise an exception if there's a connection error
  * @return null
  */
 public function connectSessionId($sessionId, $senderId, $senderPassword)
 {
     $xml = self::XML_HEADER . self::XML_SESSIONID . self::XML_FOOTER;
     $xml = str_replace("{1%}", $sessionId, $xml);
     $xml = str_replace("{4%}", $senderId, $xml);
     $xml = str_replace("{5%}", $senderPassword, $xml);
     if (is_null($this->getResponseValidation())) {
         $xml = str_replace("{6%}", "", $xml);
     } else {
         $xml = str_replace("{6%}", "<validate>" . $this->getResponseValidation() . "</validate>", $xml);
     }
     $response = api_post::execute($xml, self::DEFAULT_LOGIN_URL);
     self::validateConnection($response);
     $responseObj = simplexml_load_string($response);
     $this->sessionId = (string) $responseObj->operation->result->data->api->sessionid;
     $this->companyId = (string) $responseObj->operation->authentication->companyid;
     $this->userId = (string) $responseObj->operation->authentication->userid;
     $this->endPoint = (string) $responseObj->operation->result->data->api->endpoint;
     $this->senderId = $senderId;
     $this->senderPassword = $senderPassword;
 }