I am using the Consolibyte PHP Quickbooks connect. I am getting an error after connecting to quickbooks:
something went wrong fetching user token
If I try again I get the error:
ErrorException in IntuitAnywhere.php line 468: Undefined index: oauth_token
I've been using this for almost a year now with no issues. Yesterday we weren't able to receive payment data from the api. I tried disconnecting and reconnecting and this started happening. I'm not sure what to do. We have mcrypt setup and we are using php 7. I also updated to the newest version of the github repo to see if that would fix it but it's still doing the same thing.
Thank you for your help!
Here is my config file
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Your application token (Intuit will give you this when you register an Intuit Anywhere app)
$token = env('TOKEN');
// Your OAuth consumer key and secret (Intuit will give you both of these when you register an Intuit app)
//
// IMPORTANT:
// To pass your tech review with Intuit, you'll have to AES encrypt these and
// store them somewhere safe.
//
// The OAuth request/access tokens will be encrypted and stored for you by the
// PHP DevKit IntuitAnywhere classes automatically.
$oauth_consumer_key = env('KEY');
$oauth_consumer_secret = env('SECRET');
// If you're using DEVELOPMENT TOKENS, you MUST USE SANDBOX MODE!!! If you're in PRODUCTION, then DO NOT use sandbox.
$sandbox = env('SANDBOX'); // When you're using development tokens
// $sandbox = true; // When you're using production tokens
// This is the URL of your OAuth auth handler page
$quickbooks_oauth_url = env('OAUTH');
// This is the URL to forward the user to after they have connected to IPP/IDS via OAuth
$quickbooks_success_url = env('SUCCESS');
// This is the menu URL script
$quickbooks_menu_url = env('MENU');
// This is a database connection string that will be used to store the OAuth credentials
// $dsn = 'pgsql://username:password@hostname/database';
// $dsn = 'mysql://username:password@hostname/database';
$dsn = 'mysqli://'.env('DB_USER').':'.env('DB_PASS').'@'. env('DB_HOST').'/'.env('DB');
// You should set this to an encryption key specific to your app
$encryption_key = env('ENCRYPT');
// Do not change this unless you really know what you're doing!!! 99% of apps will not require a change to this.
$the_username = 'DO_NOT_CHANGE_ME';
// The tenant that user is accessing within your own app
$the_tenant = 12345;
// Initialize the database tables for storing OAuth information
if (!\QuickBooks_Utilities::initialized($dsn)) {
// Initialize creates the neccessary database schema for queueing up requests and logging
\QuickBooks_Utilities::initialize($dsn);
}
// Instantiate our Intuit Anywhere auth handler
//
// The parameters passed to the constructor are:
// $dsn
// $oauth_consumer_key Intuit will give this to you when you create a new Intuit Anywhere application at AppCenter.Intuit.com
// $oauth_consumer_secret Intuit will give this to you too
// $this_url This is the full URL (e.g. http://path/to/this/file.php) of THIS SCRIPT
// $that_url After the user authenticates, they will be forwarded to this URL
//
$IntuitAnywhere = new \QuickBooks_IPP_IntuitAnywhere($dsn, $encryption_key, $oauth_consumer_key, $oauth_consumer_secret, $quickbooks_oauth_url, $quickbooks_success_url);
// Are they connected to QuickBooks right now?
if ($IntuitAnywhere->check($the_username, $the_tenant) and
$IntuitAnywhere->test($the_username, $the_tenant)
) {
// Yes, they are
$quickbooks_is_connected = true;
// 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);
}
// Print the credentials we're using
//print_r($creds);
// This is our current realm
$realm = $creds['qb_realm'];
// Load the OAuth information from the database
$Context = $IPP->context();
// Get some company info
$CompanyInfoService = new \QuickBooks_IPP_Service_CompanyInfo();
$quickbooks_CompanyInfo = $CompanyInfoService->get($Context, $realm);
return [$realm, $Context];
} else {
// No, they are not
$quickbooks_is_connected = false;
return [$realm, $Context];
}
}
Here is my connection file. It's a blade template so the script is included in my footer:
@extends('app')
@section('content')
<?php if ($quickbooks_is_connected): ?>
<ipp:blueDot></ipp:blueDot>
<?php endif; ?>
<div>
<p>
QuickBooks connection status:
<?php if ($quickbooks_is_connected): ?>
<div style="border: 2px solid green; text-align: center; padding: 8px; color: green;">
CONNECTED!<br>
<br>
</div>
<table>
<tr>
<td>
<a href="disconnect">Disconnect from QuickBooks</a>
</td>
<td>
(If you do this, you'll have to go back through the authorization/connection process to get connected again)
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<a href="reconnect">Reconnect / refresh connection</a>
</td>
<td>
(QuickBooks connections expire after 6 months, so you have to this roughly every 5 and 1/2 months)
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<a href="diagnostics">Diagnostics about QuickBooks connection</a>
</td>
<td>
</td>
</tr>
</table>
<?php else: ?>
<div style="border: 2px solid red; text-align: center; padding: 8px; color: red;">
<b>NOT</b> CONNECTED!<br>
<br>
<ipp:connectToIntuit></ipp:connectToIntuit>
<br>
<br>
You must authenticate to QuickBooks <b>once</b> before you can exchange data with it. <br>
<br>
<strong>You only have to do this once!</strong> <br><br>
After you've authenticated once, you never have to go
through this connection process again. <br>
Click the button above to
authenticate and connect.
</div>
<?php endif; ?>
</p>
</div>
@endsection
@section('scripts')
<script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>
<script type="text/javascript">
intuit.ipp.anywhere.setup({
menuProxy: '<?php print($quickbooks_menu_url); ?>',
grantUrl: '<?php print($quickbooks_oauth_url); ?>'
});
</script>
@endsection
I appologize if I'm not posting correctly, I haven't asked any questions on here before.
I ran the troubleshooting scripts mentioned by Keith, here is the output:
> Trying to hit URL: oauth.intuit.com/oauth/v1/get_request_token Did we disable SSL checks? false * Hostname was NOT found in DNS cache * Could not resolve host: oauth.intuit.com * Closing connection 67
Trying to hit URL: appcenter.intuit.com/api/v1/Connection/Reconnect Did we disable SSL checks? false * Hostname was NOT found in DNS cache * Could not resolve host: appcenter.intuit.com * Closing connection 68
Trying to hit URL: oauth.intuit.com/oauth/v1/get_request_token Did we disable SSL checks? true * Hostname was NOT found in DNS cache * Could not resolve host: oauth.intuit.com * Closing connection 69
Trying to hit URL: appcenter.intuit.com/api/v1/Connection/Reconnect Did we disable SSL checks? true * Hostname was NOT found in DNS cache * Could not resolve host: appcenter.intuit.com * Closing connection 70
php version: 7.0.1-4+deb.sury.org~trusty+1 mcrypt extension? true mcrypt module rijndael-256? NULL curl extension? true