.NET
Learn how to work with Dojo's .NET SDK for the Payments API.
The Dojo.Net NuGet package is the official Dojo .NET library, supporting .NET Standard 2.0+, .NET Core 2.0+, and .NET Framework 4.6.1+.
Installing the SDK
The fastest way to start using the package is to install it using the .NET CLI
dotnet add package
command
in your project directory, but you can also use other methods like the NuGet CLI and the Microsoft Package Manager Console.
- .NET Core CLI
- NuGet CLI
- Package Manager Console
- Visual Studio
Using the .NET Core command-line interface (CLI) tools:
dotnet add package Dojo.Net
Using the NuGet Command Line Interface (CLI):
nuget install Dojo.Net
Using the Package Manager Console:
Install-Package Dojo.Net
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 "Dojo.Net".
- Click on the Dojo.Net package, select the appropriate version in the right-tab and click Install.
Building
In order to build the source code for this SDK, .NET 3.0+ is required:
- Go to the
src
subfolder. - Run:
dotnet build
Usage
Create a PaymentIntentsClient
instance in your .NET application. Initialize this client with an
HttpClient
for managing
HTTP requests and an ApiKeyClientAuthorization
to ensure secure API authentication. Then, you can start
handling payment intents.
Dojo.Net.PaymentIntentsClient client = new PaymentIntentsClient(
new HttpClient(),
new ApiKeyClientAuthorization(apiKey));
Use it as .NET service
To use the Dojo.Net SDK as a .NET service, you need to register it in your .NET project. This will configure the SDK to be
accessible throughout the application. This code sets up client authorization with your API key and adds an HttpClient
for IPaymentIntentsClient
.
builder.Services.AddSingleton<IClientAuthorization>(new ApiKeyClientAuthorization(apiKey));
builder.Services.AddHttpClient<IPaymentIntentsClient, PaymentIntentsClient>();
Automatic retries
The library does not automatically retries requests on intermittent failures like connection errors. We suggest you use the Polly library to set up a retry policy.
This code configures a retry mechanism, allowing the application to automatically retry a failing HTTP request up to three times with increasing delays between retries:
builder.Services
.AddHttpClient<IPaymentIntentsClient, PaymentIntentsClient>()
.AddTransientHttpErrorPolicy(
x => x.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(3, retryAttempt))));
For any requests, bug or comments, please open an issue or submit a pull request.