Skip to content

Instantly share code, notes, and snippets.

@myleshyson
Last active December 22, 2016 15:06
Show Gist options
  • Save myleshyson/8ee0c05b282d5f62b4343e85f018adba to your computer and use it in GitHub Desktop.
Save myleshyson/8ee0c05b282d5f62b4343e85f018adba to your computer and use it in GitHub Desktop.
Using QuickBooks Online WebHooks With Laravel

#Getting Set Up With QuickBooks

  1. If you haven't already, make an account with quickbooks here.
  2. Once you make an account sign in and go to MyApps, then create an app.
  3. Then in the nav under where it says your name, click on Sandbox and create a sandbox company.
  4. Once the app is created, go to your App dashboard and go to settings, then scroll till you see Webhooks. If you are working locally and using something like Larael Valet, you'll need to cd into your local site folder and run valet share. Reason being that QuickBooks needs a publically accesible url. Make sure to copy the https url and use that to point to where your endpoint code will run. Something like https://fde565689fgh.ngrok.io/some-uri. Quickbooks will send a post request to that url whenever one of the resources you specify changes.

#Getting Set Up On Your Site

  1. For starters, you'll need to have connected your app with quickbooks. I made a package that makes this really easy. You can find it here

  2. Once you connect your app to quickbooks your almost there. Create a post route that corresponds to the endpoint url in quickbooks. Something Like

    //routes/web.php
    
    Route::post('/some-uri', function(Request $request) {
     //handle the event from quickbooks
    });
  3. In that route, if you want to verify that the request is from quickbooks you need your webhook token. You can find that back in your quickbooks developer dashboard. Go to MyApps, then your App, then under settings where you set up your WebHooks token, you'll see a link that says show token. Copy that, and then use it like so in your route:

    //routes/web.php
    Route::post('/some-uri', function(Request $request) {
     $payloadHash = hash_hmac('sha256', file_get_contents("php://input"), 'YOUR_TOKEN_HERE');
     $singatureHash = bin2hex(base64_decode($request->server('HTTP_INTUIT_SIGNATURE')));
     
     if ($payloadHash == $singatureHash) {
         Log::notice('Something Happened From Quickbooks!');
     } else {
         Log::notice('Hmm this request doesnt seem to be from quickbooks');
    });

    Then in your app under storage/logs/laravel.log you should see 'Something Happened From Quickbooks!'.

    Quick Note It takes a little while for the request to come through. It seems quickbooks sends the requests in batches every 5 minutes or so. Unfortunately when testing this it'll take a while to see if anything actually happened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment