gocardless/gocardless-pro-php

Name: gocardless-pro-php

Owner: GoCardless

Description: GoCardless Pro PHP Client

Created: 2015-03-30 17:35:58.0

Updated: 2017-12-31 12:28:43.0

Pushed: 2018-01-18 12:36:41.0

Homepage: null

Size: 1017

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

GoCardless Pro PHP client library

A PHP client for interacting with the GoCardless Pro API.

PHP version CircleCI

Installation

The recommended way to install gocardless-pro is using Composer.

stall Composer
 -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version of gocardless-pro.

composer.phar require gocardless/gocardless-pro

After installing, you need to require Composer's autoloader:

ire 'vendor/autoload.php';
Manual installation

We strongly recommend using Composer - it'll make it easier to manage your dependencies and stay up to date. But if you don't want to, you can also install the library manually:

Initialising A Client

Create a GoCardlessPro\Client instance, providing your access token and the environment you want to use. We strongly advise storing your access token as an environment variable, rather than directly in your code. you can easily load the environment variables from a .env file by using something like phpdotenv, though keep it out of version control!

ess_token = getenv('GC_ACCESS_TOKEN');
ent = new \GoCardlessPro\Client(array(
ccess_token' => $access_token,
nvironment'  => \GoCardlessPro\Environment::SANDBOX

You can create an access_token from the “Developers” tab in your GoCardless dashboard.

The environment can either be \GoCardlessPro\Environment::SANDBOX or \GoCardlessPro\Environment::LIVE, depending on whether you want to use the sandbox or live API.

For full documentation, see our API docs.

GET requests

You can make a request to get a list of resources using the list method.

ent->customers()->list();

Note: This README will use customers throughout but each of the resources in the API is available in this library.

If you need to pass any options, the last (or only, in the absence of URL params) argument to list() is an array of URL parameters:

tomers = $client->customers()->list(['params' => ['limit' => 400]]);

A call to list() returns an instance of ListResponse. You can use its records attribute to iterate through the results.

 count($customers->records);
ach ($customers->records as $resource) {
ho $resource->given_name;

In the case where a URL parameter is needed, the method signature will contain the required arguments:

tomer = $client->customers()->get($customer_id);
 $customer->given_name;

As with list, the last argument can be an options array, with any URL parameters given:

ent->customers()->get($customer_id, ['params' => ['some_flag' => true]]);

Both individual resource and ListResponse instances have an api_response attribute, which lets you access the following properties of the request:

_response = $client->customers()->get($customer_id)->api_response;
 $api_response->status_code;
POST/PUT Requests

For POST and PUT requests, you need to provide a body for your request by passing it in as the first argument.

ent->customers()->create([
arams' => ["given_name" => "Pete", "family_name" => "Hamilton"]

As with GET requests, if any parameters are required, these come first:

ent->customers()->update($customer_id, [
arams' => ["family_name" => "Smith"]

If you wish to take advantage of idempotency in your requests, you can do so by passing an idempotency header. For example:

ent->customers()->create([
arams' => ["given_name" => "Pete", "family_name" => "Hamilton"]
eaders" => ["Idempotency-Key" => "ABC123"]

It you were to make this request again, the API would reject the request and the client would raise an InvalidStateException.

Handling Failures

When the API returns an error, the library will return a corresponding subclass of ApiException, one of:

These types of error are covered in the API documentation.

If the error is an HTTP transport layer error (e.g. cannot connect, empty response from server, etc.), the client will throw an ApiConnectionException. If it can't parse the response from GoCardless, it will throw a MalformedResponseException.

{
lient->customer()->create(array(
"params" => array("invalid_name" => "Pete")
;
tch (\GoCardlessPro\Core\Exception\ApiException $e) {
 Api request failed / record couldn't be created.
tch (\GoCardlessPro\Core\Exception\MalformedResponseException $e) {
 Unexpected non-JSON response
tch (\GoCardlessPro\Core\Exception\ApiConnectionException $e) {
 Network error

Properties of the exception can be accessesed with the following methods:

Supporting PHP < 5.5

This client library only supports PHP >= 5.5. Earlier releases of PHP are now considered end of life and may be exposed to security vulnerabilities.

Contributing

This client is auto-generated from Crank, a toolchain that we hope to soon open source. Issues should for now be reported on this repository.

Please do not modify the source code yourself, your changes will be overriden!


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.