-
Notifications
You must be signed in to change notification settings - Fork 128
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 #89 from infusionsoft/resthooks
Add RESTHook functions
- Loading branch information
Showing
5 changed files
with
1,133 additions
and
947 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
session_start(); | ||
//session_destroy(); | ||
|
||
require_once '../vendor/autoload.php'; | ||
|
||
$infusionsoft = new \Infusionsoft\Infusionsoft(array( | ||
'clientId' => '', | ||
'clientSecret' => '', | ||
'redirectUri' => '', | ||
)); | ||
|
||
// By default, the SDK uses the Guzzle HTTP library for requests. To use CURL, | ||
// you can change the HTTP client by using following line: | ||
// $infusionsoft->setHttpClient(new \Infusionsoft\Http\CurlClient()); | ||
|
||
// If the serialized token is available in the session storage, we tell the SDK | ||
// to use that token for subsequent requests. | ||
if (isset($_SESSION['token'])) { | ||
$infusionsoft->setToken(unserialize($_SESSION['token'])); | ||
} | ||
|
||
// If we are returning from Infusionsoft we need to exchange the code for an | ||
// access token. | ||
if (isset($_GET['code']) and !$infusionsoft->getToken()) { | ||
$infusionsoft->requestAccessToken($_GET['code']); | ||
$_SESSION['token'] = serialize($infusionsoft->getToken()); | ||
} | ||
|
||
function resthookManager($infusionsoft) { | ||
$resthooks = $infusionsoft->resthooks(); | ||
|
||
// first, create a new task | ||
$resthook = $resthooks->create([ | ||
'eventKey' => 'contact.add', | ||
'hookUrl' => 'http://infusionsoft.app/verifyRestHook.php' | ||
]); | ||
var_dump($resthook); | ||
$resthook = $resthooks->find($resthook->id)->verify(); | ||
|
||
return $resthook; | ||
} | ||
|
||
if ($infusionsoft->getToken()) { | ||
try { | ||
$resthook = resthookManager($infusionsoft); | ||
} | ||
catch (\Infusionsoft\TokenExpiredException $e) { | ||
// If the request fails due to an expired access token, we can refresh | ||
// the token and then do the request again. | ||
$infusionsoft->refreshAccessToken(); | ||
|
||
// Save the serialized token to the current session for subsequent requests | ||
$_SESSION['token'] = serialize($infusionsoft->getToken()); | ||
|
||
$resthook = resthookManager($infusionsoft); | ||
} | ||
|
||
var_dump($resthook); | ||
} | ||
else { | ||
echo '<a href="' . $infusionsoft->getAuthorizationUrl() . '">Click here to authorize</a>'; | ||
} |
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,21 @@ | ||
<?php | ||
|
||
session_start(); | ||
|
||
require_once '../vendor/autoload.php'; | ||
|
||
$infusionsoft = new \Infusionsoft\Infusionsoft(array( | ||
'clientId' => '', | ||
'clientSecret' => '', | ||
'redirectUri' => '', | ||
)); | ||
|
||
// In order to verify the endpoint, we need to return the X-Hook-Secret header. | ||
// By default, the autoverify() function will set the proper header, but if you | ||
// pass false as the first argument to autoverify(false) the function will simply | ||
// return the header value for you to set as you please (handy if you are using | ||
// a PHP class or framework that manages requests for you | ||
|
||
$infusionsoft->resthooks()->autoverify(); | ||
|
||
return; |
Oops, something went wrong.