GoCardless 7.7.0
dotnet add package GoCardless --version 7.7.0
NuGet\Install-Package GoCardless -Version 7.7.0
<PackageReference Include="GoCardless" Version="7.7.0" />
<PackageVersion Include="GoCardless" Version="7.7.0" />
<PackageReference Include="GoCardless" />
paket add GoCardless --version 7.7.0
#r "nuget: GoCardless, 7.7.0"
#addin nuget:?package=GoCardless&version=7.7.0
#tool nuget:?package=GoCardless&version=7.7.0
.NET Client for the GoCardless API
For full details of the GoCardless API, see the API docs.
Installation
To install GoCardless
, run the following command in the Package Manager Console
Install-Package GoCardless -Version 7.7.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.
Support and feedback
- Developer documentation
- Developer support
- api@gocardless.com
Product | Versions 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.6 is compatible. netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net46 is compatible. net461 was computed. 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 | tizen30 was computed. 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. |
-
.NETFramework 4.6
- Newtonsoft.Json (>= 13.0.3)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 1.6
- NETStandard.Library (>= 1.6.1)
- Newtonsoft.Json (>= 13.0.3)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.3)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 2.1
- Newtonsoft.Json (>= 13.0.3)
- System.Net.Http (>= 4.3.4)
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- System.Net.Http (>= 4.3.4)
NuGet packages (4)
Showing the top 4 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. |
|
ActingOffice.Addons.GoCardless
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
7.7.0 | 572 | 4/4/2025 |
7.4.0 | 6,305 | 2/17/2025 |
7.3.0 | 2,372 | 1/28/2025 |
7.2.0 | 9,346 | 12/3/2024 |
7.1.0 | 4,921 | 11/6/2024 |
7.0.0 | 15,664 | 9/23/2024 |
6.7.0 | 14,936 | 8/20/2024 |
6.6.0 | 6,879 | 8/5/2024 |
6.5.0 | 22,160 | 6/28/2024 |
6.4.0 | 118 | 6/27/2024 |
6.3.0 | 9,970 | 5/28/2024 |
6.2.0 | 2,078 | 5/23/2024 |
6.1.0 | 137 | 5/22/2024 |
6.0.2 | 7,096 | 5/3/2024 |
6.0.1 | 15,078 | 4/25/2024 |
6.0.0 | 140 | 4/25/2024 |
5.21.2 | 424 | 4/25/2024 |
5.21.1 | 11,140 | 3/20/2024 |
5.21.0 | 96,717 | 1/18/2024 |
5.20.0 | 5,218 | 1/10/2024 |
5.19.0 | 4,395 | 12/11/2023 |
5.18.0 | 25,794 | 10/26/2023 |
5.17.1 | 20,447 | 8/7/2023 |
5.17.0 | 18,067 | 5/15/2023 |
5.16.0 | 328 | 5/11/2023 |
5.15.0 | 27,471 | 4/11/2023 |
5.14.0 | 7,997 | 3/20/2023 |
5.13.0 | 23,736 | 3/16/2023 |
5.12.1 | 7,563 | 2/13/2023 |
5.12.0 | 18,831 | 2/7/2023 |
5.11.0 | 42,586 | 12/22/2022 |
5.10.0 | 1,284 | 12/19/2022 |
5.9.0 | 1,640 | 12/13/2022 |
5.8.0 | 330 | 12/12/2022 |
5.7.0 | 79,313 | 7/22/2022 |
5.6.0 | 3,465 | 7/13/2022 |
5.5.0 | 2,058 | 7/8/2022 |
5.4.0 | 5,451 | 6/29/2022 |
5.3.0 | 63,250 | 4/22/2022 |
5.2.0 | 185,633 | 11/30/2021 |
5.1.0 | 3,143 | 11/22/2021 |
5.0.2 | 379 | 11/22/2021 |
5.0.1 | 7,613 | 10/21/2021 |
5.0.0 | 45,714 | 8/18/2021 |
4.10.0 | 2,415 | 8/12/2021 |
4.9.0 | 79,162 | 5/20/2021 |
4.8.0 | 8,472 | 4/13/2021 |
4.7.0 | 10,200 | 3/2/2021 |
4.6.0 | 11,298 | 1/11/2021 |
4.5.0 | 15,400 | 11/4/2020 |
4.4.0 | 23,992 | 8/18/2020 |
4.3.0 | 35,553 | 7/14/2020 |
4.2.0 | 9,425 | 6/18/2020 |
4.1.0 | 1,632 | 6/1/2020 |
4.0.0 | 1,414 | 5/18/2020 |
3.7.0 | 6,953 | 4/28/2020 |
3.6.0 | 6,262 | 4/20/2020 |
3.5.2 | 1,461 | 4/8/2020 |
3.5.1 | 686 | 4/7/2020 |
3.5.0 | 5,133 | 3/12/2020 |
3.4.1 | 51,291 | 2/26/2020 |
3.3.1 | 2,880 | 2/24/2020 |
3.3.0 | 2,169 | 2/10/2020 |
3.2.0 | 847 | 2/6/2020 |
3.1.1 | 9,365 | 1/29/2020 |
3.1.0 | 633 | 1/28/2020 |
3.0.1 | 16,229 | 12/17/2019 |
3.0.0 | 69,217 | 11/29/2019 |
2.18.0 | 11,142 | 10/25/2019 |
2.17.0 | 2,368 | 10/16/2019 |
2.16.0 | 13,670 | 9/6/2019 |
2.15.0 | 8,226 | 7/26/2019 |
2.13.0 | 69,169 | 1/17/2019 |
2.12.1 | 17,199 | 12/10/2018 |
2.12.0 | 10,411 | 10/10/2018 |
2.11.1 | 9,394 | 8/24/2018 |
2.11.0 | 3,084 | 7/13/2018 |
2.10.1 | 8,776 | 7/5/2018 |
2.10.0 | 10,897 | 6/8/2018 |
2.9.0 | 5,981 | 5/22/2018 |
2.8.0 | 2,671 | 5/17/2018 |
2.7.0 | 2,268 | 4/26/2018 |
2.6.0 | 1,877 | 4/11/2018 |
2.5.0 | 1,862 | 3/16/2018 |
2.4.0 | 10,681 | 12/5/2017 |
2.3.0 | 2,259 | 11/14/2017 |
2.2.0 | 5,884 | 10/25/2017 |
2.1.1 | 5,533 | 9/18/2017 |
2.1.0 | 1,380 | 9/18/2017 |
2.0.6 | 13,241 | 9/1/2017 |
2.0.5 | 1,471 | 8/23/2017 |
2.0.4 | 5,530 | 8/18/2017 |
2.0.3 | 3,700 | 7/21/2017 |
2.0.2 | 2,544 | 7/6/2017 |