Skip to content

formancehq/formance-sdk-csharp

Repository files navigation

formance

Developer-friendly & type-safe Csharp SDK specifically catered to leverage formance API.

🏗 Welcome to your new SDK! 🏗

It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:

Summary

Formance Stack API: Open, modular foundation for unique payments flows

Introduction

This API is documented in OpenAPI format.

Authentication

Formance Stack offers one forms of authentication:

  • OAuth2 OAuth2 - an open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications.

Table of Contents

SDK Installation

NuGet

To add the NuGet package to a .NET project:

dotnet add package formance

Locally

To add a reference to a local instance of the SDK in a .NET project:

dotnet add reference src/formance/formance.csproj

SDK Example Usage

Example

using formance;
using formance.Models.Components;

var sdk = new Formance(security: new Security() {
    ClientID = "<YOUR_CLIENT_ID_HERE>",
    ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
});

var res = await sdk.GetVersionsAsync();

// handle response

Available Resources and Operations

Available methods

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default, an API error will raise a formance.Models.Errors.SDKException exception, which has the following properties:

Property Type Description
Message string The error message
Request HttpRequestMessage The HTTP request
Response HttpResponseMessage The HTTP response

When custom error responses are specified for an operation, the SDK may also throw their associated exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the GetInfoAsync method throws the following exceptions:

Error Type Status Code Content Type
formance.Models.Errors.ErrorResponse default application/json
formance.Models.Errors.SDKException 4XX, 5XX */*

Example

using formance;
using formance.Models.Components;
using System;
using formance.Models.Errors;

var sdk = new Formance(security: new Security() {
    ClientID = "<YOUR_CLIENT_ID_HERE>",
    ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
});

try
{
    var res = await sdk.Ledger.V1.GetInfoAsync();

    // handle response
}
catch (Exception ex)
{
    if (ex is Models.Errors.ErrorResponse)
    {
        // Handle exception data
        throw;
    }
    else if (ex is formance.Models.Errors.SDKException)
    {
        // Handle default exception
        throw;
    }
}

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the serverIndex: int optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server Variables Default values
0 http://localhost
1 https://{organization}.{environment}.formance.cloud organization: string
environment: ServerEnvironment
"orgID-stackID"
"sandbox"

If the selected server has variables, you may override their default values through the additional parameters made available in the SDK constructor.

Example

using formance;
using formance.Models.Components;

var sdk = new Formance(
    serverIndex: 1,
    security: new Security() {
        ClientID = "<YOUR_CLIENT_ID_HERE>",
        ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
    }
);

var res = await sdk.GetVersionsAsync();

// handle response

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the serverUrl: string optional parameter when initializing the SDK client instance. For example:

using formance;
using formance.Models.Components;

var sdk = new Formance(
    serverUrl: "http://localhost",
    security: new Security() {
        ClientID = "<YOUR_CLIENT_ID_HERE>",
        ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
    }
);

var res = await sdk.GetVersionsAsync();

// handle response

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
ClientID
ClientSecret
oauth2 OAuth2 Client Credentials Flow

You can set the security parameters through the security optional parameter when initializing the SDK client instance. For example:

using formance;
using formance.Models.Components;

var sdk = new Formance(security: new Security() {
    ClientID = "<YOUR_CLIENT_ID_HERE>",
    ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
});

var res = await sdk.GetVersionsAsync();

// handle response

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

SDK Created by Speakeasy