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 thow an exception. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate type.

Error Object 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 ErrorResponse)
    {
        // Handle exception data
        throw;
    }
    else if (ex is 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: number 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
0 http://localhost None
1 https://{stack}.sandbox.formance.cloud None

Override Server URL Per-Client

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

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