GoCardless 11.1.0

dotnet add package GoCardless --version 11.1.0
                    
NuGet\Install-Package GoCardless -Version 11.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GoCardless" Version="11.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GoCardless" Version="11.1.0" />
                    
Directory.Packages.props
<PackageReference Include="GoCardless" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GoCardless --version 11.1.0
                    
#r "nuget: GoCardless, 11.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GoCardless@11.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GoCardless&version=11.1.0
                    
Install as a Cake Addin
#tool nuget:?package=GoCardless&version=11.1.0
                    
Install as a Cake Tool

.NET Client for the GoCardless API

For full details of the GoCardless API, see the API docs.

NuGet <GoCardless>

Installation

To install GoCardless, run the following command in the Package Manager Console

Install-Package GoCardless -Version 11.1.0

Usage

Note: This README will use "customers" in examples throughout, but every endpoint in the API is available in this library.

Initialising the client

The client is initialised with an access token and an environment.

var accessToken = "your_access_token";
var gocardless = GoCardlessClient.Create(accessToken, Environment.SANDBOX);

GET requests

Individual resources

You can retrieve individual resources by ID using that resource's GetAsync method:

var customerResponse = await gocardless.Customers.GetAsync("CU0123");
var customer = customerResponse.Customer;
Lists of resources

There are two ways to list resources. You can either make single requests for lists with ListAsync:

var customerRequest = new GoCardless.Services.CustomerListRequest()
{
    Limit = 100
};

var customerListResponse = await gocardless.Customers.ListAsync(customerRequest);

foreach (var customer in customerListResponse.Customers)
{
    Console.WriteLine(customer.GivenName);
}

Console.WriteLine("Next page cursor: " +  customerListResponse.Meta.Cursors.After);

or use the lazy pagination offered by All:

var customerRequest = new GoCardless.Services.CustomerListRequest()
{
    Limit = 100
};

var customerListResponse = gocardless.Customers.All(customerRequest);
foreach (var customer in customerListResponse)
{
    Console.WriteLine(customer.GivenName);
}

The lazy pagination approach is generally simpler - it automatically makes as many API requests as needed to return the whole list as an enumerable, and you don't need to take care of pagination manually.

POST/PUT requests

These work in a similar way to GET requests, and you can initialize a request object with all of the available parameters for each endpoint.

Creating a customer

var customerRequest = new GoCardless.Services.CustomerCreateRequest()
{
    Email = "user@example.com",
    GivenName = "Frank",
    FamilyName = "Osborne",
    AddressLine1 = "27 Acer Road",
    AddressLine2 = "Apt 2",
    City = "London",
    PostalCode = "E8 3GX",
    CountryCode = "GB",
    Metadata = new Dictionary<string, string>()
    {
      {"salesforce_id", "ABCD1234"}
    }
};

var customerResponse = await gocardless.Customers.CreateAsync(customerRequest);
var customer = customerResponse.Customer;

Updating a customer

var customerRequest = new GoCardless.Services.CustomerUpdateRequest()
{
    Metadata = new Dictionary<string, string>()
    {
        {"custom_reference", "NEWREFERENCE001"}
    }
};
var customerResponse = await gocardless.Customers.UpdateAsync("CU0123", customerRequest);

When creating a resource, the library will automatically include a randomly-generated idempotency key

  • this means that if a request appears to fail but is in fact successful (for example due to a timeout), you will not end up creating multiple duplicates of the resource.

You can provide your own key for any endpoints that support idempotency keys by setting it in the request object:

var customerRequest = new GoCardless.Services.CustomerCreateRequest()
{
    Email = "user@example.com",
    IdempotencyKey = "unique_customer_reference"
};

Setting custom headers

You shouldn't generally need to customise the headers sent by the library, but you may wish to in some cases (for example if you want to send an Accept-Language header when creating a mandate PDF).

To do this, you can provide RequestSettings like this:

var requestSettings = new GoCardless.Internals.RequestSettings
{
    Headers = new Dictionary<string, string>()
    {
        {"Accept-Language", "fr"}
    }
};

var mandatePdfRequest = new GoCardless.Services.MandatePdfsCreateRequest()
{
    Iban = "FR14BARC20000055779911"
};

var mandatePdfResponse = await gocardless.MandatePdfs.CreateAsync(mandatePdfRequest, requestSettings);

Custom headers you specify will override any headers generated by the library itself (for example, an Authorization header with your configured access token or an Idempotency-Key header with a randomly-generated value or one you've configured manually). Custom headers always take precedence.

Accessing raw response data

You can retrieve the System.Net.Http.HttpResponseMessage from any resource or resource list response:

var customerRequest = new GoCardless.Services.CustomerUpdateRequest()
{
    Metadata = new Dictionary<string, string>()
    {
        {"custom_reference", "NEWREFERENCE001"}
    }
};
var customerResponse = await gocardless.Customers.UpdateAsync("CU0123", customerRequest);

HttpResponseMessage responseMessage = customerResponse.ResponseMessage;

Errors

If the API returns an error response, the client will raise a corresponding Exception. The exceptions are all subclasses of GoCardless.Exceptions.ApiException:

  • InternalException
  • InvalidApiUsageException
  • InvalidStateException
  • ValidationFailedException

These errors are fully documented in the API documentation.

The exceptions have the following properties to facilitate access to information in the API response:

  • string Type
  • string DocumentationUrl
  • string RequestId
  • int Code
  • IReadOnlyList<GoCardless.Errors.Error> Errors

GoCardless.Errors.Error provides more specific error messages and reasons from the response.

When the API returns an invalid_state error due to an idempotent_creation_conflict the library will, where possible, automatically retrieve the existing record which was created using the same idempotency key.

If a timeout occurs, and the request being made is idempotent, the library will automatically retry the request up to 2 more times.

Unless you pass your own HttpClient to GoCardlessClient.Create, requests are made with the shared GoCardlessClient.DefaultHttpClient, which times out after 100 seconds (the HttpClient default). To use a different timeout, pass an HttpClient with its Timeout set:

var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
var client = GoCardlessClient.Create(accessToken, Environment.SANDBOX, httpClient);

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 Event objects which are easy to work with:

// When you create a webhook endpoint, you can specify a secret. When GoCardless sends
// you a webhook, it will sign the body using that secret. Since only you and GoCardless
// know the secret, you can check the signature and ensure that the webhook is truly
// from GoCardless.
var webhookEndpointSecret = Environment.GetEnvironmentVariable("GOCARDLESS_WEBHOOK_ENDPOINT_SECRET");

// In your webhook handler
[HttpPost("/webhooks")]
public IActionResult HandleWebhook()
{
    var requestBody = new StreamReader(Request.Body).ReadToEnd();
    var signatureHeader = Request.Headers["Webhook-Signature"];

    try
    {
        var events = WebhookParser.Parse(requestBody, webhookEndpointSecret, signatureHeader);

        foreach (var webhookEvent in events)
        {
            Console.WriteLine(webhookEvent.Id);
        }

        return Ok();
    }
    catch (InvalidSignatureException)
    {
        // The webhook doesn't appear to be genuinely from GoCardless
        return StatusCode(498);
    }
}
Accessing the webhook ID

If you need to access the webhook ID for debugging purposes, you can use ParseWithMeta instead:

var result = WebhookParser.ParseWithMeta(requestBody, webhookEndpointSecret, signatureHeader);
var events = result.Events;
var webhookId = result.WebhookId;  // e.g. "WB123" - useful for debugging

Note: The webhook ID is intended for debugging and logging purposes only. It should not be used for deduplication - instead, use the event IDs to deduplicate, as each event has a unique ID that remains consistent if the same event is sent multiple times.

For more details on working with webhooks, see our "Getting started" guide.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on GoCardless:

Package Downloads
N3O.Umbraco.Payments.GoCardless

TODO

Kartris

Kartris is a free, open source cart system optimized for performance and capable of handling 1,000,000+ SKUs out of the box

N3O.Umbraco.Payments.GoCardless.Core

Support for GoCardless payments.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.1.0 45 11/5/2026
11.0.2 194 11/3/2026
11.0.1 183 11/2/2026
11.0.0 74 11/2/2026
10.16.0 590 10/29/2026
10.15.1 102 10/29/2026
10.15.0 204 10/28/2026
10.14.0 364 10/27/2026
10.13.3 684 10/26/2026
10.13.2 563 10/23/2026
10.13.1 105 10/23/2026
10.13.0 1,445 10/12/2026
10.12.2 688 10/7/2026
10.12.1 235 10/6/2026
10.12.0 215 10/6/2026
10.11.0 134 10/6/2026
10.10.3 132 10/6/2026
10.10.2 199 10/6/2026
10.10.1 144 10/6/2026
10.10.0 123 10/6/2026
Loading failed