コード例 #1
0
<?php

session_start();
require_once '../vendor/autoload.php';
$infusionsoft = new \Infusionsoft\Infusionsoft(array('clientId' => 'CLIENT_ID', 'clientSecret' => 'CLIENT_SECRET', 'redirectUri' => 'REDIRECT_URL'));
// 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']);
}
function addWithDupCheck($infusionsoft)
{
    $contact = array('FirstName' => 'John', 'LastName' => 'Doe', 'Email' => '*****@*****.**');
    return $infusionsoft->contacts->addWithDupCheck($contact, 'Email');
}
if ($infusionsoft->getToken()) {
    try {
        $cid = addWithDupCheck($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();
        $cid = addWithDupCheck($infusionsoft);
コード例 #2
0
    // not only requested an access token, but also set the token in the current
    // Infusionsoft object, so there's no need for you to do it.
    if ($infusionsoft->getToken()) {
        // Save the serialized token to the current session for subsequent requests
        // NOTE: this can be saved in your database - make sure to serialize the
        // entire token for easy future access
        Session::put('token', serialize($infusionsoft->getToken()));
        // Now redirect the user to a page that performs some Infusionsoft actions
        return redirect()->to('/contacts');
    }
    // something didn't work, so let's go back to the beginning
    return redirect()->to('/');
});
$app->get('/contacts', function () use($app) {
    // Setup a new Infusionsoft SDK object
    $infusionsoft = new \Infusionsoft\Infusionsoft(array('clientId' => getenv('INFUSIONSOFT_CLIENT_ID'), 'clientSecret' => getenv('INFUSIONSOFT_CLIENT_SECRET'), 'redirectUri' => getenv('INFUSIONSOFT_REDIRECT_URL')));
    // Set the token if we have it in storage (in this case, a session)
    $infusionsoft->setToken(unserialize(Session::get('token')));
    try {
        // Retrieve a list of contacts by querying the data service
        $contacts = $infusionsoft->data->query('Contact', 10, 0, ['FirstName' => 'John'], ['FirstName', 'LastName', 'Email', 'ID'], 'FirstName', true);
    } catch (\Infusionsoft\TokenExpiredException $e) {
        // Refresh our access token since we've thrown a token expired exception
        $infusionsoft->refreshAccessToken();
        // We also have to save the new token, since it's now been refreshed.
        // We serialize the token to ensure the entire PHP object is saved
        // and not accidentally converted to a string
        Session::put('token', serialize($infusionsoft->getToken()));
        // Retrieve the list of contacts again now that we have a new token
        $contacts = $infusionsoft->data->query('Contact', 10, 0, ['FirstName' => 'John'], ['FirstName', 'LastName', 'Email', 'ID'], 'FirstName', true);
    }
コード例 #3
0
<?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;
コード例 #4
0
<?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 {