Download the PHP package gocardless/gocardless-pro-php without Composer
On this page you can find all versions of the php package gocardless/gocardless-pro-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gocardless/gocardless-pro-php
More information about gocardless/gocardless-pro-php
Files in gocardless/gocardless-pro-php
Package gocardless-pro-php
Short Description GoCardless Pro PHP Client Library
License MIT
Homepage https://gocardless.com/
Informations about the package gocardless-pro-php
GoCardless Pro PHP client library
A PHP client for interacting with the GoCardless Pro API.
- "Getting started" guide with copy and paste PHP code samples
- API Reference
- Composer Package
- Changelog
Installation
The recommended way to install gocardless-pro
is using
Composer.
Next, run the Composer command to install the latest stable version of gocardless-pro
.
After installing, you need to require Composer's autoloader:
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!
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.
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:
A call to list()
returns an instance of ListResponse
. You can use its records
attribute to iterate through the results.
In the case where a URL parameter is needed, the method signature will contain the required arguments:
As with list, the last argument can be an options array, with any URL parameters given:
Both individual resource and ListResponse instances have an api_response
attribute,
which lets you access the following properties of the request:
status
headers
body
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.
As with GET requests, if any parameters are required, these come first:
The GoCardless API includes idempotency keys. The library will automatically inject these into your request when you create a resource, preventing it from getting duplicated if something goes wrong with the API (e.g. networking issues or a timeout).
You can also specify your own idempotency key - you could, for example, use IDs of records in your database, protecting yourself not only from network or API issues, but also mistakes on your side which could lead to double-creation:
If the library hits an idempotency key conflict (that is, you try to create a resource with an idempotency key you've already used), it will automatically load and return the already-existing resource.
Handling Failures
When the API returns an error, the library will return a corresponding subclass of
ApiException
, one of:
InvalidApiUsageException
InvalidStateException
ValidationFailedException
These types of error are covered in the API documentation.
If the error is an HTTP transport layer error (e.g. timeouts or issues within
GoCardless's infrastructure), requests will automatically be retried by the library up to
3 times, with a 500ms delay between attempts, before a ApiConnectionException
is
raised.
If the library can't parse the response from GoCardless, it will throw a
MalformedResponseException
.
Properties of the exception can be accessed with the following methods:
$e->getType();
$e->getCode();
$e->getErrors();
$e->getDocumentationUrl();
$e->getMessage();
$e->getRequestId();
$e->getApiResponse();
Handling webhooks
GoCardless supports webhooks, allowing you to receive real-time notifications when things happen in your account, so you can take automatic actions in response, for example:
- When a customer cancels their mandate with the bank, suspend their club membership
- When a payment fails due to lack of funds, mark their invoice as unpaid
- When a customer's subscription generates a new payment, log it in their "past payments" list
The client allows you to validate that a webhook you receive is genuinely from GoCardless, and to parse it into GoCardlessPro\Resources\Event
objects which are easy to work with:
For more details on working with webhooks, see our "Getting started" guide.
Supporting PHP >= 8.1
This client library only supports PHP >= 8.1 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 overridden!
All versions of gocardless-pro-php with dependencies
ext-curl Version *
ext-json Version *
ext-mbstring Version *
guzzlehttp/guzzle Version ^7.4