예제 #1
0
 /**
  * Get API session array
  *
  * @param array $config
  * @return array
  */
 private function getAPISession(array $config)
 {
     $contentBlock = new Content();
     $getApiSession = new ApiSessionCreate();
     $contentBlock->append($getApiSession);
     $requestHandler = new RequestHandler($config);
     $response = $requestHandler->executeSynchronous($config, $contentBlock);
     $operation = $response->getOperation();
     $authentication = $operation->getAuthentication();
     $result = $operation->getResult(0);
     $data = $result->getData();
     $api = $data->api;
     $session = ['session_id' => strval($api->sessionid), 'endpoint_url' => strval($api->endpoint), 'verify_ssl' => $requestHandler->getVerifySSL(), 'current_company_id' => $authentication->getCompanyId(), 'current_user_id' => $authentication->getUserId(), 'current_user_is_external' => $authentication->getSlideInUser()];
     return $session;
 }
예제 #2
0
 /**
  * Execute an asynchronous request to the API
  *
  * @param Content $contentBlock Content block to send
  * @param string $asyncPolicyId Intacct asynchronous policy ID
  * @param bool $transaction Force the operation to be one transaction
  * @param string $requestControlId Request control ID
  * @param bool $uniqueFunctionControlIds Force the function control ID's to be unique
  * @param array $params Overriding params, @see IntacctClient::__construct()
  *
  * @return AsynchronousResponse
  */
 protected function executeAsync(Content $contentBlock, $asyncPolicyId, $transaction = false, $requestControlId = null, $uniqueFunctionControlIds = false, array $params = [])
 {
     $config = array_merge($this->getSessionConfig(), ['policy_id' => $asyncPolicyId, 'transaction' => $transaction, 'control_id' => $requestControlId, 'unique_id' => $uniqueFunctionControlIds], $params);
     $requestHandler = new RequestHandler($config);
     $response = $requestHandler->executeAsynchronous($config, $contentBlock);
     return $response;
 }
    /**
     * @covers Intacct\Xml\RequestHandler::__construct
     * @covers Intacct\Xml\RequestHandler::executeSynchronous
     * @covers Intacct\Xml\RequestHandler::execute
     * @covers Intacct\Xml\RequestHandler::setLogger
     * @covers Intacct\Xml\RequestHandler::setLogMessageFormatter
     * @covers Intacct\Xml\RequestHandler::setLogLevel
     */
    public function testMockExecuteWithDebugLogger()
    {
        $xml = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>sessionProvider</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>testuser</userid>
                  <companyid>testcompany</companyid>
                  <sessiontimestamp>2015-12-06T15:57:08-08:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>getAPISession</function>
                  <controlid>func1UnitTest</controlid>
                  <data>
                        <api>
                              <sessionid>unittest..</sessionid>
                              <endpoint>https://unittest.intacct.com/ia/xml/xmlgw.phtml</endpoint>
                        </api>
                  </data>
            </result>
      </operation>
</response>
EOF;
        $headers = ['Content-Type' => 'text/xml; encoding="UTF-8"'];
        $mockResponse = new Response(200, $headers, $xml);
        $mock = new MockHandler([$mockResponse]);
        $handle = fopen('php://memory', 'a+');
        $handler = new StreamHandler($handle, Logger::DEBUG);
        $logger = new Logger('unittest');
        $logger->pushHandler($handler);
        $config = ['control_id' => 'unittest', 'sender_id' => 'testsenderid', 'sender_password' => 'pass123!', 'session_id' => 'testsession..', 'mock_handler' => $mock, 'logger' => $logger];
        $contentBlock = new Content([new ApiSessionCreate()]);
        $requestHandler = new RequestHandler($config);
        $response = $requestHandler->executeSynchronous($config, $contentBlock);
        // Test for some output in the StreamHandler
        fseek($handle, 0);
        $this->assertEquals('[', substr(stream_get_contents($handle), 0, 1));
    }