Saturday, February 4, 2012

How to use Keith Palmer's PHP-DevKit to integrate a web app with Quickbooks Online

So here at Appguppy, we've been trying to enhance our e-commerce features to make it easier for our customers to sell stuff on their apps. One of the initiatives is to integrate our system with Quickbooks so that people can easily pull in their products and sell the through their app.

For this we needed to use Intuit's Partner Platform and their SDK. Unfortunately, they don't have a set of libraries for PHP, but since the IPP now allows oauth and XML, it is not too hard to integrate. Still, there are dozens of object types and thousands of properties that we need to build in, and that's very time consuming.

So along comes a new version of Keith Palmer's excellent PHP-DevKit. Which finally supports oauth. The problem is, it's not immediately obvious how to use it. Below is a step by step guide:

1. Download the latest devkit build. Unfortunately, its currently only available via SVN, so you'll have to install an SVN client and point it to this url:

svn checkout https://code.intuit.com/svn/repos/php_devkit

2.To create our simple app, we put it on a test server in our /var/www directory. You should now have a file Quickbooks.php and a sub-directory Quickbooks under /var/www

3. Make sure you have mcrypt installed in PHP, you can check this with phpinfo(). If not, download and install it.

4. Make a new file index.php and put the following in the file:

require_once 'QuickBooks.php';
$token = 'sfewtw4et3w45sfsfsdfdsf';
$oauth_consumer_key = 'sfewtwsetsgsdsdfsdc';
$oauth_consumer_secret = 'dsffwe5tr4w5sdfsdfsdfsdfsdf';
// This is the URL of your OAuth auth handler page
$this_url = 'http://myserver/index.php';
// This is the URL to forward the user to after they have connected to IPP/IDS via OAuth
$that_url = 'http://myserver/other.php';
$dsn = 'mysql://test:test@localhost/quickbooks';
// You should set this to an encryption key specific to your app
$encryption_key = 'abcd1234';
// The user that's logged in
$the_username = 'your_app_username_here_2';
// The tenant that user is accessing within your own app
$the_tenant = 12345;

The first request is made by the original php page (in our case index.php - but you can specify whatever you want in $this_url) to the oauth server with your oauth consumer secret and and oauth consumer key (I'll tell you how to get those in a sec). This is done by the handle() function in the IntuitAnywhere object.

The handle() function then redirects the user to the authentication URL, which shows one of those login/connect screens to the user (like you see when you use a Twitter app).

Once the user accepts the app, Intuit sends the user back to the page they were on (it will return to whatever is in $this_url -- in our case index.php). This time the handle() function sees that there is a token in the HTTP request and saves the token. It then redirects the user to another page ($that_url, or in our case other.php).

In other.php, we re-initialize the IntuitAnywhere object, but instead of using handle() to get the token, we use load() to load the token that was saved in the previous step.

We then create an IPP object specifying that we're using oauth, and that will provide us with a context from which to make calls.

6. Now let's make this thing work. First, get your token, oauth consumer key and oauth consumer secret from Intuit's Developer Center under Manage Apps -> (click on your Dev Master app) -> "App Tokens and Keys". In both index.php and other.php set the lines marked in purple above to those values.

7. Replace myserver (marked in green) in both files to your server URL. Also update the Mysql username and password (marked in blue) to yours

8. Create a database in mysql called quickbooks. This will be used to save tokens. All the tables will be created automatically by PHP Devkit.

9. That's it - now point your browser to http://myserver/index.php - it should redirect to the Intuit Anywhere authorization screen. Users can enter their username and password there and click to authorize your app. Once they do, it will go to other.php and you should see a list of customers for that user.

41 comments:

Raymond- the $the_tenant variable is something YOU provide- it's your OWN unique identifier for that particular customer/tenant of your web application.

e.g. if you identify your customers with a unique #, then put your unique customer # there. If you identify them with a domain name (e.g. "their-company.your-website.com") then you could pass in their subdomain.

Hi Raymond- did you read my comment above and look at the example code? All you have to do is set the $the_tenant variable to your unique identifier for your customer (e.g. your customer ID or customer primary key value). If you look in the example files, it's set in the example_ipp_config.php file.

Pawanvir - if you're having trouble, you should post on the forums. The forums are the best avenue for technical support. http://www.consolibyte.com/forum/ You should consider posting your code so that we can see what you're doing. - Keith

Thanks for replying. I will have Pawanvir to show the code. However i would like to know your views as what we are trying to achieve is possible.

We are using core php to create our custom shopping cart and trying to connect it to clients QuickBooks Software. However we never used quickbooks. I read on some forums that it will be done through some web connector, however they are asp.net based. Pl. advise if the solutions is still possible in php and what will be the steps involved.

If you are building a custom, one-off shopping cart *for a single customer* then you should be using the Web Connector, not IPP. Again, post on our forums or the Intuit forums if you need more details.

If you are building an SaaS application which allows many of your end-users to connect their QuickBooks files to your app, and you charge a recurring fee for it, then Intuit Anywhere is the appropriate choice.

now i cant understand how to start set up code or how to use this code??

what i need to do that i make a one online shopping cart system. when customer purchase order than invoice also generate in quickbook... i need a quickbook online so can u pls help me or guide me how to do???

I have also integrated this code in my application. But I am not able getting any customer details. Please tell me what we have to input in "$encryption_key" variable and "$the_tenant" variable.Waiting for your response.

Look, I'm not trying to be mean here - the bottom line is just that this comment board is just not a good way to provide support. Comments posted on this blog aren't searchable, they mangle code snippets, they aren't separated into relevant topics, and the answers posted here just generally don't benefit the community as a whole, because very few people are going to see the comments here.

For that reason, we don't provide support via this board.

If you want support, PLEASE PLEASE PLEASE ask on the forums. We're a small open-source project team, and we simply can't waste our time answering your questions here when all they do is make a mess of everything we say. If you at all value our contributions to the open-source community, please be appreciative of that and ask your questions on the forums.

Lucki - if you get that message, it also shows you an e-mail address to email and your IP address. Send an email to that address with your IP address, and we'll unblock you. It's likely because someone was/is using your IP to send SPAM.

I have configured the QuickBooks now how actually it shuld be integrated with the existing PHP CMS application the Example index.php and all are working but noiw i have live php files how to integrated our database with QuickBooks Please Let me know as i am facing my deadlines

Do i need to install the Web Connector or just use this Framework that will work for me i have just installed the framework for PHP CMS application but then how to keep it in Sync with my database please let me know..

Hello Keith,I have started to work on quickbook.Following step i have done-1.Download v3-php-sdk-2.0.5 (1)2.Download quickbooks-devkit3.Under build folder(after extract of quickbook).I create index.php ,other.php.4.Create a account on developer.intuit.com and update the secreet key token in my files.Please tell me next step.Thanks

quickbooks helpline number - Are you new user for QuickBooks or facing issues in your quick QuickBooks software? We are a leading QuickBooks tech support provider company in USA. Call us at QuickBooks helpline number 1-855-861-4161 and get solutions for the issues that you are facing.