Again, experimenting with Xero Connect and now it works if run from the command line but not from Epesi. If run from Epesi it doesn't get past the dashboard if url fetch is present in the code. Is there some kind of module timeout present in Epesi?
<?php
require 'vendor/autoload.php';
require 'utils.php';
define ( "XRO_APP_TYPE", "Private" );
define ( "OAUTH_CALLBACK", "oob" );
class XeroConnect {
function __construct($data_dir, $consumer_key, $secret_key) {
// print "In constructor\n";
$useragent = "XeroOAuth-PHP UserAgent";
$signatures = array (
'consumer_key' => $consumer_key,
'shared_secret' => $secret_key,
// API versions
'core_version' => '2.0',
'payroll_version' => '1.0',
'file_version' => '1.0'
);
if (XRO_APP_TYPE == "Private" || XRO_APP_TYPE == "Partner") {
$signatures ['rsa_private_key'] = Utils::join_paths($data_dir, 'printec_keys.pem');
$signatures ['rsa_public_key'] = Utils::join_paths($data_dir, 'printec_keys.cer');
}
print_r($signatures);
$this->XeroOAuth = new XeroOAuth ( array_merge ( array (
'application_type' => XRO_APP_TYPE,
'oauth_callback' => OAUTH_CALLBACK,
'user_agent' => $useragent
), $signatures ) );
$initialCheck = $this->XeroOAuth->diagnostics ();
$checkErrors = count ( $initialCheck );
if ($checkErrors > 0) {
echo "<br/>" . PHP_EOL;
// you could handle any config errors here, or keep on truckin if you like to live dangerously
foreach ( $initialCheck as $check ) {
echo 'Error: ' . $check . PHP_EOL;
}
} else {
$oauthSession = array (
'oauth_token' => $this->XeroOAuth->config ['consumer_key'],
'oauth_token_secret' => $this->XeroOAuth->config ['shared_secret'],
'oauth_session_handle' => ''
);
if (isset ( $oauthSession ['oauth_token'] )) {
$this->XeroOAuth->config ['access_token'] = $oauthSession ['oauth_token'];
$this->XeroOAuth->config ['access_token_secret'] = $oauthSession ['oauth_token_secret'];
}
$contacts_url = $this->XeroOAuth->url("Contacts", "core");
//$timestamp = mktime(12,0,0,5,6,2015);
//$mod_since_date = array('If-Modified-Since' => gmdate("M d Y H:i:s",$timestamp));
$mod_since_date = array();
// The following code does not work from Epesi (but shell only) and if left in won't
// get past the dashboard
$resp = $this->XeroOAuth->request("GET", $contacts_url, $mod_since_date, "", "json");
$contacts = json_decode($resp['response'],true);
foreach ($contacts['Contacts'] as $contact) {
echo $contact['ContactID'] . ' ' . $contact['Name'] . PHP_EOL;
}
// comment out code above to get to work in Epesi
}
}
}
// testing only, change to "true" if testing from shell or "false"
// if running from Epesi
// This part works!!!!
if (true) {
$consumer_key = "AENYJU0RNDRPLJO8L0ULIPTGHYJBKH";
$secret_key = "V25VTLF6N2ICWDFU25TOHHRTRVNUTD";
$data_dir = "C:/www/epesi-1.6.5/data/Custom_XeroConnect";
$obj = new XeroConnect($data_dir, $consumer_key, $secret_key);
}
?>
Any thoughts as to why Epesi is "timing out" back to the dashboard?
PS: I eventually will move the url fetches to cron jobs but was hoping just to test this out before moving further.
Regards
Glenn