Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for calling intuit.ipp.anywhere.setup()?

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?

like image 821
The Machete Avatar asked Feb 19 '14 18:02

The Machete


1 Answers

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>
like image 57
dthagard Avatar answered Sep 23 '22 04:09

dthagard