LNBits Client is shipped with LightningPay
package.
More info :
string apiKey = "YourApiKey";
using (var client = LNBitsClient.New("https://lnbits.com/", apiKey))
{
//Your code...
}
If you wants to use your own HttpClient to request the LNBits API, you can send it with the parameter "httpClient" of the method New() :
using (HttpClient httpClient = new HttpClient())
{
var client = LNBitsClient.New("https://lnbits.com/", apiKey, httpClient: httpClient);
//Your code...
}
You can retrieve a code sample with LNBits Client here : LNBits Client Sample
LightningPay.DependencyInjection
package adds extension method to create the LNBits Client with .NET Core Dependency Injection in your startup file :
public void ConfigureServices(IServiceCollection services)
{
///...
string apiKey = "YourApiKey";
services.AddLNBitsLightningClient(new Uri("https://lnbits.com/"), apiKey);
}
The AddLNBitsLightningClient
method has optionnal pamameters to configure your client :
Parameter name | Type | Required | Description |
---|---|---|---|
address | Uri |
Yes | Address of the LNBits api (example : https://lnbits.com/) |
apiKey | String |
Yes | LNBits api key |
retryOnHttpError | int |
No | Number of retry on http error |
certificateThumbprint | String |
No | Certificate thumbprint used for your https address if the certificate is not public Ex : "284800A04D0C046636EBE60C37A4F527B8B550F3" |
allowInsecure | bool |
No | If you use https address, determine if you allow non secure transport (certificateThumbprint parameter will be ignored) |
Once you register LightningPay
, you can use the client in any object by dependency injection in constructor :
private readonly ILightningClient lightningClient;
public HomeController(ILightningClient lightningClient)
{
this.lightningClient = lightningClient;
}
You can retrieve a code samples used Dependency Injection in the Visual Studio Solution WebApp.sln
LNBits has a lot of extensions ! You can easly add your own method to implements the extension of your choice by add extension methods to the ILightningClient
interface.
You just need the LightningPay.Abstractions
package to create your extension methods.
You can retrieve a code samples in the Visual Studio Solution LNBitsExtensions.sln
public static async Task<string> AddLNUrlp(this ILightningClient client,
long amount,
string description)
{
var response = await client.ToRestClient()
.Post<CreatePayLinkResponse>("lnurlp/api/v1/links", new CreatePayLinkRequest()
{
Amount = amount,
Min = amount,
Max = amount,
Description = description,
MaxCommentChars = 20
});
return response.Url;
}