Overview

You use anIntacctClient to perform one or more operations on your company data. You should use the generic classes to get information about objects, and use the object-specific classes for creating, updating, or deleting objects.

You create and send a request as follows:

  1. Construct an IntacctClient instance.

  2. For each operation you want to perform, construct an instance of a class that extends AbstractFunction. Set field values on that instance.

  3. Create a Content instance, providing an array of your class instances to the constructor.

  4. Pass the Content instance into the execute method of your IntacctClient to send the request.

  5. Parse the response from the execute method. Data results are in the Results object.

Construct an IntacctClient

The IntacctClient constructor can provide login credentials, configuration options, logger choices, and so forth. The following shows a basic constructor that accesses credentials from a separate file.

<?php
$client = new IntacctClient([
    'profile_file' => __DIR__ . '\.intacct\credentials.ini',
]);

See About the SDK for more information about providing credentials.

Set up the operations

To make a gateway request, you first need to create an instance of a class for the operation you want, then use the setters to provide the details. For example, the following creates two instances, one that will be used to create a CUSTOMER object, and another that will be used to update a CUSTOMER object.

<?php
$customerCreate = new CustomerCreate();  
$customerCreate->setCustomerName("Joshua Granley");

$customerUpdate = new CustomerUpdate();
$customerUpdate->setCustomerId(10206);  
$customerUpdate->setComments("Gold star customer!");

Note: The object-specific functions provide getters and setters that map underlying XML element names to more intuitive names. However, the generic functions (including the read functions) still use the XML element names for inputs and outputs. In other words, this SDK does not serialize objects between read and create/update/delete operations. In order to use the output from a read function as the input for an object-specific function, you need to translate XML element names to the appropriate getters and setters. You can see examples of this in the tests (such as test/Intacct/Functions/AccountsReceivable/CustomerCreateTest.php). Note that developers are welcome to fork the SDK, enhance it with support for serialization, and provide a pull request.

Create a Content instance with an array of operations

You create a single Content instance to wrap your operations, for example:

<?php
$content = new Content([$customerCreate, $customerUpdate]); 

Execute the request

To send the request, call execute on your client and pass in the Content instance.

<?php
$response = $client->execute($content);  

Behind the scenes, the AbstractClient parent class converts the SDK calls into XML API calls and sends them to the gateway. By default, the operations will be processed independently—If one fails, the others still proceed. You can use a transaction to group the operations into a unit that will success or fail as a group. To do this, set the $transaction parameter to true in the execute call.

If you want to receive asynchronous responses from the gateway, you can do this with executeAsyc. However, you must first work with Intacct to configure asynchronous processing.

Handle the response

An execute call returns a SynchronousResponse instance that encapsulates the information returned from the gateway. You can get a SimpleXMLIterator from the SynchronousResponse so you can iterate all the results. For example:

<?php
$response->getOperation()->getResults();
    foreach ($simpleXMLresponses as $data) {
        var_dump($data);
    }

You have direct access to the XML objects, so you can convert them to JSON or parse them into your own PHP objects. (This is beyond the scope of the current SDK, but you are encouraged to do it yourself and share your work!)

If there is an error, data will not be returned. You must catch any errors that are thrown.

If want to see the complete XML of the response, you can view it as follows:

<?php
print_r($response);

Error Handling

See Error Handling for information about general errors that must be handled for both IntacctClient and QueryClient requests.

If you are using transactions with your IntacctClient, you can use code such as the following to get information about failures:

<?php
$results = $response->getOperation()->getResults();
$i = 0;
foreach ($results as $data) {
    if($data->getStatus() == "aborted" && count($data->getErrors()) >  0) {
        echo "Errors in result number $i have caused the rollback" . ":\n";
        var_dump($data);
    }
    $i++;
}

What’s Next?

Provide feedback