Hi, Today we will learn how to integrate quickbooks online in laravel 5.1.
The very first thing we'll have to do is register our app with Intuit. When we do this, Intuit will give us these variables:
- app token
- consumer secret
- consumer key
The installation
Add this to your composer.json.
"require": { "consolibyte/quickbooks": "^3.1" },
This will give us a page in root folder, QuickBooks.php. Include this page in public/index.php.
require_once '../QuickBooks.php';
Now make a controller in app/Http/Controllers
QuickBookController.php.
Write following code to your controller:
class QuickBookController extends Controller { public function __Construct() { $oauth_consumer_key = 'your consumer key'; $oauth_consumer_secret = 'consumer secret'; $sandbox = true; // When you're using development tokens $dsn = 'mysqli://root:root@localhost/DbName'; $encryption_key = 'encryption key'; $the_username = 'DO_NOT_CHANGE_ME'; $the_tenant = 12345; if (!\QuickBooks_Utilities::initialized($dsn)) { // Initialize creates the neccessary database schema for queueing up requests and logging \QuickBooks_Utilities::initialize($dsn); } $IntuitAnywhere = new \QuickBooks_IPP_IntuitAnywhere($dsn, $encryption_key, $oauth_consumer_key, $oauth_consumer_secret, '', ''); if ($IntuitAnywhere->check($the_username, $the_tenant) && $IntuitAnywhere->test($the_username, $the_tenant)) { // Set up the IPP instance $IPP = new \QuickBooks_IPP($dsn); // Get our OAuth credentials from the database $creds = $IntuitAnywhere->load($the_username, $the_tenant); // Tell the framework to load some data from the OAuth store $IPP->authMode( \QuickBooks_IPP::AUTHMODE_OAUTH, $the_username, $creds); if ($sandbox) { // Turn on sandbox mode/URLs $IPP->sandbox(true); } // This is our current realm $this->realmId = $creds['qb_realm']; // Load the OAuth information from the database $this->context = $IPP->context(); } else { return false; } } public function getCustomerCount() { //echo csrf_token(); $VendorService = new \QuickBooks_IPP_Service_Vendor(); $vendors = $VendorService->query($this->context, $this->realmId, "SELECT * FROM Customer"); print_r($vendors); exit; foreach ($vendors as $Vendor) { print('Vendor Id=' . $Vendor->getId() . ' is named: ' . $Vendor->getDisplayName() . '<br>'); } } }
The constructer will give connection to quickbook online account. After that you can make function to your use like getCustomerCount().
No comments:
Post a Comment