Quickbooks – PHP integration

Integration:  PHP and Quickbooks using v3-php-sdk-2.0.5

This was a bit of headache. In this article I explain how to configure your quickbooks php sdk, issues faced, fixes until successful integration.

Some useful references to accomplish php / quickbook integration using the php sdk.
– download php sdk
http://bit.ly/IppPhpSdkV3

– PHP SDK for QuickBooks V3 documentation and getting started
https://developer.intuit.com/docs/0100_accounting/0500_developer_kits/0210_ipp_php_sdk_for_quickbooks_v3

*** Trying to Integrate
After download the v3-php-sdk-2.0.5 in order to accomplish the quickbooks integration, i have faced some serious problems to be able to integrate. After the installation I have set some settings in App.Config and directly accessed _Samples folder and decided to run the safest CustomerQuery.php – assuming it doesn’t cause any modification to our existing records :).
The first issue encountered was this:

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'DirectoryIterator::__construct(/var/folders/bn/gqvb2w4x7n3573t34xd1sdn00000gq/T): failed to open dir: Permission denied' in /var/www/test/v3-php-sdk-2.0.5/Core/LogRequestsToDisk.php:65 Stack trace: #0 /var/www/test/v3-php-sdk-2.0.5/Core/LogRequestsToDisk.php(65): DirectoryIterator->__construct('/var/folders/bn...') #1 /Applications/XAMPP/xamppfiles/htdocs/test/v3-php-sdk-2.0.5/Core/RestCalls/SyncRestHandler.php(227): LogRequestsToDisk->LogPlatformRequests('SELECT * FROM C...', 'https://sandbox...', Array, true) #2 /var/www/test/v3-php-sdk-2.0.5/DataService/DataService.php(572): SyncRestHandler->GetResponse(Object(RequestParameters), 'SELECT * FROM C...', NULL) #3 /var/www/test/v3-php-sdk-2.0.5/_Samples/CustomerQuery.php(37): DataService->Query('SELECT * FROM C...') #4 {main} thrown in /var/www/test/v3-php-sdk-2.0.5/Core/LogRequestsToDisk.php on line 65

After tracing the code i found out that the situation is caused by the following setting in sdk.config:
<requestLog enableRequestResponseLogging=”true” requestResponseLoggingDirectory=”/IdsLogs” />

So basically I thought, let’s turn the logging off. The result was still the same after mofifying the configuration:
<requestLog enableRequestResponseLogging=”false” requestResponseLoggingDirectory=”/IdsLogs” />

After tracing the code I discovered that a fix should be applied to overcome this problem.
*** Applied FIX:

/Core/LogRequestsToDisk.php / line 57:
if ($this->EnableServiceRequestsLogging)
replaced by
if ($this->EnableServiceRequestsLogging == ‘true’)

Description:
EnableServiceRequestsLogging was interpreted as string when using false value and on casting to bool the string word ‘false’ was considered to be true: (bool)’false’ –> true
After applying this fix we are ready to go and start setting up our configuration and the environment.
*** Quickbooks developer account – Creating an App
The first thing you want to do is to create an app on quickbooks developer account by connecting to which you will be integrating with your quickbooks online account. In order to achieve this, access:
https://developer.intuit.com

From the top right menu, click “My Apps” and then create a new App.

For this tutorial choose the “Just start coding” option on the right and then check “Accounting” out of Quickbooks API. So far you have an app and some keys for development. Now you need to click on the “Keys” tab and you will see the App Token , OAuth Consumer Key and OAuth Consumer Secret.

Basically the idea here is to generate AccessToken and AccessTokenSecret using the existing (App Token , OAuth Consumer Key and OAuth Consumer Secret). This will mean that your application with (App Token) will be granted access to your account data and services and will be authenticated by AccessToken and AccessTokenSecret, that you will use to connect from your application to the SDK.
Integration scenario
PHP CODE + SDK –(connected to)–> Developer Application –(connected to)–> Quickbooks APIs
*** Getting authentication tokens

In order to generate access token for your app to your whole account, you need to do this using the url:
https://appcenter.intuit.com/Playground/OAuth

following step-by step instructions, starting from the already defined App Token , OAuth Consumer Key and OAuth Consumer Secret, we will continue until we get AccessToken and AccessTokenSecret. After this point we have all the authentication tokens we need in order to configure our SDK.
*** Configuration
we need 2 configuration files:
App.Config – located at the path of the index file you are working on
sdk.config – located at the root path of the SDK

App.Config should containg the settings:
– RealmID (your company id, can include the sandbox company id)
– AccessToken
– AccessTokenSecret
– ConsumerKey
– ConsumerSecret
sdk.config should be adjusted:
<logger>
<!– To enable/disable Request and Response log–>
<requestLog enableRequestResponseLogging=”false” requestResponseLoggingDirectory=”/IdsLogs” />
</logger>
<service>
<baseUrl qbd=”https://quickbooks.api.intuit.com/” qbo=”https://sandbox-quickbooks.api.intuit.com/” ipp=”https://appcenter.intuit.com/api/” />
</service>
As we are integrating with quickbooks, we are concerned about “qbo” attribute of “baseUrl”.
In case we are on development environment and would like to use the actual company keys, we would need to use the default url:
https://quickbooks.api.intuit.com/

In case we are connecting to the sandbox company this url has to be changed to:
https://sandbox-quickbooks.api.intuit.com/

 

Sample App.Config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <intuit>
 <ipp>
 <!--Json serialization not supported in PHP SDK v1.0.0 -->
 <message>
 <request serializationFormat="Xml" compressionFormat="None"/>
 <response serializationFormat="Xml" compressionFormat="None"/>
 </message>
 <service>
 <baseUrl qbd="https://sandbox-quickbooks.api.intuit.com/v3" qbo="https://sandbox-quickbooks.api.intuit.com/v3" ipp="https://appcenter.intuit.com/api/" />
 </service>
 <logger>
 <!-- To enable/disable Request and Response log-->
 <requestLog enableRequestResponseLogging="false" requestResponseLoggingDirectory="IdsLogs/" />
 </logger>
 </ipp>
 </intuit>
 <appSettings>
 <!--These samples use a hard-coded realm ID and OAuth tokens. Enter the values below. -->
 <add key="AccessToken" value="xxxxx" />
 <add key="AccessTokenSecret" value="xxxxx" />
 <add key="ConsumerKey" value="xxxxx" />
 <add key="ConsumerSecret" value="xxxxx" />
 <add key="RealmID" value="xxxxx" />
 </appSettings>
</configuration>

 

Sample sdk.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <intuit>
 <ipp>
 <!--Json serialization not supported in PHP SDK v2.0.5 -->
 <message>
 <request serializationFormat="Xml" compressionFormat="None"/>
 <response serializationFormat="Xml" compressionFormat="None"/>
 </message>
 <service>
 <baseUrl qbd="https://quickbooks.api.intuit.com/" qbo="https://sandbox-quickbooks.api.intuit.com/" ipp="https://appcenter.intuit.com/api/" />
 </service>
 <logger>
 <!-- To enable/disable Request and Response log-->
 <requestLog enableRequestResponseLogging="false" requestResponseLoggingDirectory="IdsLogs/" />
 </logger>
 </ipp>
 </intuit>
</configuration>

 

 

If you have any ideas or suggestions or other experiences about PHP – Quickbooks SDK integration please comment below. 🙂
Happy integration !

Majd Arbash

...

Leave a Reply