Falu 2.2.0
See the version list below for details.
dotnet add package Falu --version 2.2.0
NuGet\Install-Package Falu -Version 2.2.0
<PackageReference Include="Falu" Version="2.2.0" />
paket add Falu --version 2.2.0
#r "nuget: Falu, 2.2.0"
// Install Falu as a Cake Addin #addin nuget:?package=Falu&version=2.2.0 // Install Falu as a Cake Tool #tool nuget:?package=Falu&version=2.2.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
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:
- Open the Solution Explorer.
- Right-click on a project within your solution.
- Click on Manage NuGet Packages...
- Click on the Browse tab and search for "Falu".
- 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 | Versions 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. |
-
.NETStandard 2.1
- CloudNative.CloudEvents (>= 2.7.1)
- Microsoft.Extensions.Http.Polly (>= 8.0.6)
- Polly.Contrib.WaitAndRetry (>= 1.1.1)
- System.Net.Http.Json (>= 8.0.0)
-
net7.0
- CloudNative.CloudEvents (>= 2.7.1)
- Microsoft.Extensions.Http.Polly (>= 8.0.6)
- Polly.Contrib.WaitAndRetry (>= 1.1.1)
- System.Net.Http.Json (>= 8.0.0)
-
net8.0
- CloudNative.CloudEvents (>= 2.7.1)
- Microsoft.Extensions.Http.Polly (>= 8.0.6)
- Polly.Contrib.WaitAndRetry (>= 1.1.1)
- System.Net.Http.Json (>= 8.0.0)
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 |
---|---|---|
3.0.0 | 119 | 11/25/2024 |
2.2.1 | 285 | 10/14/2024 |
2.2.0 | 618 | 7/11/2024 |
2.1.0 | 136 | 7/4/2024 |
2.0.1 | 154 | 7/1/2024 |
2.0.0 | 111 | 7/1/2024 |
1.14.0 | 408 | 6/5/2024 |
1.13.1 | 2,493 | 11/20/2023 |
1.13.0 | 346 | 11/20/2023 |
1.12.0 | 1,575 | 7/12/2023 |
1.11.5 | 555 | 7/10/2023 |
1.11.4 | 1,157 | 6/19/2023 |
1.11.3 | 532 | 6/13/2023 |
1.11.2 | 597 | 5/26/2023 |
1.11.1 | 497 | 5/25/2023 |
1.10.0 | 1,625 | 11/22/2022 |
1.9.0 | 1,465 | 9/21/2022 |
1.8.0 | 715 | 9/19/2022 |
1.7.2 | 769 | 9/12/2022 |
1.7.1 | 719 | 9/9/2022 |
1.7.0 | 783 | 9/5/2022 |
1.6.0 | 814 | 8/29/2022 |
1.5.0 | 745 | 8/26/2022 |
1.4.0 | 784 | 8/22/2022 |
1.3.0 | 933 | 7/25/2022 |
1.2.0 | 873 | 7/18/2022 |
1.1.0 | 794 | 7/13/2022 |
1.0.0 | 1,795 | 3/29/2022 |
0.12.0 | 1,026 | 2/10/2022 |
0.11.0 | 997 | 1/19/2022 |
0.10.0 | 677 | 1/4/2022 |
0.9.0 | 850 | 12/6/2021 |
0.8.0 | 1,540 | 9/21/2021 |
0.7.0 | 700 | 9/3/2021 |
0.6.0 | 695 | 8/16/2021 |
0.5.2 | 811 | 8/3/2021 |
0.5.1 | 694 | 7/14/2021 |
0.5.0 | 813 | 6/17/2021 |
0.4.2-ci0008 | 580 | 6/16/2021 |
0.4.2-ci0007 | 587 | 6/14/2021 |