Falu 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Falu --version 2.1.0                
NuGet\Install-Package Falu -Version 2.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Falu" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Falu --version 2.1.0                
#r "nuget: Falu, 2.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Falu as a Cake Addin
#addin nuget:?package=Falu&version=2.1.0

// Install Falu as a Cake Tool
#tool nuget:?package=Falu&version=2.1.0                

<a href="https://falu.io"> <img src="falu-logo.png" alt="Falu Logo" title="Falu" width="120" height="120" align="right"> </a>

Falu .NET

NuGet GitHub Workflow Status

The official Falu .NET library, supporting .NET Standard 2.1+.

Installation

Using the .NET Core command-line interface (CLI) tools:

dotnet add package Falu

Using the NuGet Command Line Interface (CLI):

nuget install Falu

Using the Package Manager Console:

Install-Package Falu

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on a project within your solution.
  3. Click on Manage NuGet Packages...
  4. Click on the Browse tab and search for "Falu".
  5. Click on the Falu package, select the appropriate version in the right-tab and click Install.

Documentation

For a comprehensive list of examples, check out the API documentation.

Usage

Simple instance

You can create an instance of the client manually as shown below:

public class Program
{
    static async Task Main(string[] args)
    {
        var apiKey = "<put-you-key-here>";
        var options = Options.Create(new FaluClientOptions { ApiKey = apiKey, });

        var client = new FaluClient(new HttpClient(), options);
        // .... do whatever you wish
    }
}

Dependency Injection

Often it is recommended that you make use of an IoC container to control the lifetime of dependencies created. This is the case in ASP.NET Core but can also be done in background jobs. First, you would put the API Key in your secret:

{
    "Falu": {
        "ApiKey": "<put-you-key-here>",
        "Retries": 3, // defaults to 2
    }
}

To setup the secret via cli, use the command:

dotnet secrets add "Falu:ApiKey" "<put-you-key-here>"

Next add the client to you instance of IServicesCollection in Startup.cs or Program.cs:

public Startup(IConfiguration configuration)
{
   Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
   // Add client
   services.AddFalu(Configuration["Falu:ApiKey"]);

   // The sample service we'll use to demonstrate usage
   // It is recommended the service be consumed in a service with scoped or transient lifetime and not in a singleton one
   // If you have to consume in a singleton service, inject an instance of IServiceProvider and get an instance from there when needed
   services.AddScoped<MyService>();
   ....
}

Our sample service would then make use of the FaluClient as follows:

private readonly FaluClient client;
public MyService(FaluClient client)
{
   this.client = client ?? throw new ArgumentNullException(nameof(client));
}

public async Task DoSomethingAsync(CancellationToken cancellationToken = default)
{
    // utilize as shown in the simple example above
}

Per-request configuration

All of the service methods accept an optional idempotency key.

var request = new IdentityVerificationCreateRequest
{
    // omitted for brevity
};
var ro = new RequestOptions { IdempotencyKey = "SOME STRING", };
await client.IdentityVerifications.CreateAsync(request: request, options: ro);

Identity

With FaluClient you can verify your user's identity from a documentation perspective. Below is a sample of how to do verify the user's phone number against a name or id card.

FaluClient client; // omitted for brevity

var request = new IdentityVerificationCreateRequest
{
    Type = "document", // can also be "id_number" or "document_and_selfie" or "document_and_video"
    Options = new IdentityVerificationOptions
    {
        AllowUploads = true,
        Document = new IdentityVerificationOptionsForDocument { },
    },
    ReturnUrl = "https://my-app.com/verify/waiting?userId=123456",
};
var response = await client.IdentityVerifications.CreateAsync(request);
response.EnsureSuccess(); // might throw an exception (FaluException)
var url = response.Resource.Url; // use this URL to complete verification
var clientSecret = response.Resource.ClientSecret; // pass this to Android/iOS apps using the official SDK

Messages

With FaluClient you can send both transactional and bulk messages to customers. You can use pre-created templates to streamline sending of your messages. Below is a sample of how to create a template then used it to send a message.

FaluClient client; // omitted for brevity

// Creating message template (only needs to be done once)
await client.MessageTemplates.CreateAsync(new TemplatePatchModel
{
    Description = "Sample Template",
    Alias = "sample-template",
    Body = "This is my template {{var1}} and {{var2}}"
});

// Sending of templated messages
var message = new MessageCreateRequest
{
    To = "+254722000000",
    Template = new MessageTemplate
    {
        Alias = "sample-template",
        Model = new { var1 = "test", var2 = "test2" },
    }
};

// Send message, delivery shall be relayed via webhooks
var response = await client.Messages.CreateAsync(message);
response.EnsureSuccess(); // might throw an exception (FaluException)

Templates should be created only once before use. Store the template ID or the Alias in your application and use either to reference the template.

Payments

Below is a sample of how to request money from a customer via MPESA STK Push (a.k.a. Popup, Checkout, etc.).

FaluClient client; // omitted for brevity

var request = new PaymentRequest
{
    Amount = 1000,
    Currency = "kes",
    Mpesa = new PaymentRequestMpesaStkPush
    {
        Phone = "+254722000000",
        Reference = "<put-payment-reference-here>",
        Paybill = true, // false to tills (a.k.a Buygoods)
        Destination = "<put-short-code-here>", // required for specificity
    }
};

// Initiate the payment, completion shall be relayed via webhooks
var response = await client.Payments.CreateAsync(request);
response.EnsureSuccess(); // might throw an exception (FaluException)

Your incoming account for MPESA must be configured in your Workspace settings before you can initiate an outgoing payment to a customer.

Transfers

With FaluClient you can send and receive money to and from customers or businesses via multiple payment providers. Below is a sample of how to send money to a customer via MPESA.

FaluClient client; // omitted for brevity

var request = new TransferRequest
{
    Amount = 1000,
    Currency = "kes",
    Purpose = "business", // can also be "salary"
    Mpesa = new TransferRequestMpesa
    {
        Customer = new TransferRequestMpesaToCustomer
        {
            Phone = "+254722000000",
            Source = "<put-short-code-here>", // required for specificity
        },
    }
};

// Initiate the transfer, completion shall be relayed via webhooks
var response = await client.Transfers.CreateAsync(request);
response.EnsureSuccess(); // might throw an exception (FaluException)

Your outgoing account for MPESA must be configured in your Workspace settings before you can initiate an outgoing payment to a customer.

Development

For any requests, bug or comments, please open an issue or submit a pull request.

License

The Library is licensed under the MIT license. Refer to the LICENSE file for more information.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.1 220 10/14/2024
2.2.0 616 7/11/2024
2.1.0 134 7/4/2024
2.0.1 152 7/1/2024
2.0.0 109 7/1/2024
1.14.0 406 6/5/2024
1.13.1 2,491 11/20/2023
1.13.0 344 11/20/2023
1.12.0 1,573 7/12/2023
1.11.5 553 7/10/2023
1.11.4 1,155 6/19/2023
1.11.3 530 6/13/2023
1.11.2 595 5/26/2023
1.11.1 495 5/25/2023
1.10.0 1,623 11/22/2022
1.9.0 1,463 9/21/2022
1.8.0 713 9/19/2022
1.7.2 767 9/12/2022
1.7.1 717 9/9/2022
1.7.0 781 9/5/2022
1.6.0 812 8/29/2022
1.5.0 743 8/26/2022
1.4.0 782 8/22/2022
1.3.0 931 7/25/2022
1.2.0 871 7/18/2022
1.1.0 792 7/13/2022
1.0.0 1,793 3/29/2022
0.12.0 1,024 2/10/2022
0.11.0 995 1/19/2022
0.10.0 675 1/4/2022
0.9.0 848 12/6/2021
0.8.0 1,538 9/21/2021
0.7.0 698 9/3/2021
0.6.0 693 8/16/2021
0.5.2 809 8/3/2021
0.5.1 692 7/14/2021
0.5.0 811 6/17/2021
0.4.2-ci0008 580 6/16/2021
0.4.2-ci0007 587 6/14/2021