6

This is a question about best practices for making the JavaScript call that generates the standard "Connect to QuickBooks" button (for establishing a connection to QuickBooks Harmony via Intuit's v3 REST API).

If I follow Intuit's example, I would:

  1. Reference https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js in a script tag.
  2. Place the <ipp:connectToIntuit></ipp:connectToIntuit> tagset where I want the "Connect to QuickBooks" button to display
  3. Cross my fingers and hope that intuit.ipp.anywhere.js isn't redirecting to a downtime message, again still exists
  4. Make my call to intuit.ipp.anywhere.setup()
  5. See the "Connect to QuickBooks" button

... which works (for many values of "works"), but feels pretty fragile:

  1. If intuit.ipp.anywhere.js is redirecting to a downtime message (read: not JavaScript) or is otherwise unavailable, I'll get a script error.
  2. If I get a script error (or something else goes wrong with Intuit's copy of the script), there isn't any feedback to the user, just a blank space where the "Connect to QuickBooks" button should be.

To make this all a little more resilient, I'm combining the reference to intuit.ipp.anywhere.js and the call to intuit.ipp.anywhere.setup() into a JQuery .ajax() call:

    $.ajax({
     url: 'https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js', 
     type: 'GET',
     dataType: 'script',
     timeout: 4000,
     success: function(response) {
      if (typeof intuit !== 'undefined') {
       intuit.ipp.anywhere.setup({
        menuProxy: 'MYMENUPROXYURL.aspx',
        grantUrl: 'MYGRANTURL.aspx'
       });
      }
     },
     error: function(x, t, m) {
       // show some friendly error message about Intuit downtime
     }        
    });

... which also works (for a few more values of "works"):

  1. My call to setup() is wrapped inside the success handler (and an additional check on the existence of the intuit Object), so I shouldn't get a script error if things go wrong.
  2. If the GET of Intuit's script times out (after 4000ms) or returns something that isn't script, I'll show a friendly error message to the user.

Has anyone else taken a different approach? And is Intuit back online?

The Machete
  • 255
  • 3
  • 12
  • Hey, this looks like a great start - does this make your browser stop using the local cache though? – Troy Anderson Mar 14 '14 at 14:27
  • @TroyAnderson We use the `.getScript` function which by default sets the cache to 'false'. With The Machete's post, he could add an explicit `cache: false` to the `.ajax` parameters. – dthagard Mar 14 '14 at 15:25
  • @TroyAnderson An explicit `cache: false` is not required on the `.ajax` parameters as the `dataType: script` will default the cache value to false ([reference](http://api.jquery.com/jquery.ajax/)) – Armin Sadeghi Feb 12 '15 at 05:39

1 Answers1

2

That's similar to how we've handled it. We had wrapped it in jQuery.getScript call, but apparently the .fail handler doesn't work with cross domain script tags. Our solution is as follows:

<script type="text/javascript>
    var timeoutID;
    timeoutID = window.setTimeout(function () {
        $("#ippConnectToIntuit").replaceWith('<p class="error-message">There was a problem communicating with QuickBooks. The service may be down or in heavy use. Try again later.</p>');
        }, 5000);
    $.getScript("https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js")
        .done(function () {
            window.clearTimeout(timeoutID);
            intuit.ipp.anywhere.setup({
                menuProxy: '/path/to/our/menu/proxy',
                grantUrl: '/path/to/our/grant/url'
            });
        });
</script>
<div id="ippConnectToIntuit"><ipp:connecttointuit></ipp:connecttointuit></div>
dthagard
  • 823
  • 7
  • 23