![]() |
VOOZH | about |
dotnet add package ClearBank.Net --version 1.0.37
NuGet\Install-Package ClearBank.Net -Version 1.0.37
<PackageReference Include="ClearBank.Net" Version="1.0.37" />
<PackageVersion Include="ClearBank.Net" Version="1.0.37" />Directory.Packages.props
<PackageReference Include="ClearBank.Net" />Project file
paket add ClearBank.Net --version 1.0.37
#r "nuget: ClearBank.Net, 1.0.37"
#:package ClearBank.Net@1.0.37
#addin nuget:?package=ClearBank.Net&version=1.0.37Install as a Cake Addin
#tool nuget:?package=ClearBank.Net&version=1.0.37Install as a Cake Tool
Unofficial .NET client for ClearBank integration, creating online payments via their API. Bank payment handling automation in the United Kingdom (UK/GB) and European Union (EU). Released as a NuGet package. This aims to be bare and easy.
The library has been structured as UK/UK.Multicurrency/EU, and aims to cover major use cases from ClearBank developer portal with simple setup in both Microsoft DotNet and Microsoft .NET Framework.
Here are the pre-conditions:
From the Access Policies, add the role, and "Key Permissions" for the Sign & Verify. Azure KeyVault supports HSM (hardware security module) backed keys.
For example, a new self-signed certificate can be used, but the PEM format has to be selected.
Download the certificate, a PEM-file.
openssl.exe req -new -sha256 -key "c:\temp\downloaded.pem" -out file.csr
Authorization: Bearer (the long string)Update: You can also get CSR now directly from Azure keyvault, by selecting the certificate and clicking "Certificate Operation" → "Download CSR"
The signing is done similarly to this repo, but the official code is more messy because it's C#. GitHub - clearbank/fi-api-signtool
Your user code should look something like this:
let doSomeTransactions =
let clearbankDefaultConfig =
{
BaseUrl = "https://institution-api-sim.clearbank.co.uk/"
PrivateKey = "..."
AzureKeyVaultName = "myVault"
AzureKeyVaultCredentials = DefaultCredentials
} : ClearBank.Common.ClearbankConfigruation
let azureKeyVaultCertificateName = "my-cert"
let fromAccount = ClearBank.Common.UK_Domestic("60-01-34", "51112345")
let target1 =
ClearBank.UK.createCreditTransfer
{
To = ClearBank.Common.UK_Domestic("20-20-15", "55555555")
AccountHolder = "Mr Test"
Sum = 123.00m
Currency = "GBP"
Description = "Phone Bill"
PaymentReference = "123456789"
TransactionId = "12345" // End-to-end: You identify corresponding webhooks with this.
}
let target2 =
ClearBank.UK.createCreditTransfer
{
To = ClearBank.Common.UK_Domestic("40-47-84", "70872490")
AccountHolder = "John Doe"
Sum = 123.00m
Currency = "GBP"
Description = "Some money"
PaymentReference = "12345"
TransactionId = "12345"
}
let xReqId = Guid.NewGuid()
let instructions = ClearBank.UK.createPaymentInstruction "Batch123" fromAccount [| target1 ; target2 |]
ClearBank.UK.transferPayments clearbankDefaultConfig azureKeyVaultCertificateName xReqId [| instructions |] |> Async.RunSynchronously
If you have problems with the KeyVault authentication, you can change the AzureKeyVaultCredentials in the config
let clearbankDefaultConfig =
{
BaseUrl = "https://institution-api-sim.clearbank.co.uk/"
PrivateKey = "..."
AzureKeyVaultName = "..."
AzureKeyVaultCertificateName = "..."
AzureKeyVaultCredentials =
CredentialsWithOptions (
Azure.Identity.DefaultAzureCredentialOptions (
//ExcludeEnvironmentCredential = true
//,ExcludeManagedIdentityCredential = true
ExcludeSharedTokenCacheCredential = true
,ExcludeVisualStudioCredential = true
//,ExcludeVisualStudioCodeCredential = true
//,ExcludeAzureCliCredential = true
//,ExcludeInteractiveBrowserCredential = true
))
LogUnsuccessfulHandler = None
} : ClearBank.Common.ClearbankConfiguration
The last LogUnsuccessfulHandler property is an optional error-logging callback. You could replace it e.g. with Some logging and have a function:
let logging(status,content) =
match ClearBank.Common.parseClarBankErrorContent content with
| ClearBankEmptyResponse -> Console.WriteLine "Response was empty"
| ClearBankTransactionError errors -> errors |> Seq.iter(fun (tid,err) -> Console.WriteLine("Transaction id " + tid + " failed for " + err))
| ClearBankGeneralError(title, detail) -> Console.WriteLine(title + ", " + detail)
| ClearBankUnknownError content -> Console.WriteLine("JSON: " + content)
There is a method ClearBank.UK.createNewAccount to create new accounts.
There are methods ClearBank.UK.getAccounts, that you can use for e.g. getting balances,
and ClearBank.UK.getTransactions config pageSize pageNumber startDate endDate
To receive webhooks, you need a web server, which is outside the scope of this library. However, there are some helper classes provided in this library.
To use those, your server code could look something like this:
type CBWebhookController() as this =
inherit ApiController()
member __.Post ()
async {
// 1. Verify the webhook against your ClearBank public key:
// Download the public key (a .pem file) from your ClearBank portal and use a converter such as https://raskeyconverter.azurewebsites.net/PemToXml to convert the text to XML
let publicKeyXml = "<RSAKeyValue>...</RSAKeyValue>"
let signature = this.Request.Headers.GetValues("DigitalSignature") |> Seq.tryHead |> Option.map Convert.FromBase64String //add some error handling
let! bodyJson = this.Request.Content.ReadAsStringAsync() |> Async.AwaitTask
let! isVerified = ClearBank.Common.verifySignature publicKeyXml signature bodyJson //proceed only if true
// 2. Parse and handle the request:
let parsed = ClearBank.Webhooks.parsePaymentsCallUK bodyJson
// Use parsed.Type to get the webhook type.
// Different types may have the corresponding end-to-end transactionId in different places.
// Fetch your transaction based on that ID, and do whatever you want.
// match parsed.Type with
// | ClearBank.Webhooks.WebhookTypes.UK.TransactionSettled -> ...
// | ClearBank.Webhooks.WebhookTypes.UK.PaymentMessageAssessmentFailed -> ...
// | ClearBank.Webhooks.WebhookTypes.UK.PaymentMessageValidationFailed -> ...
// | ClearBank.Webhooks.WebhookTypes.UK.TransactionRejected -> ...
// | _ -> (* "FITestEvent" *) ...
// 3. Create response
return! ClearBank.Webhooks.createResponse clearbankDefaultConfig azureKeyVaultCertificateName this.Request parsed.Nonce
} |> Async.StartAsTask
To test webhooks, you can use e.g. Fiddler to compose them and https://webhook.site/ to get their calls.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.37 | 119 | 4/30/2026 |
| 1.0.35 | 260 | 11/2/2025 |
| 1.0.34 | 238 | 10/27/2025 |
| 1.0.33 | 359 | 5/8/2025 |
| 1.0.32 | 596 | 3/12/2025 |
| 1.0.31 | 599 | 1/24/2025 |
| 1.0.29 | 311 | 1/21/2025 |
| 1.0.28 | 296 | 1/16/2025 |
| 1.0.27 | 300 | 1/14/2025 |
| 1.0.26 | 841 | 10/7/2024 |
| 1.0.25 | 759 | 7/14/2024 |
| 1.0.24 | 1,192 | 3/13/2024 |
| 1.0.23 | 316 | 3/12/2024 |
| 1.0.22 | 770 | 1/10/2024 |
| 1.0.21 | 386 | 1/3/2024 |
| 1.0.20 | 580 | 12/6/2023 |
| 1.0.19 | 349 | 12/1/2023 |
| 1.0.18 | 674 | 10/22/2023 |