Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1. error_reporting(E_ALL);
  2. ini_set('display_errors', 1);
  3.  
  4.  
  5. // Your application token (Intuit will give you this when you register an Intuit Anywhere app)
  6. $token = env('TOKEN');
  7.  
  8. // Your OAuth consumer key and secret (Intuit will give you both of these when you register an Intuit app)
  9. //
  10. // IMPORTANT:
  11. // To pass your tech review with Intuit, you'll have to AES encrypt these and
  12. // store them somewhere safe.
  13. //
  14. // The OAuth request/access tokens will be encrypted and stored for you by the
  15. // PHP DevKit IntuitAnywhere classes automatically.
  16. $oauth_consumer_key = env('KEY');
  17. $oauth_consumer_secret = env('SECRET');
  18.  
  19. // If you're using DEVELOPMENT TOKENS, you MUST USE SANDBOX MODE!!! If you're in PRODUCTION, then DO NOT use sandbox.
  20. $sandbox = env('SANDBOX'); // When you're using development tokens
  21. // $sandbox = true; // When you're using production tokens
  22.  
  23. // This is the URL of your OAuth auth handler page
  24. $quickbooks_oauth_url = env('OAUTH');
  25.  
  26. // This is the URL to forward the user to after they have connected to IPP/IDS via OAuth
  27. $quickbooks_success_url = env('SUCCESS');
  28.  
  29. // This is the menu URL script
  30. $quickbooks_menu_url = env('MENU');
  31.  
  32. // This is a database connection string that will be used to store the OAuth credentials
  33. // $dsn = 'pgsql://username:password@hostname/database';
  34. // $dsn = 'mysql://username:password@hostname/database';
  35. $dsn = 'mysqli://'.env('DB_USER').':'.env('DB_PASS').'@'. env('DB_HOST').'/'.env('DB');
  36.  
  37. // You should set this to an encryption key specific to your app
  38. $encryption_key = env('ENCRYPT');
  39.  
  40. // Do not change this unless you really know what you're doing!!! 99% of apps will not require a change to this.
  41. $the_username = 'DO_NOT_CHANGE_ME';
  42.  
  43. // The tenant that user is accessing within your own app
  44. $the_tenant = 12345;
  45.  
  46. // Initialize the database tables for storing OAuth information
  47. if (!QuickBooks_Utilities::initialized($dsn)) {
  48. // Initialize creates the neccessary database schema for queueing up requests and logging
  49. QuickBooks_Utilities::initialize($dsn);
  50. }
  51.  
  52. // Instantiate our Intuit Anywhere auth handler
  53. //
  54. // The parameters passed to the constructor are:
  55. // $dsn
  56. // $oauth_consumer_key Intuit will give this to you when you create a new Intuit Anywhere application at AppCenter.Intuit.com
  57. // $oauth_consumer_secret Intuit will give this to you too
  58. // $this_url This is the full URL (e.g. http://path/to/this/file.php) of THIS SCRIPT
  59. // $that_url After the user authenticates, they will be forwarded to this URL
  60. //
  61. $IntuitAnywhere = new QuickBooks_IPP_IntuitAnywhere($dsn, $encryption_key, $oauth_consumer_key, $oauth_consumer_secret, $quickbooks_oauth_url, $quickbooks_success_url);
  62.  
  63. // Are they connected to QuickBooks right now?
  64. if ($IntuitAnywhere->check($the_username, $the_tenant) and
  65. $IntuitAnywhere->test($the_username, $the_tenant)
  66. ) {
  67. // Yes, they are
  68. $quickbooks_is_connected = true;
  69.  
  70. // Set up the IPP instance
  71. $IPP = new QuickBooks_IPP($dsn);
  72.  
  73. // Get our OAuth credentials from the database
  74. $creds = $IntuitAnywhere->load($the_username, $the_tenant);
  75.  
  76. // Tell the framework to load some data from the OAuth store
  77. $IPP->authMode(
  78. QuickBooks_IPP::AUTHMODE_OAUTH,
  79. $the_username,
  80. $creds
  81. );
  82.  
  83. if ($sandbox) {
  84. // Turn on sandbox mode/URLs
  85. $IPP->sandbox(true);
  86. }
  87.  
  88. // Print the credentials we're using
  89. //print_r($creds);
  90.  
  91. // This is our current realm
  92. $realm = $creds['qb_realm'];
  93.  
  94. // Load the OAuth information from the database
  95. $Context = $IPP->context();
  96.  
  97. // Get some company info
  98. $CompanyInfoService = new QuickBooks_IPP_Service_CompanyInfo();
  99. $quickbooks_CompanyInfo = $CompanyInfoService->get($Context, $realm);
  100.  
  101. return [$realm, $Context];
  102. } else {
  103. // No, they are not
  104. $quickbooks_is_connected = false;
  105.  
  106. return [$realm, $Context];
  107. }
  108. }
  109.  
  110. @extends('app')
  111.  
  112. @section('content')
  113.  
  114.  
  115. <?php if ($quickbooks_is_connected): ?>
  116. <ipp:blueDot></ipp:blueDot>
  117. <?php endif; ?>
  118.  
  119. <div>
  120. <p>
  121. QuickBooks connection status:
  122.  
  123. <?php if ($quickbooks_is_connected): ?>
  124. <div style="border: 2px solid green; text-align: center; padding: 8px; color: green;">
  125. CONNECTED!<br>
  126. <br>
  127.  
  128. </div>
  129.  
  130. <table>
  131. <tr>
  132. <td>
  133. <a href="disconnect">Disconnect from QuickBooks</a>
  134. </td>
  135. <td>
  136. (If you do this, you'll have to go back through the authorization/connection process to get connected again)
  137. </td>
  138. </tr>
  139. <tr>
  140. <td>&nbsp;</td>
  141. <td>&nbsp;</td>
  142. </tr>
  143. <tr>
  144. <td>
  145. <a href="reconnect">Reconnect / refresh connection</a>
  146. </td>
  147. <td>
  148. (QuickBooks connections expire after 6 months, so you have to this roughly every 5 and 1/2 months)
  149. </td>
  150. </tr>
  151. <tr>
  152. <td>&nbsp;</td>
  153. <td>&nbsp;</td>
  154. </tr>
  155. <tr>
  156. <td>
  157. <a href="diagnostics">Diagnostics about QuickBooks connection</a>
  158. </td>
  159. <td>
  160. &nbsp;
  161. </td>
  162. </tr>
  163. </table>
  164.  
  165. <?php else: ?>
  166. <div style="border: 2px solid red; text-align: center; padding: 8px; color: red;">
  167. <b>NOT</b> CONNECTED!<br>
  168. <br>
  169. <ipp:connectToIntuit></ipp:connectToIntuit>
  170. <br>
  171. <br>
  172. You must authenticate to QuickBooks <b>once</b> before you can exchange data with it. <br>
  173. <br>
  174. <strong>You only have to do this once!</strong> <br><br>
  175.  
  176. After you've authenticated once, you never have to go
  177. through this connection process again. <br>
  178. Click the button above to
  179. authenticate and connect.
  180. </div>
  181. <?php endif; ?>
  182.  
  183. </p>
  184. </div>
  185. @endsection
  186. @section('scripts')
  187. <script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>
  188. <script type="text/javascript">
  189. intuit.ipp.anywhere.setup({
  190. menuProxy: '<?php print($quickbooks_menu_url); ?>',
  191. grantUrl: '<?php print($quickbooks_oauth_url); ?>'
  192. });
  193. </script>
  194. @endsection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement