SDKs overview

GoCardless offers official Software Development Kits (SDKs) to facilitate integration with its API, enabling developers to incorporate direct debit and instant bank payment functionalities into their applications. These SDKs are designed to abstract the complexities of HTTP requests, authentication, and error handling, providing a more streamlined development experience in several popular programming languages. By using an SDK, developers can interact with the GoCardless platform using familiar language constructs, reducing the time and effort required to implement payment processing logic in their applications. The SDKs cover core functionalities such as managing customers, mandates, payments, and payouts, aligning with the GoCardless API reference documentation.

The SDKs act as a client library, allowing developers to programmatically access GoCardless services. This approach standardizes API interactions, ensuring that requests are correctly formatted and responses are parsed efficiently. For example, when creating a new customer, an SDK function might take customer details as arguments and handle the underlying API call, including setting request headers and serializing data, as described in the GoCardless developer portal.

Official SDKs by language

GoCardless maintains official SDKs for several programming languages, developed and supported by their engineering team. These SDKs are the recommended method for integrating with the GoCardless API due to their direct alignment with the API specifications and ongoing maintenance. The following table outlines the official SDKs, their respective package managers, and typical installation commands.

Language Package Manager Install Command Example Maturity
Ruby RubyGems gem install gocardless_pro Stable
Python pip pip install gocardless-pro Stable
PHP Composer composer require gocardless/gocardless-pro Stable
Java Maven / Gradle Maven: Add to pom.xml; Gradle: Add to build.gradle Stable
Node.js npm npm install gocardless-pro Stable

Each SDK is designed to be idiomatic to its respective language, providing a natural development experience. For instance, the Python SDK uses classes and methods that align with Pythonic conventions, while the Ruby SDK leverages Ruby's object-oriented features. Developers can find detailed API mapping and usage examples within the SDKs' official documentation on the GoCardless developer site.

Installation

Installing GoCardless SDKs typically involves using the standard package manager for the chosen programming language. This ensures that dependencies are resolved correctly and the SDK is made available within the project environment. Below are generalized installation instructions for each officially supported language.

Ruby

The Ruby SDK is available via RubyGems. To install it, execute the following command in your terminal:

gem install gocardless_pro

After installation, you can require the gem in your Ruby application:

require 'gocardless_pro'

Python

The Python SDK can be installed using pip, Python's package installer:

pip install gocardless-pro

To use it in your Python code:

import gocardless_pro

PHP

For PHP projects, Composer is used to manage dependencies. Add the SDK to your project's composer.json file or run the command:

composer require gocardless/gocardless-pro

Ensure your application includes Composer's autoloader:

require 'vendor/autoload.php';

Java

For Java, the SDK is distributed through Maven Central. If you are using Maven, add the dependency to your pom.xml:

<dependency>
    <groupId>com.gocardless</groupId>
    <artifactId>gocardless-pro</artifactId>
    <version>[latest_version]</version>
</dependency>

If you are using Gradle, add it to your build.gradle:

implementation 'com.gocardless:gocardless-pro:[latest_version]'

Replace [latest_version] with the current version from the GoCardless Java client library documentation.

Node.js

The Node.js SDK is available via npm. Install it using:

npm install gocardless-pro

Then, import it into your JavaScript or TypeScript code:

const GoCardlessPro = require('gocardless-pro');
// or for ES Modules
import GoCardlessPro from 'gocardless-pro';

Quickstart example

This example demonstrates how to initialize the GoCardless client and create a new customer using the Python SDK. This process is fundamental for initiating direct debit mandates and payments.

Python Quickstart

First, ensure you have your access token. You can find this in your GoCardless dashboard under 'Developers' -> 'API access' or 'API keys'. It is recommended to use environment variables for sensitive credentials in production environments, as suggested by general security practices for API authorization.

import gocardless_pro
import os

# Initialize the client with your access token and environment
# Use 'sandbox' for testing, 'live' for production
client = gocardless_pro.Client(
    access_token=os.environ.get('GC_ACCESS_TOKEN'),
    environment='sandbox'
)

try:
    # Create a new customer
    customer = client.customers.create({
        "email": "[email protected]",
        "given_name": "John",
        "family_name": "Doe",
        "address_line1": "42 Main Street",
        "city": "London",
        "postal_code": "SW1A 0AA",
        "country_code": "GB"
    })

    print(f"Customer created successfully: {customer.id}")
    print(f"Customer details: {customer.given_name} {customer.family_name}, {customer.email}")

except gocardless_pro.errors.GoCardlessProError as e:
    print(f"Error creating customer: {e.message}")
    print(f"Errors: {e.errors}")

This snippet demonstrates:

  • Client Initialization: Setting up the gocardless_pro.Client with an access token and specifying the environment (sandbox for testing or live for production).
  • Customer Creation: Calling the client.customers.create method with a dictionary of customer details. The SDK handles the API request and parses the response.
  • Error Handling: Using a try-except block to catch potential GoCardlessProError exceptions, which can occur due to invalid input or API issues.

Developers can expand on this by creating mandates, payments, and managing webhooks as detailed in the GoCardless API documentation.

Community libraries

While GoCardless provides a robust set of official SDKs, the developer community sometimes creates and maintains additional libraries or integrations. These community-driven projects can offer specialized functionalities, integrations with specific frameworks, or support for languages not officially covered. Although GoCardless does not officially endorse or support these libraries, they can be valuable resources for developers with specific needs.

Some common types of community contributions include:

  • Framework-specific integrations: Libraries that integrate GoCardless into popular web frameworks like Django, Ruby on Rails, or Laravel, often providing helpers for common tasks such as form handling or database synchronization.
  • Additional language support: While GoCardless covers major languages, community libraries might emerge for languages like Go, C#, or others not in the official SDK list.
  • Specialized tools: Command-line interfaces (CLIs) or utility libraries that simplify specific aspects of GoCardless API interaction.

Developers considering community libraries should evaluate their maintainer activity, documentation quality, and compatibility with the latest GoCardless API versions. Resources like GitHub and Stack Overflow are common places to discover and discuss such projects. For example, developers might search for GoCardless integrations within the open-source community for specific platforms.

When using community-contributed libraries, it is prudent to conduct due diligence, including:

  • Checking the project's GitHub repository for recent commits and open issues.
  • Reviewing the license to ensure it aligns with your project's requirements.
  • Testing the library thoroughly, especially in a sandbox environment, before deploying to production.
  • Verifying that the library handles secure API key management and adheres to best practices for payment processing.

For official support and the most reliable integration, GoCardless always recommends using its official client libraries, which are regularly updated and tested against their API.