예제 #1
0
    /**
     * @covers Intacct\Xml\RequestBlock::__construct
     * @covers Intacct\Xml\RequestBlock::writeXml
     */
    public function testWriteXml()
    {
        $expected = <<<EOF
<?xml version="1.0" encoding="iso-8859-1"?>
<request><control><senderid>testsenderid</senderid><password>pass123!</password><controlid>unittest</controlid><uniqueid>false</uniqueid><dtdversion>3.0</dtdversion><includewhitespace>false</includewhitespace></control><operation transaction="false"><authentication><sessionid>testsession..</sessionid></authentication><content></content></operation></request>
EOF;
        $config = ['sender_id' => 'testsenderid', 'sender_password' => 'pass123!', 'session_id' => 'testsession..', 'control_id' => 'unittest'];
        $contentBlock = new Content();
        $requestHandler = new RequestBlock($config, $contentBlock);
        $xml = $requestHandler->writeXml();
        $this->assertXmlStringEqualsXmlString($expected, $xml->flush());
    }
    /**
     * @covers Intacct\Logging\MessageFormatter::format
     */
    public function testRequestAndResponseRemoval()
    {
        $config = ['control_id' => 'unittest', 'sender_id' => 'testsenderid', 'sender_password' => 'pass123!', 'company_id' => 'testcompany', 'user_id' => 'testuser', 'user_password' => 'P@ssW0rd!123'];
        $contentBlock = new Content([new ApiSessionCreate('unittest')]);
        $xmlRequest = new RequestBlock($config, $contentBlock);
        $xmlResponse = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<response>
    <control>
        <status>success</status>
        <senderid>testsenderid</senderid>
        <controlid>testControl</controlid>
        <uniqueid>false</uniqueid>
        <dtdversion>3.0</dtdversion>
    </control>
    <operation>
        <authentication>
            <status>success</status>
            <userid>testuser</userid>
            <companyid>testcompany</companyid>
            <sessiontimestamp>2016-08-22T10:58:43-07:00</sessiontimestamp>
        </authentication>
        <result>
            <status>success</status>
            <function>get_list</function>
            <controlid>test1</controlid>
            <listtype start="0" end="0" total="1">vendor</listtype>
            <data>
                <vendor>
                    <recordno>4</recordno>
                    <vendorid>V0004</vendorid>
                    <name>Vendor 4</name>
                    <taxid>99-9999999</taxid>
                    <achenabled>true</achenabled>
                    <achaccountnumber>1111222233334444</achaccountnumber>
                    <achaccounttype>Checking Account</achaccounttype>
                </vendor>
            </data>
        </result>
        <result>
            <status>success</status>
            <function>readByQuery</function>
            <controlid>test2</controlid>
            <data listtype="vendor" count="1" totalcount="1" numremaining="0" resultId="">
                <vendor>
                    <RECORDNO>4</RECORDNO>
                    <VENDORID>V0004</VENDORID>
                    <NAME>Vendor 4</NAME>
                    <TAXID>99-9999999</TAXID>
                    <ACHENABLED>true</ACHENABLED>
                    <ACHACCOUNTNUMBER>1111222233334444</ACHACCOUNTNUMBER>
                    <ACHACCOUNTTYPE>Checking Account</ACHACCOUNTTYPE>
                </vendor>
            </data>
        </result>
    </operation>
</response>
EOF;
        $mockRequest = new Request('POST', 'https://unittest.intacct.com', [], $xmlRequest->writeXml()->flush());
        $mockResponse = new Response(200, [], $xmlResponse);
        $formatter = new MessageFormatter("{req_body}/n/r{res_body}");
        $message = $formatter->format($mockRequest, $mockResponse);
        $this->assertNotContains('<password>pass123!</password>', $message);
        $this->assertNotContains('<password>P@ssW0rd!123</password>', $message);
        $this->assertContains('<password>REDACTED</password>', $message);
        $this->assertNotContains('<taxid>99-9999999</taxid>', $message);
        $this->assertNotContains('<TAXID>99-9999999</TAXID>', $message);
        $this->assertContains('<taxid>REDACTED</taxid>', $message);
        $this->assertContains('<TAXID>REDACTED</TAXID>', $message);
        $this->assertNotContains('<achaccountnumber>1111222233334444</achaccountnumber>', $message);
        $this->assertNotContains('<ACHACCOUNTNUMBER>1111222233334444</ACHACCOUNTNUMBER>', $message);
        $this->assertContains('<achaccountnumber>REDACTED</achaccountnumber>', $message);
        $this->assertContains('<ACHACCOUNTNUMBER>REDACTED</ACHACCOUNTNUMBER>', $message);
    }
예제 #3
0
 /**
  * Execute a request asynchronously with a policy ID
  *
  * @param array $params
  * @param Content $contentBlock
  *
  * @return AsynchronousResponse
  */
 public function executeAsynchronous(array $params, Content $contentBlock)
 {
     $defaults = ['policy_id' => null];
     $config = array_merge($defaults, $params);
     if (!isset($params['policy_id'])) {
         throw new InvalidArgumentException('Required "policy_id" key not supplied in params for asynchronous request');
     }
     $requestBlock = new RequestBlock($config, $contentBlock);
     $client = $this->execute($requestBlock->writeXml());
     $body = $client->getBody();
     $body->rewind();
     $response = new AsynchronousResponse($body->getContents());
     return $response;
 }