TrueLayer.Client
2.0.0-beta4
Prefix Reserved
dotnet add package TrueLayer.Client --version 2.0.0-beta4
NuGet\Install-Package TrueLayer.Client -Version 2.0.0-beta4
<PackageReference Include="TrueLayer.Client" Version="2.0.0-beta4" />
<PackageVersion Include="TrueLayer.Client" Version="2.0.0-beta4" />
<PackageReference Include="TrueLayer.Client" />
paket add TrueLayer.Client --version 2.0.0-beta4
#r "nuget: TrueLayer.Client, 2.0.0-beta4"
#:package TrueLayer.Client@2.0.0-beta4
#addin nuget:?package=TrueLayer.Client&version=2.0.0-beta4&prerelease
#tool nuget:?package=TrueLayer.Client&version=2.0.0-beta4&prerelease
TrueLayer.NET
The official TrueLayer .NET client provides convenient access to TrueLayer APIs from applications built with .NET.
The library currently supports .NET 10.0, .NET 9.0 and .NET 8.0.
Installation
Using the .NET Core command-line interface (CLI) tools:
dotnet add package TrueLayer.Client
Using the NuGet Command Line Interface (CLI)
nuget install TrueLayer.Client
Using the Package Manager Console:
Install-Package TrueLayer.Client
From within Visual Studio:
- Open the Solution Explorer.
- Right-click on a project within your solution.
- Click on Manage NuGet Packages...
- Click on the Browse tab and search for "TrueLayer.Client".
- Click on the
TrueLayer.Clientpackage, select the appropriate version in the right-tab and click Install.
Pre-release Packages
Pre-release packages can be downloaded from GitHub Packages.
dotnet add package TrueLayer.Client --prerelease --source https://nuget.pkg.github.com/TrueLayer/index.json
More information on using GitHub packages with .NET.
Documentation
For a comprehensive list of examples, check out the API documentation.
Usage
Prerequisites
First sign up for a developer account. Follow the instructions to set up a new application and obtain your Client ID and Secret. Once the application has been created you must add your application redirected URIs in order to test your integration end-to-end.
Next, generate a signing key pair used to sign API requests.
To generate a private key, run:
docker run --rm -v ${PWD}:/out -w /out -it alpine/openssl ecparam -genkey -name secp521r1 -noout -out ec512-private-key.pem
To obtain the public key, run:
docker run --rm -v ${PWD}:/out -w /out -it alpine/openssl ec -in ec512-private-key.pem -pubout -out ec512-public-key.pem
Navigate to the Payments settings section of the TrueLayer console and upload your public key. Obtain the Key Id.
Configure Settings
Add your Client ID, Secret and Signing Key ID to appsettings.json or any other supported configuration provider.
{
"TrueLayer": {
"ClientId": "your id",
"ClientSecret": "your secret",
"UseSandbox": true,
"Payments": {
"SigningKey": {
"KeyId": "85eeb2da-702c-4f4b-bf9a-e98af5fd47c3"
}
}
}
}
Initialize TrueLayer.NET
Register the TrueLayer client in Startup.cs or Program.cs (.NET 10.0/.NET 9.0/.NET 8.0):
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddTrueLayer(configuration, options =>
{
if (options.Payments?.SigningKey != null)
{
// For demo purposes only. Private key should be stored securely
options.Payments.SigningKey.PrivateKey = File.ReadAllText("ec512-private-key.pem");
}
},
// For best performance and reliability we advise to cache the auth token
authCachingStrategy: AuthCachingStrategy.InMemory)
}
Multiple TrueLayer Clients
Use keyed version of TrueLayer client (.NET 10.0/.NET 9.0/.NET 8.0):
.AddKeyedTrueLayer("TrueLayerGbp",
configuration,
options =>
{
// For demo purposes only. Private key should be stored securely
var privateKey = File.ReadAllText("ec512-private-key.pem");
if (options.Payments?.SigningKey != null)
{
options.Payments.SigningKey.PrivateKey = privateKey;
}
},
authTokenCachingStrategy: AuthTokenCachingStrategies.InMemory)
.AddKeyedTrueLayer("TrueLayerEur",
configuration,
options =>
{
// For demo purposes only. Private key should be stored securely
var privateKey = File.ReadAllText("ec512-private-key.pem");
if (options.Payments?.SigningKey != null)
{
options.Payments.SigningKey.PrivateKey = privateKey;
}
},
authTokenCachingStrategy: AuthTokenCachingStrategies.InMemory)
Use [FromKeyedServices()] attribute to retrieve keyed client
public GbpController([FromKeyedServices("TrueLayerGbp")]ITrueLayerClient trueLayerClient, ...
public EurController([FromKeyedServices("TrueLayerEur")]ITrueLayerClient trueLayerClient, ...
Or GetRequiredKeyedService
var GbpClient = ServiceProvider.GetRequiredKeyedService<ITrueLayerClient>("TrueLayerGbp");
var EurClient = ServiceProvider.GetRequiredKeyedService<ITrueLayerClient>("TrueLayerEur");
Make a payment
Inject ITrueLayerClient into your classes:
public class MyService
{
private readonly ITrueLayerClient _client;
public MyService(ITrueLayerClient client)
{
_client = client;
}
public async Task<ActionResult> MakePayment()
{
var paymentRequest = new CreatePaymentRequest(
amountInMinor: amount.ToMinorCurrencyUnit(2),
currency: Currencies.GBP,
paymentMethod: new CreatePaymentMethod.BankTransfer(
new CreateProviderSelection.UserSelected
{
Filter = new ProviderFilter
{
ProviderIds = new[] { "mock-payments-gb-redirect" }
}
},
new Beneficiary.ExternalAccount(
"TrueLayer",
"truelayer-dotnet",
new AccountIdentifier.SortCodeAccountNumber("567890", "12345678")
)
),
user: new PaymentUserRequest("Jane Doe", "jane.doe@example.com", "0123456789")
);
var apiResponse = await _client.Payments.CreatePayment(
paymentRequest,
idempotencyKey: Guid.NewGuid().ToString()
);
if (!apiResponse.IsSuccessful)
{
return HandleFailure(
apiResponse.StatusCode,
// Includes details of any errors
apiResponse.Problem
);
}
// Pass the ResourceToken to the TrueLayer Web or Mobile SDK
// or, redirect to the TrueLayer Hosted Payment Page
string hostedPaymentPageUrl = _client.Payments.CreateHostedPaymentPageLink(
apiResponse.Data!.Id,
apiResponse.Data!.ResourceToken,
new Uri("https://redirect.yourdomain.com"));
return Redirect(hostedPaymentPageUrl);
}
}
For more examples see the API documentation. Advanced customization options and documentation for contributors can be found in the Wiki.
Retrieve provider details
Inject ITrueLayerClient into your classes:
public class MyService
{
private readonly ITrueLayerClient _client;
public MyService(ITrueLayerClient client)
{
_client = client;
}
public async Task<ActionResult> GetProvider(string id)
{
var apiResponse = await _client.PaymentsProviders.GetPaymentsProvider(id);
if (!apiResponse.IsSuccessful)
{
return HandleFailure(
apiResponse.StatusCode,
// Includes details of any errors
apiResponse.Problem
);
}
return Ok(apiResponse.Data.Id);
}
}
For more examples see the API documentation. Advanced customization options and documentation for contributors can be found in the Wiki.
Make a payout
Inject ITrueLayerClient into your classes:
public class MyService
{
private readonly ITrueLayerClient _client;
public MyService(ITrueLayerClient client)
{
_client = client;
}
public async Task<ActionResult> MakePayout()
{
var payoutRequest = new CreatePayoutRequest(
merchantAccountId: "VALID_MERCHANT_ID",
amountInMinor: amount.ToMinorCurrencyUnit(2),
currency: Currencies.GBP,
beneficiary: new Beneficiary.ExternalAccount(
"TrueLayer",
"truelayer-dotnet",
new SchemeIdentifier.Iban("VALID_IBAN")
)
);
var apiResponse = await _client.Payouts.CreatePayout(
payoutRequest,
idempotencyKey: Guid.NewGuid().ToString()
);
if (!apiResponse.IsSuccessful)
{
return HandleFailure(
apiResponse.StatusCode,
// Includes details of any errors
apiResponse.Problem
);
}
return Accepted(apiResponse.Data.Id);
}
}
For more examples see the API documentation. Advanced customization options and documentation for contributors can be found in the Wiki.
Testing
This project includes two types of tests:
Unit Tests - Run standalone without external dependencies:
dotnet test test/TrueLayer.Tests/
Acceptance Tests - End-to-end integration tests that require TrueLayer sandbox credentials:
# Set credentials via environment variables
TrueLayer__ClientId=your_client_id TrueLayer__ClientSecret=your_client_secret dotnet test
# Or run all tests (will fail without credentials)
dotnet test
The acceptance tests make real HTTP calls to TrueLayer's sandbox APIs to validate the entire SDK against live services. See test/TrueLayer.AcceptanceTests/README.md for credential setup instructions.
Building locally
This project uses Cake to build, test and publish packages.
Run build.sh (Mac/Linux) or build.ps1 (Windows) To build and test the project.
This will output NuGet packages and coverage reports in the artifacts directory.
Contributing
Contributions are always welcome!
Please adhere to this project's code of conduct.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 is compatible. 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 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Http (>= 10.0.0)
- OneOf (>= 3.0.271)
- TrueLayer.Signing (>= 0.2.2)
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Http (>= 10.0.0)
- OneOf (>= 3.0.271)
- TrueLayer.Signing (>= 0.2.2)
-
net9.0
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Http (>= 10.0.0)
- OneOf (>= 3.0.271)
- TrueLayer.Signing (>= 0.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 2.0.0-beta4 | 265 | 11/11/2025 | |
| 2.0.0-beta3 | 175 | 11/5/2025 | |
| 2.0.0-beta2 | 175 | 11/4/2025 | |
| 1.25.0 | 277 | 10/15/2025 | |
| 1.24.0 | 8,433 | 7/25/2025 | |
| 1.23.0-alpha1 | 154 | 1/28/2025 | |
| 1.22.0 | 10,006 | 1/15/2025 | |
| 1.22.0-alpha2 | 1,095 | 12/23/2024 | |
| 1.22.0-alpha1 | 169 | 12/20/2024 | |
| 1.21.0 | 498 | 12/18/2024 | |
| 1.20.0 | 461 | 12/11/2024 | |
| 1.20.0-beta1 | 188 | 12/11/2024 | |
| 1.19.0 | 353 | 12/2/2024 | |
| 1.18.0 | 344 | 11/25/2024 | |
| 1.17.0 | 454 | 11/25/2024 | |
| 1.17.0-beta3 | 176 | 11/22/2024 | |
| 1.17.0-beta2 | 167 | 11/22/2024 | |
| 1.17.0-beta1 | 174 | 11/22/2024 | |
| 1.16.0 | 387 | 11/7/2024 | |
| 1.15.1-alpha.0.2 | 129 | 11/7/2024 | |
| 1.15.0 | 453 | 10/10/2024 | |
| 1.14.0 | 389 | 9/30/2024 | |
| 1.13.0 | 442 | 9/11/2024 | |
| 1.12.0 | 3,837 | 8/13/2024 | |
| 1.11.0 | 828 | 8/5/2024 | |
| 1.10.1-beta1 | 226 | 8/5/2024 | |
| 1.10.0 | 10,658 | 8/1/2024 | |
| 1.10.0-beta2 | 224 | 8/1/2024 | |
| 1.10.0-beta1 | 202 | 7/26/2024 | |
| 1.9.0 | 447 | 7/22/2024 | |
| 1.9.0-beta1 | 331 | 7/19/2024 | |
| 1.8.0 | 478 | 7/12/2024 | |
| 1.7.2 | 888 | 6/18/2024 | |
| 1.6.1 | 15,217 | 2/13/2024 | |
| 1.6.0 | 3,519 | 1/22/2024 | |
| 1.5.0 | 1,226 | 11/16/2023 | |
| 1.5.0-beta1 | 324 | 11/15/2023 | |
| 1.4.0 | 3,933 | 10/17/2023 | |
| 1.4.0-beta3 | 978 | 9/13/2023 | |
| 1.4.0-beta2 | 400 | 9/6/2023 | |
| 1.4.0-beta1 | 374 | 9/4/2023 | |
| 1.3.2 | 526 | 10/9/2023 | |
| 1.3.1 | 627 | 8/30/2023 | |
| 1.3.0 | 1,408 | 7/19/2023 | |
| 1.2.2-alpha.0.1 | 327 | 7/19/2023 | |
| 1.2.1 | 1,096 | 4/26/2023 | |
| 1.2.0 | 4,679 | 3/6/2023 | |
| 1.2.0-beta1 | 416 | 3/6/2023 | |
| 1.1.0-beta1 | 439 | 2/19/2023 | |
| 1.0.0 | 1,162 | 1/23/2023 | |
| 0.3.3 | 775 | 1/10/2023 | |
| 0.3.2 | 672 | 12/21/2022 | |
| 0.3.1 | 767 | 11/29/2022 | |
| 0.3.1-beta1 | 434 | 11/25/2022 | |
| 0.3.0 | 834 | 11/2/2022 | |
| 0.3.0-alpha0 | 466 | 11/18/2022 | |
| 0.2.3 | 1,736 | 10/5/2022 | |
| 0.2.2 | 1,424 | 8/18/2022 | |
| 0.2.2-beta3 | 476 | 8/4/2022 | |
| 0.2.2-beta2 | 486 | 8/2/2022 | |
| 0.2.1 | 853 | 7/5/2022 | |
| 0.2.1-beta3 | 507 | 7/1/2022 | |
| 0.2.1-beta2 | 459 | 6/30/2022 | |
| 0.2.1-beta1 | 481 | 6/29/2022 | |
| 0.2.0 | 2,568 | 3/14/2022 | |
| 0.1.1 | 894 | 11/2/2021 |