Git Product home page Git Product logo

ibanity-dotnet's Introduction

Ibanity .NET client library

Build status License: MIT NuGet

This .NET Client library offers various services you can use in order to submit requests towards the Ibanity Platform.

Quick start

Configure the library using IbanityServiceBuilder.

Minimal configuration values are:

  • The Ibanity URL
  • Your application private key and public certificate as .pfx file (PKCS#12)
  • The passphrase for the private key
var ibanityService = new IbanityServiceBuilder().
    SetEndpoint("https://api.ibanity.com").
    AddClientCertificate(
        certificatePath,
        certificatePassword).
    Build();

You can then make use of Ponto Connect services through your IIbanityService instance.

var financialInstitutions = await ibanityService.PontoConnect.FinancialInstitutions.List();

All services are thread safe and can be configured as singleton if you want to leverage frameworks like IServiceProvider or Castle Windsor. To avoid exhausting client ports, you should use a single IIbanityService instance across your application.

Code samples

There are three sample projects available within this repository:

See ClientSample class for extended examples.

Use token to authenticate requests

A token is required to access most resource types.

var ibanityService = new IbanityServiceBuilder().
    SetEndpoint("https://api.ibanity.com").
    AddClientCertificate(
        certificatePath,
        certificatePassword).
    AddPontoConnectOAuth2Authentication(
        pontoConnectClientId,
        pontoConnectClientSecret).
    Build();

var token = await ibanityService.PontoConnect.TokenService.GetToken(refreshToken);
var accounts = await ibanityService.PontoConnect.Accounts.List(token);

// Once done, you have to save the refresh token somewhere, so you can use it later to get another token.
// Refresh token value contained within the token instance is automatically updated from time to time.
SaveToken(token.RefreshToken);

Perform custom requests to Ibanity

You can perform custom HTTP calls to Ibanity using the IApiClient.

It can be accessed by calling:

var lowLevelClient = ibanityService.PontoConnect.ApiClient;

Configure proxy

If you are using a Web application firewall or a proxy, you can configure it in the IbanityServiceBuilder, using one of these methods:

AddProxy(IWebProxy proxy);
AddProxy(Uri endpoint);
AddProxy(string endpoint);
var ibanityService = new IbanityServiceBuilder().
    SetEndpoint("https://api.ibanity.com").
    AddClientCertificate(
        certificatePath,
        certificatePassword).
    AddProxy("https://internal.proxy.com").
    Build();

Sign custom requests to Ibanity

If you want to sign HTTP requests, you can use the IHttpSignatureService from the library.

var signatureService = new HttpSignatureServiceBuilder().
    SetEndpoint("https://api.ibanity.com").
    AddCertificate(
        certificateId,
        certificatePath,
        certificatePassword).
    Build();

Configure HTTP timeouts

var ibanityService = new IbanityServiceBuilder().
    SetEndpoint("https://api.ibanity.com").
    AddClientCertificate(
        certificatePath,
        certificatePassword).
    SetTimeout(TimeSpan.FromSeconds(30)).
    Build();

Verify and parse webhook events

var webhookEvent = await ibanityService.Webhooks.VerifyAndDeserialize(
    payload, // webhook body
    signature); // webhook 'Signature' header

switch (webhookEvent)
{
    case SynchronizationSucceededWithoutChange synchronizationEvent:
        Console.WriteLine(synchronizationEvent.SynchronizationSubtype);
        break;
    ...
}

Certificates

Creating PFX certificate file

You may need to convert your certificate from .pem files to a .pfx file (also known as PKCS#12 format). You can use an OpenSSL command to do so:

openssl pkcs12 -export -in certificate.pem -inkey private_key.pem -out certificate.pfx

Where:

  • certificate.pem is your existing certificate
  • private_key.pem is the private key matching your existing certificate
  • certificate.pfx is the resulting PKCS#12 file

You will have to enter the passphrase protecting the private_key.pem file, then (twice) the passphrase you want to use to encrypt the certificate.pfx file.

Loading certificate

Mutual TLS client certificate (as well as signature certificate) can be loaded in two different ways:

  • Using the path to the file holding the certificate, and its passphrase.
  • Using a X509Certificate2 instance, allowing you to load the certificate from a custom location you manage.

Azure App Service

When running on Azure App Service, even when loading the certificate from a file, Windows must access the certificate store. This may lead to an exception when the library is loading certificates.

You can use Azure CLI to allow this operation:

az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_LOAD_USER_PROFILE=1

More information is available in App Service documentation.

Requirements

Either:

  • .NET Framework 4.6.2 (or above)
  • .NET Core 2.0 (or above)
  • .NET 5.0 (or above)

ibanity-dotnet's People

Contributors

stephdewit avatar damienbr avatar cleclefibanity avatar

Stargazers

 avatar

Watchers

 avatar Loic Vigneron avatar Gilles Hooghe avatar Jens avatar  avatar

Forkers

joachimvr

ibanity-dotnet's Issues

[Codabox Connect] Relationship for documents when searching for multiple clients

When searching documents for multiple clients in one call, it seems that the DocumentSearchResponse class doesn't indicate the relationship with the requested clients.

In the REST API, however, the relationship is available in the response via the included.documents property.

Screenshot 2023-02-02 at 16 11 31

Is this something that will be added in the near future?
Looping through the returned documents and fetching additional details is not possible at the moment because we don't know to which client the document belongs to (unless we only fetch for 1 client at the time).

var documentSearchRequest = new DocumentSearch
{
    DocumentType = "bankAccountStatement", 
    From = new DateTimeOffset(2022, 1, 1, 0, 0, 0, TimeSpan.Zero),
    To = new DateTimeOffset(2023, 1, 1, 0, 0, 0, TimeSpan.Zero)
};
        
var documentSearchResponse = await ibanityService.CodaboxConnect.DocumentSearches.Create(
    token, 
    consent.AccountingOfficeId, 
    documentSearchRequest,
    new [] { "customerCompanyNumber1", "customerCompanyNumber2" },
    100
);

foreach (var document in documentSearchResponse.Documents)
{
        var statement = await ibanityService.CodaboxConnect.BankAccountStatements.Get(token, consent.AccountingOfficeId, "company number required here", Guid.Parse(document.Id));
}

authentication URL not working

Hi, I'm trying to connect through authentication URL for this web app but it's not working for me so can you please guide me from where can I generate authentication URL for my app. thank you

[Codabox Connect] Invalid payload when searching documents

We're currently trying to integrate with Codabox Connect but when doing a document search we get the following response:

Unhandled exception. Ibanity.Apis.Client.Http.IbanityClientException: Request 0001B2779489D1030A01069401BB63DA3DEF1821DC1AFD failed (400 BadRequest): invalidPayload (The submitted payload could not be parsed. Unknown property: meta)
   at Ibanity.Apis.Client.Http.HttpResponseMessageExtensions.ThrowOnFailure(HttpResponseMessage this, ISerializer`1 serializer, ILogger logger)
   at Ibanity.Apis.Client.Http.ApiClient.SendWithPayload[TRequest,TResponse](HttpMethod method, String path, String bearerToken, TRequest payload, Nullable`1 idempotencyKey, CancellationToken cancellationToken)
   at Ibanity.Apis.Client.Products.BaseResourceClient`6.InternalCreate[TRequestAttributes,TRequestMeta,TRequestRelationships,TRequestLinks](TToken token, String path, Data`4 payload, Nullable`1 idempotencyKey, Nullable`1 cancellationToken)
   at Program.<Main>$(String[] args) in /Users/thomasvdb/Research/IbanityClientResearch/IbanityClientResearch/Program.cs:line 29
   at Program.<Main>(String[] args)

This is the code of a Console program I tried setting up:

using Ibanity.Apis.Client;
using Ibanity.Apis.Client.Products.CodaboxConnect.Models;

var certificatePath = "";
var certificatePassword = "";
var codaboxConnectClientId = "";
var codaboxConnectClientSecret = "";
var consentId = Guid.Parse("");
var customerCompanyNumber = "";

var ibanityService = new IbanityServiceBuilder().
    SetEndpoint("https://api.ibanity.com").
    AddClientCertificate(
        certificatePath,
        certificatePassword).
    AddCodaboxConnectOAuth2Authentication(codaboxConnectClientId, codaboxConnectClientSecret).
    Build();

var token = await ibanityService.CodaboxConnect.ClientTokenService.GetToken();
var consent = await ibanityService.CodaboxConnect.AccountingOfficeConsents.Get(token, consentId);

Console.WriteLine($"Consent found. Accounting office ID: {consent.AccountingOfficeId}");

var documentSearchRequest = new DocumentSearch
{
    DocumentType = "creditCardStatement", 
    From = new DateTimeOffset(2022, 1, 1, 0, 0, 0, TimeSpan.Zero),
    To = new DateTimeOffset(2023, 1, 1, 0, 0, 0, TimeSpan.Zero),
};
        
var documentSearchResponse = await ibanityService.CodaboxConnect.DocumentSearches.Create(
    token, 
    consent.AccountingOfficeId, 
    documentSearchRequest,
    new [] { customerCompanyNumber }
);

foreach (var document in documentSearchResponse.Documents)
{
    Console.WriteLine($"Document ID: {document.Id}");
}

Fetching the consent works but the document search fails with the exception mentioned in the beginning.
Is there something incorrectly configured in the request?

Tested this with .NET 6 on macOS Ventura 13.2

[Codabox Connect] Fetching bank statement details by ID throws validation error

When trying to fetch the details of a bank account statement, I get the following validation error:

Error: Request 0001B2779489ECEF0A01069401BB63DB8AE96C261437A failed (400 BadRequest): validationError (must be a valid Belgian company number)

Code sample:

using Ibanity.Apis.Client;
using Ibanity.Apis.Client.Products.CodaboxConnect.Models;

var certificatePath = "";
var certificatePassword = "";
var codaboxConnectClientId = "";
var codaboxConnectClientSecret = "";
var consentId = Guid.Parse("");
var customerCompanyNumber = "";

var ibanityService = new IbanityServiceBuilder().
    SetEndpoint("https://api.ibanity.com").
    AddClientCertificate(
        certificatePath,
        certificatePassword).
    AddCodaboxConnectOAuth2Authentication(codaboxConnectClientId, codaboxConnectClientSecret).
    Build();

var token = await ibanityService.CodaboxConnect.ClientTokenService.GetToken();
var consent = await ibanityService.CodaboxConnect.AccountingOfficeConsents.Get(token, consentId);

Console.WriteLine($"Consent found. Accounting office ID: {consent.AccountingOfficeId}");

var documentSearchRequest = new DocumentSearch
{
    DocumentType = "bankAccountStatement", 
    From = new DateTimeOffset(2022, 1, 1, 0, 0, 0, TimeSpan.Zero),
    To = new DateTimeOffset(2023, 1, 1, 0, 0, 0, TimeSpan.Zero),
};
        
var documentSearchResponse = await ibanityService.CodaboxConnect.DocumentSearches.Create(
    token, 
    consent.AccountingOfficeId, 
    documentSearchRequest,
    new [] { customerCompanyNumber }
);

foreach (var document in documentSearchResponse.Documents)
{
    Console.WriteLine($"Document ID: {document.Id}");

    try
    {
        var statement = await ibanityService.CodaboxConnect.BankAccountStatements.Get(token, consent.AccountingOfficeId, codaboxConnectClientId, Guid.Parse(document.Id));
        Console.WriteLine("Statement: " + JsonSerializer.Serialize(statement));
    }
    catch (Exception exp)
    {
        Console.WriteLine("Error: " + exp.Message);
    }
}

This validation error is thrown when calling ibanityService.CodaboxConnect.BankAccountStatements.Get(...) but we don't specify a company number here, only the document ID which we received from the previous call (which worked so the company number seems to be correct).

The same validation is error is thrown when calling ibanityService.CodaboxConnect.BankAccountStatements.GetPdf(...).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.