dmorenof / gocardless-sdk
Unofficial PHP SDK for the GoCardless API (customers, mandates, payments, subscriptions, billing requests, payouts, refunds and more).
Requires
- php: ^8.4
- dmorenof/sdk-runtime: ^1.13.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-25 03:07:41 UTC
README
GoCardless direct debit, instant bank payments and billing requests as typed PHP.
Customers, mandates, payments, subscriptions, billing requests, payouts and refunds across GoCardless's whole public API, generated from the OpenAPI document GoCardless publishes.
Unofficial. Not affiliated with, endorsed by or supported by GoCardless. See NOTICE.md.
Why this SDK
- 138 operations from the official contract, with typed models for every resource.
- Query objects such as
metadataare sent asmetadata[key]=value;limitaccepts an integer or a string, as the API does. - Errors arrive as typed exceptions you can catch by kind.
- Generated from the contract, never edited by hand.
src/is produced fromcontract/gocardless.jsonby sdk-generator on top of the shared sdk-runtime: when the contract changes you regenerate, you do not patch. - Typed end to end. 138 operations and 510 typed request, answer and model classes. A request is a model whose fields are checked where you assign them (PHP 8.4 property hooks); an answer is a model; a list is a typed collection. PHPStan at the maximum level reports no error on the whole SDK.
- One way to fail. An HTTP answer the contract does not declare as success is an
ApiExceptionthat keeps the raw response and, when the API documents it, the decoded error as a model. Network failures keep their own type. - Production controls included. PSR-18 HTTP client (Guzzle by default), timeouts (30 s / 10 s by default), retries with
Retry-After, redirect policy, middleware and per-environment servers, all in oneConfigurationobject.
Install
PHP 8.4 or later.
composer require dmorenof/gocardless-sdk
Quick start
<?php use GoCardlessSDK\Configuration; use GoCardlessSDK\GoCardlessAPISDK; use GoCardlessSDK\GetParams\Payouts as PayoutsParams; use GoCardlessSDK\Payouts; use Dmorenof\SdkRuntime\Security\SecurityCredentials; $configuration = new Configuration(); $configuration->securityCredentials = new SecurityCredentials(['bearerAuth' => getenv('GOCARDLESS_ACCESS_TOKEN') ?: '']); GoCardlessAPISDK::configure($configuration); // `GoCardless-Version` is a required header of every call. $payouts = Payouts::get(new PayoutsParams((object) ['GoCardlessVersion' => '2015-07-06', 'limit' => 25])); echo json_encode($payouts), "\n";
The same example is in examples/quickstart.php. Every operation is listed in docs/OPERATIONS.md.
What it covers
138 operations. The biggest areas:
| Area | Operations |
|---|---|
billing_requests |
14 |
outbound_payments |
8 |
subscriptions |
7 |
blocks |
6 |
instalment_schedules |
6 |
mandates |
6 |
payments |
6 |
customer_bank_accounts |
5 |
customers |
5 |
payer_authorisations |
5 |
billing_request_templates |
4 |
creditor_bank_accounts |
4 |
…and 32 more areas; the full list is in docs/OPERATIONS.md.
Handling errors
use Dmorenof\SdkRuntime\ApiException; try { // ... any call from the quick start } catch (ApiException $e) { echo $e->response->status, "\n"; // the HTTP status echo $e->response->body, "\n"; // the raw body, always kept var_dump($e->error); // the decoded error model, when the API documents one }
Configuration
Configuration is the only place to set anything: baseUrl, securityCredentials, headers, timeout, connectTimeout, retryPolicy, redirectPolicy, middleware, httpClient (any PSR-18 client), serverVariables. Use Client::connect($configuration) instead of the static facades when you need several independent connections.
Good to know
- GoCardless also publishes official libraries; this SDK is generated from its contract and is not affiliated with GoCardless.
- For the sandbox, set
$configuration->baseUrl = 'https://api-sandbox.gocardless.com';. - Version
0.1.0is a first release: the API of the SDK follows the contract, and a regenerated contract can rename classes. Pin a version. - The SDK has been checked against its contract (generation, static analysis, serialization of requests); it has not been run against the live service unless the section above says so. Use test credentials first.
Documentation
- Operations catalog
- Vendor documentation
- sdk-runtime (what every SDK shares) and sdk-generator
- CHANGELOG.md, CONTRIBUTING.md, SECURITY.md
License
MIT, see LICENSE.md. The license covers this SDK's code, not the API, its trademarks or its terms: see NOTICE.md.