The example shows you how to:


Prerequisites


Set up

  1. In the composer.json file, note that the src/Example directory is mapped to the \Intacct\Example\ namespace in the autoloader:

    "autoload": {
      "psr-4": {
        "Intacct\\Example\\": "src/Example/"
      }
    }
    
  2. Open src/Example/AbstractTestObject.php and note how it extends Intacct\Functions\AbstractFunction.

    AbstractFunction is a helper class provided mainly to generate random control IDs. AbstractFunction implements Intacct\Functions\FunctionInterface, and any class whose instances will be executed by a client must implemement FunctionInterface. If using executeBatch, the parameter must be a FunctionInterface[] array.

  3. Open src/Example/TestObjectCreate.php and note how it extends AbstractTestObject.

    The FunctionInterface requires that the class implement the writeXml(XMLWriter &$xml) function. This implementation is where you provide the XML that will be processed at the gateway endpoint.

  4. Open src/Example/AbstractTestObject.php and replace test_object with the integration name for your custom object.

    const INTEGRATION_NAME = 'test_object';
    

Run the example

  1. Run the custom-object-function.php file:

    php custom-object-function.php
    
  2. Observe the terminal output, which should look similar to this:

    Created record ID 10153
       
    Process finished with exit code 0
    

    Note the record ID (for use below).

  3. Open the generated logs/intacct.html file in your browser and review the entries.

    The file provides info and debug entries. The SDK provides a debug entry for each HTTP request/response (with the Sage Intacct endpoint).

    Note that the log file was created by the HTML logger set in the client config.


Extra credit

Get the record by ID

  1. Update custom-object-function.php to execute a Read function that uses the record ID returned in the TestObjectCreate result.

    $read = new \Intacct\Functions\Common\Read();
    $read->setObjectName(\Intacct\Example\TestObjectCreate::INTEGRATION_NAME);
    $read->setKeys([
        $recordNo
    ]);
       
    $response = $client->execute($read);
    

Delete the record

  1. Create a TestObjectDelete class and execute an instance of it that uses the same record ID returned in the TestObjectCreate result.

    If you need help, see .

    <?php
       
    namespace Intacct\Example;
       
    use Intacct\Xml\XMLWriter;
       
    class TestObjectDelete extends AbstractTestObject
    {
       
        public function __construct($recordId)
        {
            $this->setId($recordId);
        }
           
        public function writeXml(XMLWriter &$xml)
        {
            $xml->startElement('function');
            $xml->writeAttribute('controlid', $this->getControlId());
       
            $xml->startElement('delete');
       
            $xml->writeElement('object', self::INTEGRATION_NAME);
            $xml->writeElement('keys', $this->getId());
       
            $xml->endElement(); // delete
            $xml->endElement(); // function
        }
    }
    

What’s next?

For more complex examples, you can use the functions in the SDK as models. For example, AbstractBill extends AbstractFunction, then BillCreate and BillDelete extend AbstractBill and write the XML for creating or deleting bills.

Provide feedback