-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from picqer/guzzle6
Update to Guzzle 6
- Loading branch information
Showing
5 changed files
with
371 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ composer.phar | |
vendor/ | ||
.env | ||
index.php | ||
storage.txt | ||
storage.txt | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,9 @@ | |
"email": "[email protected]" | ||
} | ||
], | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/picqer/guzzle-oauth2-plugin" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"commerceguys/guzzle-oauth2-plugin": "~1.0" | ||
"php": ">=5.5.0", | ||
"guzzlehttp/guzzle": "~6.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
function getValue($key) | ||
{ | ||
$storage = json_decode(file_get_contents('storage.json'), true); | ||
if (array_key_exists($key, $storage)) { | ||
return $storage[$key]; | ||
} | ||
return null; | ||
} | ||
|
||
function setValue($key, $value) | ||
{ | ||
$storage = json_decode(file_get_contents('storage.json'), true); | ||
$storage[$key] = $value; | ||
file_put_contents('storage.json', json_encode($storage)); | ||
} | ||
|
||
function authorize() | ||
{ | ||
$connection = new \Picqer\Financials\Exact\Connection(); | ||
$connection->setRedirectUrl('YOUR_REDIRECT_URL'); | ||
$connection->setExactClientId('YOUR_CLIENT_ID'); | ||
$connection->setExactClientSecret('YOUR_CLIENT_SECRET'); | ||
$connection->redirectForAuthorization(); | ||
} | ||
|
||
function connect() | ||
{ | ||
$connection = new \Picqer\Financials\Exact\Connection(); | ||
$connection->setRedirectUrl('YOUR_REDIRECT_URL'); | ||
$connection->setExactClientId('YOUR_CLIENT_ID'); | ||
$connection->setExactClientSecret('YOUR_CLIENT_SECRET'); | ||
|
||
if (getValue('authorizationcode')) // Retrieves authorizationcode from database | ||
{ | ||
$connection->setAuthorizationCode(getValue('authorizationcode')); | ||
} | ||
|
||
if (getValue('accesstoken')) // Retrieves accesstoken from database | ||
{ | ||
$connection->setAccessToken(getValue('accesstoken')); | ||
} | ||
|
||
if (getValue('refreshtoken')) // Retrieves refreshtoken from database | ||
{ | ||
$connection->setRefreshToken(getValue('refreshtoken')); | ||
} | ||
|
||
if (getValue('expires_in')) // Retrieves expires from database | ||
{ | ||
$connection->setTokenExpires(getValue('expires_in')); | ||
} | ||
|
||
// Make the client connect and exchange tokens | ||
try { | ||
$connection->connect(); | ||
} catch (\Exception $e) { | ||
throw new Exception('Could not connect to Exact: ' . $e->getMessage()); | ||
} | ||
|
||
// Save the new tokens for next connections | ||
setValue('accesstoken', $connection->getAccessToken()); | ||
setValue('refreshtoken', $connection->getRefreshToken()); | ||
setValue('expires_in', $connection->getTokenExpires()); | ||
|
||
return $connection; | ||
} | ||
|
||
if (isset($_GET['code']) && is_null(getValue('authorizationcode'))) { | ||
setValue('authorizationcode', $_GET['code']); | ||
} | ||
|
||
$connection = connect(); | ||
|
||
try { | ||
$journals = new \Picqer\Financials\Exact\Journal($connection); | ||
$result = $journals->get(); | ||
foreach ($result as $journal) { | ||
echo 'journal: ' . $journal->Description . '<br>'; | ||
} | ||
|
||
echo 'done'; | ||
} catch (\Exception $e) { | ||
echo get_class($e) . ' : ' . $e->getMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.