Ver código fonte

xero oauth2 has been successfully skeletoned with init_wp () working for sync_pay_item().

master
sp 4 anos atrás
pai
commit
e36adaf4e8
13 arquivos alterados com 289 adições e 10 exclusões
  1. +1
    -0
      .gitignore
  2. +8
    -0
      .idea/.gitignore
  3. +8
    -0
      .idea/modules.xml
  4. +36
    -0
      .idea/php.xml
  5. +35
    -0
      .idea/ts.iml
  6. +6
    -0
      .idea/vcs.xml
  7. +168
    -0
      Storage.php
  8. +3
    -3
      XeroOauth1.php
  9. +10
    -0
      css/bts_office.css
  10. +2
    -2
      html/timesheet_canvas_v1.html
  11. +1
    -1
      js/bts_timesheet.js
  12. +1
    -1
      js/xeroc.js
  13. +10
    -3
      ts.php

+ 1
- 0
.gitignore Ver arquivo

.buildpath .buildpath
.project .project
sample sample
/vendor/

+ 8
- 0
.idea/.gitignore Ver arquivo

# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

+ 8
- 0
.idea/modules.xml Ver arquivo

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ts.iml" filepath="$PROJECT_DIR$/.idea/ts.iml" />
</modules>
</component>
</project>

+ 36
- 0
.idea/php.xml Ver arquivo

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpIncludePathManager">
<include_path>
<path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/version" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/diff" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/recursion-context" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/exporter" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/doctrine/instantiator" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/environment" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/comparator" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/sebastian/global-state" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpspec/prophecy" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/phpunit" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/webmozart/assert" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/symfony/yaml" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-code-coverage" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/phpunit-mock-objects" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-token-stream" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/composer" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-text-template" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-file-iterator" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpunit/php-timer" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpdocumentor/reflection-docblock" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpdocumentor/type-resolver" />
<path value="$PROJECT_DIR$/xero-php-master/vendor/phpdocumentor/reflection-common" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="5.5.0" />
<component name="PhpUnit">
<phpunit_settings>
<PhpUnitSettings custom_loader_path="$PROJECT_DIR$/xero-php-master/vendor/autoload.php" />
</phpunit_settings>
</component>
</project>

+ 35
- 0
.idea/ts.iml Ver arquivo

<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/xero-php-master/src/XeroPHP" isTestSource="false" packagePrefix="XeroPHP\" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/version" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/diff" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/recursion-context" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/exporter" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/doctrine/instantiator" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/environment" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/comparator" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/sebastian/global-state" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpspec/prophecy" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/phpunit" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/webmozart/assert" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/symfony/yaml" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-code-coverage" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/phpunit-mock-objects" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-token-stream" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-text-template" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-file-iterator" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpunit/php-timer" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpdocumentor/reflection-docblock" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpdocumentor/type-resolver" />
<excludeFolder url="file://$MODULE_DIR$/xero-php-master/vendor/phpdocumentor/reflection-common" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

+ 6
- 0
.idea/vcs.xml Ver arquivo

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 168
- 0
Storage.php Ver arquivo

<?php
namespace Biukop;

class StorageClass
{
private $path;

private $oauth2 = [];
private $oauth2state = "";
function __construct() {
$this->path = dirname(__FILE__) . "/xero.json";
// \Carbon_Fields\Carbon_Fields::boot();
// if( !isset($_SESSION) ){
// $this->init_session();
// }
}

public function read_value() {
$this->oauth2state = carbon_get_theme_option("xero_oauth2state");
$this->oauth2["token"] = carbon_get_theme_option("xero_token");
$this->oauth2["refresh_token"] = carbon_get_theme_option("xero_refresh_token");
$this->oauth2["expires"] = carbon_get_theme_option("xero_expires");
$this->oauth2["tenant_id"] = carbon_get_theme_option("xero_tenant_id");
$this->oauth2["id_token"] = carbon_get_theme_option("xero_id_token");

$this->oauth2['expires_human'] = $this->getExpiresHuman($this->oauth2["expires"]);
}

public function init_session(){
// session_start();
}

public function getSession() {
return $this->oauth2;
// return $_SESSION['oauth2'];
}

private function write_json() {
$serialize = [
"oauth2state" => $this->getOauth2State(),
"oauth2" => $this->oauth2,
];
file_put_contents($this->path , json_encode($serialize));
}

public function startSession($token, $secret, $expires = null)
{
// session_start();
}

public function setToken($token, $expires = null, $tenantId, $refreshToken, $idToken)
{
// $_SESSION['oauth2'] = [
// 'token' => $token,
// 'expires' => $expires,
// 'tenant_id' => $tenantId,
// 'refresh_token' => $refreshToken,
// 'id_token' => $idToken
// ];

$this->oauth2 = [
'token' => $token,
'expires' => $expires,
'tenant_id' => $tenantId,
'refresh_token' => $refreshToken,
'id_token' => $idToken,
'expires_human' => $this->getExpiresHuman($expires)
];

carbon_set_theme_option("xero_token", $token);
carbon_set_theme_option("xero_refresh_token", $refreshToken);
carbon_set_theme_option("xero_expires", $expires);
carbon_set_theme_option("xero_tenant_id", $tenantId);
carbon_set_theme_option("xero_id_token", $idToken);
carbon_set_theme_option("xero_expires_human", $this->getExpiresHuman($expires));

$this->write_json();
}

public function getOauth2State() {
$this->oauth2state = carbon_get_theme_option("xero_oauth2state");
return $this->oauth2state;
}

public function setOauth2State($state) {
$this->oauth2state = $state;
carbon_set_theme_option("xero_oauth2state", $state);
$this->write_json();
}


private function getExpiresHuman($time_stamp) {
$expire = date("Y-m-d H:i:s", $time_stamp);
$utc_date = \DateTime::createFromFormat(
"Y-m-d H:i:s",
$expire,
new \DateTimeZone('UTC')
);

$sydney_date = $utc_date;
$sydney_date->setTimeZone(new \DateTimeZone('Australia/Sydney'));
$str = $sydney_date->format("Y-m-d H:i:s");
return $str;
}

public function getToken()
{
//If it doesn't exist or is expired, return null
// if (empty($this->getSession())
// || ($_SESSION['oauth2']['expires'] !== null
// && $_SESSION['oauth2']['expires'] <= time())
// ) {
// return null;
// }
// return $this->getSession();

if ( $this->oauth2['expires'] !== null && $this->oauth2['expires'] <= time() ) {
return null;
}
return $this->oauth2;
}

public function getAccessToken()
{
//return $_SESSION['oauth2']['token'];
return $this->oauth2['token'];
}

public function getRefreshToken()
{
// return $_SESSION['oauth2']['refresh_token'];
return $this->oauth2['refresh_token'];
}

public function getExpires()
{
//return $_SESSION['oauth2']['expires'];
return $this->oauth2['expires'];
}

public function getXeroTenantId()
{
//return $_SESSION['oauth2']['tenant_id'];
return $this->oauth2['tenant_id'];
}

public function getIdToken()
{
// return $_SESSION['oauth2']['id_token'];
return $this->oauth2['id_token'];
}

public function getHasExpired()
{
if (!empty($this->getSession()))
{
if(time() > $this->getExpires())
{
return true;
} else {
return false;
}
} else {
return true;
}
}
}
?>

Xero.php → XeroOauth1.php Ver arquivo

use \XeroPHP\Remote\Exception\RateLimitExceededException; use \XeroPHP\Remote\Exception\RateLimitExceededException;
use \XeroPHP\Remote\Exception\NotFoundException; use \XeroPHP\Remote\Exception\NotFoundException;


class Xero {
class XeroOauth1 {
private $xero; private $xero;
private $clientgroup="48646f3d-cf5e-4fea-8c8b-5812bd540e1b"; private $clientgroup="48646f3d-cf5e-4fea-8c8b-5812bd540e1b";
private $minimum_sync_interval_in_seconds = 600; private $minimum_sync_interval_in_seconds = 600;
$this->sync_employees(); $this->sync_employees();
} }
}catch(RateLimitExceededException $e){ }catch(RateLimitExceededException $e){
$msg= "Xero API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n";
$msg= "XeroOauth1 API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n";
$this->logConsole($msg); $this->logConsole($msg);
}catch(NotFoundException $e){ }catch(NotFoundException $e){
$msg= "Xero API resource not found rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n";
$msg= "XeroOauth1 API resource not found rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n";
$this->logConsole($msg); $this->logConsole($msg);
} }
} }

+ 10
- 0
css/bts_office.css Ver arquivo



} }


.sheettitle h1.today {
margin: 0 auto 0 auto;
color: darkgrey;
display: inline-block;
font-size: 1.1em;
}

.sheettitle h1:hover { .sheettitle h1:hover {
text-decoration: underline; text-decoration: underline;
font-weight: bolder; font-weight: bolder;
cursor: pointer; cursor: pointer;
color: black;
font-size: 1.3em;
/* animation: blinker 1s linear infinite; */ /* animation: blinker 1s linear infinite; */
} }



.timesheets { .timesheets {
width: calc(100vw - 300px); width: calc(100vw - 300px);
height: 100vh; height: 100vh;

+ 2
- 2
html/timesheet_canvas_v1.html Ver arquivo

</div> </div>
<div class='timesheets'> <div class='timesheets'>
<div class='sheettitle titlebar_gradient'> <div class='sheettitle titlebar_gradient'>
<h1>Web Office 2020 - Today:<span name='today'> Today </span> <a style="float:right;margin-right:20px;" href="/time-sheets/"> (old verion 2019) </a></h1>
<h1 class="today">Web Office 2021 - Today:<span name='today'> Today </span></h1>
</div> </div>
<div class='sheetsheader'> <div class='sheetsheader'>
<div class='weekly'> <div class='weekly'>
Confirm_Schedule Confirm_Schedule
</button> </button>
</div> </div>
</div>
</div>

+ 1
- 1
js/bts_timesheet.js Ver arquivo

return false; return false;
} }
// if (this.get_rate() != this.data.rate){ // if (this.get_rate() != this.data.rate){
// this.set_err_msg_rate('rate@Xero inactive ' + this.data.rate);
// this.set_err_msg_rate('rate@XeroOauth1 inactive ' + this.data.rate);
// this.mark_rate_invalid(); // this.mark_rate_invalid();
// this.mark_dirty(); // this.mark_dirty();
// return false; // return false;

+ 1
- 1
js/xeroc.js Ver arquivo

function loading() function loading()
{ {
return "<tr class='loading' ><td colspan=4 class='loading'><img src='"+bts().load_job_img +"'><br><h1>Sync to Xero</h1></td></tr>";
return "<tr class='loading' ><td colspan=4 class='loading'><img src='"+bts().load_job_img +"'><br><h1>Sync to XeroOauth1</h1></td></tr>";
} }
function display_hour_lines(response) function display_hour_lines(response)

+ 10
- 3
ts.php Ver arquivo

private $addr_table; private $addr_table;
private $ndis_table; private $ndis_table;
private $apiv1; private $apiv1;
private $XeroOauth2;
private $ndis_price; private $ndis_price;
public function __construct() { public function __construct() {
$this->setup_db_name(); $this->setup_db_name();
$this->class_loader(); $this->class_loader();
$this->apiv1 = new Apiv1($this, $this->job_table); $this->apiv1 = new Apiv1($this, $this->job_table);
$this->XeroOauth2 = new XeroOauth2($this);
//$this->check_csv_download(); //$this->check_csv_download();
add_option( "acare_ts_db_version", "1.0" ); add_option( "acare_ts_db_version", "1.0" );
//add_action('init', array($this, 'class_loader')); //add_action('init', array($this, 'class_loader'));
add_action('init', array($this, 'check_csv_download')); add_action('init', array($this, 'check_csv_download'));


add_action('wp', array($this, 'check_auth')); add_action('wp', array($this, 'check_auth'));
add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99);
$loader->addNamespace('\XeroPHP', dirname(__FILE__) . '/xero-php-master/src/XeroPHP'); $loader->addNamespace('\XeroPHP', dirname(__FILE__) . '/xero-php-master/src/XeroPHP');
$loader->addNamespace('\Biukop', dirname(__FILE__) . '/' ); $loader->addNamespace('\Biukop', dirname(__FILE__) . '/' );
$this->xero = new Xero();
$this->xero->init_wp();
//$this->xero = new XeroOauth2($this);
//$this->xero->init_wp();
//$abc = new AddrMap("01515b52-6936-46b2-a000-9ad4cd7a5b50", "0768db6d-e5f4-4b45-89a2-29f7e8d2953c"); //$abc = new AddrMap("01515b52-6936-46b2-a000-9ad4cd7a5b50", "0768db6d-e5f4-4b45-89a2-29f7e8d2953c");
//$abc = new AddrMap("122eb1d0-d8c4-4fc3-8bf8-b7825bee1a01", "0768db6d-e5f4-4b45-89a2-29f7e8d2953c"); //$abc = new AddrMap("122eb1d0-d8c4-4fc3-8bf8-b7825bee1a01", "0768db6d-e5f4-4b45-89a2-29f7e8d2953c");
//echo $sql; //echo $sql;
exit(); exit();
} }

public function init_xero_with_wp() {
$this->xero->init_wp();
}
private function get_ndis_price() private function get_ndis_price()
{//help to ensure ndis_price is only build once per call {//help to ensure ndis_price is only build once per call

Carregando…
Cancelar
Salvar