Skip to content

loumray/infusionsoft-php

 
 

Repository files navigation

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"
    }
}

This package is compatible with PHP 5.3.3 and higher. It uses Guzzle 3.8.* as the default HTTP client which requires 5.3.3 or higher. In order to use cURL you must have the PHP cURL extension enabled.

Usage

The client ID and secret are the key and secret for your OAuth2 application found at the Infusionsoft Developers website.

require_once 'vendor/autoload.php';

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

// 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']);
}

if ($infusionsoft->getToken()) {
	// Save the serialized token to the current session for subsequent requests
	$_SESSION['token'] = serialize($infusionsoft->getToken());

	$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->setHttpLogAdapter(new MonologLogAdapter($logger));

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

License

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

About

Beta PHP client library for the Infusionsoft API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published