/infusionsoft-php

Beta PHP client library for the Infusionsoft API.

Primary LanguagePHPOtherNOASSERTION

Infusionsoft PHP SDK (beta)

Build Status Total Downloads Latest Stable Version

This package is currently in beta for testing.

Install

Via Composer

{
    "require": {
        "infusionsoft/php-sdk": "~1.0"
    }
}

Usage

require_once 'vendor/autoload.php';

$infusionsoft = new \Infusionsoft\Infusionsoft(array(
	'clientId'     => 'XXXXXXXXXXXXXXXXXXXXXXXX',
	'clientSecret' => 'XXXXXXXXXX',
	'redirectUri'  => 'http://example.com/',
));

// If the access token is available in the session storage, we tell the SDK to
// use that token for subsequent requests.
if (isset($_SESSION['access_token']))
{
	$infusionsoft->setAccessToken($_SESSION['access_token']);
}

// If we are returning from Infusionsoft we need to exchange the code for an
// access token.
if (isset($_GET['code']) and ! $infusionsoft->getAccessToken())
{
	$infusionsoft->requestAccessToken($_GET['code']);
}

if ($infusionsoft->getAccessToken())
{
	// Save the access token to the session so we don't keep exchanging the code
	$_SESSION['access_token'] = $infusionsoft->getAccessToken();

	$infusionsoft->contacts->add(array('FirstName' => 'John', 'LastName' => 'Doe'));
}
else
{
	echo '<a href="' . $infusionsoft->getAuthorizationUrl() . '">Click here to authorize</a>';
}

Debugging

To enable debugging of requests and responses, you need to set the debug flag to try by using:

$infusionsoft->setDebug(true);

Once enabled, logs will by default be written to an array that can be accessed by:

$infusionsoft->getLogs();

You can utilize the powerful logging plugin built into Guzzle by using one of the available adapters. For example, to use the Monolog writer to write to a file:

use Guzzle\Log\MonologLogAdapter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$logger = new Logger('client');
$logger->pushHandler(new StreamHandler('infusionsoft.log'));

$infusionsoft->setHttpLogAdapater(new MonologLogAdapter($logger));

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.