Skip to main content

.NET

Learn how to work with Dojo's .NET SDK for the Payments API.

NuGet

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.

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

      dotnet add package Dojo.Net

Building

In order to build the source code for this SDK, .NET 3.0+ is required:

  1. Go to the src subfolder.
  2. 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.