2017 © Pedro Peláez
 

library commonledger-sdk

Official CommonLedger API library client for PHP

image

commonledger/commonledger-sdk

Official CommonLedger API library client for PHP

  • Thursday, August 17, 2017
  • by commonledger
  • Repository
  • 4 Watchers
  • 1 Stars
  • 65,856 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 33 % Grown

The README.md

sdk-php

Official CommonLedger API library client for PHP, (*1)

Installation

Make sure you have composer installed., (*2)

Add the following to your composer.json, (*3)

{
    "require": {
        "commonledger/commonledger-sdk": "*"
    }
}

Update your dependencies, (*4)

$ php composer.phar update

This package follows the PSR-0 convention names for its classes, which means you can easily integrate these classes loading in your own autoloader., (*5)

Usage

<?php

// This file is generated by Composer
require_once 'vendor/autoload.php';

// Then we instantiate a client (as shown below)

Build a client

Without any authentication
$client = new \CommonLedger\Sdk\Client();

// If you need to send options
$client = new \CommonLedger\Sdk\Client(null, $options);
OAuth 2.0 Access Token
$client = new \CommonLedger\Sdk\Client('ACCESS-TOKEN', $options);
Setting the access token after init
$client->setAccessToken('commonledger-issued-access-token');

Authentication

Authentication with the Common Ledger API is handled using the OAuth 2.0 standard managed by the auth() module., (*6)

$oauth_params = array(
    'client_id' => 'commonledger-client-id',
    'client_secret' => 'commonledger-client-secret',
    'redirect_uri' => 'http://example.com/redirect-url-used-in-setup',
    'scope' => 'requested-scope'
);

$auth = $client->auth($oauth_params);

Redirect URL

To start authorization you must redirect the user to Common Ledger using a GET request. This can be generated by calling the getRedirectUrl() method., (*7)

$state = 'foobar'; // some application state that will be passed when the user is redirected back (optional)
$ledger = array('id' => 'abc-123', 'name' => 'Widgets Ltd'); // data that can be used to setup a new ledger (optional)
$context = 'commonledger-state'; // similar to $state, but supplied back to Common Ledger (only used by connectors) (optional)
$redirect_url = $auth->getRedirectUrl($state, $ledger, $context);

echo $redirect_url; // https://login.commonledger.com/authorize?state=foobar...

Access tokens

Once the redirect has been completed you will be returned a code that is supplied to the accessToken() method to obtain an access_token and refresh_token;, (*8)

$request_code = 'commonledger-issued-code';
$access_token = $auth->accessToken($request_code);

print_r($access_token);

/*
Array
(
    [access_token] => 0543c7eed8439967bc7576d4fbae9ed1b64b73d1
    [expires_in] => 1200
    [token_type] => Bearer
    [scope] => connector
    [refresh_token] => 6a49cd8a95f032110221d55cd64e5b0b95d8fd9d6
    [expires] => 2014-01-23T03:57:24+00:00
)
*/

For convenience the expires key is set to be the current time plus the expires_in value., (*9)

Refreshing access tokens

A token will typically expire 20 minutes after it is issued, (denoted by the expires_in and expires). You will need to refresh a token before you use it once it has expired., (*10)

$refresh_token = 'commonledger-issued-refresh-token';
$access_token = $auth->refreshToken($refresh_token);

// returns the same response as the accessToken() endpoint

Accessing data

Once you've obtained an access_token data can be requested via the each of the endpoint modules., (*11)

endpoint documentation tbc, (*12)

Contributors

Here is a list of Contributors, (*13)

Bug Reports

Report here., (*14)

Contact

Common Ledger (api@commonledger.com), (*15)

The Versions

17/08 2017

dev-master

9999999-dev https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger

17/08 2017

dev-feature/map-sync

dev-feature/map-sync https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger

24/04 2017

dev-rename

dev-rename https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger

19/04 2017

dev-feature/remove-origin

dev-feature/remove-origin https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger

16/04 2015

dev-mapping-suggest

dev-mapping-suggest https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger

01/10 2014

dev-develop

dev-develop https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger

02/09 2014

dev-hotfix/ledger-chart-tax-fix

dev-hotfix/ledger-chart-tax-fix https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger

02/09 2014

dev-origin/master

dev-origin/master https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger

02/09 2014

dev-release/1.0

dev-release/1.0 https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger

21/08 2014

dev-feature/feature-refactor-ids

dev-feature/feature-refactor-ids https://commonledger.com

Official CommonLedger API library client for PHP

  Sources   Download

MIT

The Requires

 

commonledger