SDKs

.NET, Framework and third-party SDKs

Official SDK

The Billecta SDK offers comprehensive models and stub methods for remote calls. We currently offer an official SDK for .NET.

SDK Walkthrough

Installing the package with dotnet CLI:

dotnet add package Billecta.SDK

Getting Started

Pre-requisites

  • .NET environment
  • A valid API key (SecureToken) for the Billecta API.

Example for create a SecureToken as a first-time user

In order to authenticate a call with Basic Authentication you use the Authorization header. The header should be created accordingly:

  • Username and password is combined into a string "username:password"
  • The string should be coded in Base64
  • The authentication method Basic a space should be preceding the coded string

For example, if the user has "Alladin" as a username and "Sesame, open" as a password, the header should have the following structure:

Authorization: Basic QWxsYWRpbjpTZXNhbWUsIG9wZW4=

You can use Basic authentication in all calls to the Billecta API.

An example for production using CURL for generating a SecureToken:

curl -X "POST" https://api.billecta.com/v1/authentication/apiauthenticate -H "Content-Length:0" -H "Authorization: Basic QWxsYWRpbjpTZXNhbWUsIG9wZW4=" -H "Accept: application/json"

The response will contain a SecureToken that you will need to base64-encode to use in your API calls. Once you have encoded the SecureToken, you can use it in your API calls. To test the SecureToken you can execute following curl:

curl -X "GET" https://api.billecta.com/v1/users/users -H "Content-Length:0" -H "Authorization: SecureToken {base64-encoded SecureToken}" -H "Accept: application/json"

Usage

Initialize the SDK

Create an instance of the connectors provided by the SDK to interact with the Billecta API. To specify target environment, pass the EnvironmentType parameter to the constructor. Default is Production:

For test environment

var productConnector = new ProductConnector("Insert secureToken", EnvironmentType.Testing);

For production

var productConnector = new ProductConnector("Insert secureToken");

Code Samples

To quickly get started with the SDK, here are some practical examples:

var dc = new DebtorConnector($"{secureToken}");
var debtor = new DebtorView
{
     CreditorPublicId = creditorPublicId, /* Enter the owner creditor public id here */
     Name = "Acme AB",
     Address = "Address 1",
     ZipCode = "11173",
     City = "Stockholm",
     ContactEmail = "john.doe@acme.com",
     ContactName = "John Doe",
     CountryCode = "SE",
     Email = "invoice@acme.com",
     OrgNo = "556677-8899",
     VatNumber = "SE556677889901",
};

var response = await dc.CreateAsync(debtor);

if (response.IsSuccess)
{
    var debtorPublicId = Guid.Parse(response.Value!.PublicId); // save debtorPublicId on you side
}
var ic = new InvoiceConnector($"{secureToken}");

var entry = new InvoiceActionEntryView
{
    CreditorPublicId = creditorPublicId, /* Enter the owner creditor public id here */
    CommunicationLanguage = LanguageTypeView.SV,
    DebtorPublicId = debtorPublicId,  /* Enter the debor public id here */
    DeliveryMethod = DeliveryMethodTypeView.Email,
    InvoiceDate = DateTime.Now,
    DueDate = DateTime.Now.AddDays(20),
    InvoiceNumber = null, // when set to null Billecta api will generate invoice number for you
    InvoiceFee = new AmountView(2500, "SEK"), // 25 SEK invoice fee
    InvoicePDF = null, // when set to null Billecta wil generate the invoice pdf
    OurReference = "John Doe", // you contact person
    YourReference = "Customer contact name",
    InterestPercentage = 8,
    InterestType = InterestTypeView.AboveEffectiveReference,
    InterestStartInDaysAfterDueDate = 0, // start ticking invoice from first due date
    Records =
    [
        new InvoiceActionRecordView
        {
            SequenceNo = 0,
            ArticleNumber = "1",
            ArticleDescription = "Socks",
            ProductPublicId = socksProductPublicId, /* Retreive the socks product public id here */
            Quantity = 10,
            Units = "pairs",
            RecordType = RecordTypeView.Standard,
            UnitPrice = new AmountView(10000, "SEK"), // costs 100 SEK each pair
            VAT = 25,
        },
        new InvoiceActionRecordView
        {
            SequenceNo = 1,
            ArticleNumber = "4",
            ArticleDescription = "Shoes",
            ProductPublicId = shoesProductPublicId, /* Retreive the shoes product public id here */
            Quantity = 2,
            Units = "pairs",
            RecordType = RecordTypeView.Standard,
            UnitPrice = new AmountView(50000, "SEK"), // costs 500 SEK each pair
            VAT = 25,
        },
        new InvoiceActionRecordView
        {
            SequenceNo = 3,
            ArticleDescription = "Thank you for purchasing at Acme",
            RecordType = RecordTypeView.Message
        }
    ]
};

var response = await ic.CreateInvoiceAsync(entry);

if (response.IsSuccess)
{
    string actionPublicId = response.Value!.PublicId;
    // ActionPublicId can then be used to attest the invoice to finalize it and send it to the debtor
    await ic.AttestAsync(actionPublicId);
}

Third-party SDKs

PHP

PHP SDK

There is an open source PHP SDK initiated by Johan Eliasson (elitan). The SDK is not complete but a good start and may be contributed to. Please note that this is third-party maintained by the open source community.

Rust

Rust SDK

A Rust client library for the Billecta API, available on crates.io. This SDK provides type-safe access to Billecta's invoicing and payment services. Please note that this is third-party maintained by the open source community.