.NET

Introduction

The Mangopay .NET SDK makes working with the Mangopay API easier in a .NET environment.

The SDK package is available on NuGet: mangopay4-net-sdk

Caution – Use only the mangopay4 package (late Nov 2025)

Please ensure you use only the package with mangopay4 in the name (this is the package name and has no connection with the SDK version number).

Any other package must not be used. You need to update your package manually.

Since November 25, 2025, Mangopay’s official SDKs are no longer accessible on GitHub (with the exception of PHP for publication reasons).

Prerequisites

To run the Mangopay .NET SDK, you’ll need:

  • A ClientId and an API key – if you don’t have these, contact Sales to get access to the Mangopay Dashboard
  • .NET Standard 2.0 or .NET 6.0
  • Common.Logging library (version 3.4.1 or higher)
  • Newtonsoft.Json (version 13.0.1 or higher)
  • RestSharp (version 107.3.0 or higher)
  • NETStandard.Library (version 2.0.3 or higher)

Getting started

1. Install the Mangopay package

Installation from the .NET Package Manager Console

$NuGet\Install-Package mangopay4-net-sdk

Installation with the .NET CLI

$dotnet add package mangopay4-net-sdk

2. Initialize and configure the SDK

1using MangoPay.SDK;
2using MangoPay.SDK.Entities;
3using System.Reflection;
4
5class Program {
6 static void Main(string[] args)
7 {
8 MangoPayApi api = new MangoPayApi();
9
10 api.Config.ClientId = "your-client-id";
11 api.Config.ClientPassword = "your-api-key";
12
13 ...
14
15 }
16}

The configuration object of the SDK supports all the following properties:

KeyTypeDefault valueDescription
ClientIdstringnullYour Mangopay ClientId – can be found in the Dashboard.
ClientPasswordstringnullYour Mangopay API key – can be found in the Dashboard.
BaseUrlstringhttps://api.sandbox.mangopay.com/v2.01/The API sandbox URL. Set to the sandbox environment by default. To enable production environment, set it to https://api.mangopay.com
Timeoutinteger0Time to wait in milliseconds while trying to establish a connection before terminating the attempt and generating an error.
LoggerFactoryAdapterILoggerFactoryAdapterNoOpLoggerFactoryAdapter()Logger adapter implementation. Disabled by default.

SDK usage

In the Mangopay documentation, you’ll find detailed information of all endpoints paired with its corresponding .NET SDK method implementation example. Be sure to customize the provided code to suit your specific requirements.

Idempotency support

To make a request with idempotency support, add idempotencyKey parameter to your function.

For more information, see the Idempotency article.

Call - Create user with idempotency key
1using MangoPay.SDK;
2using MangoPay.SDK.Core.Enumerations;
3using MangoPay.SDK.Entities;
4using MangoPay.SDK.Entities.POST;
5using System.Reflection;
6
7class CreateUser
8{
9 static async Task Main(string[] args)
10 {
11 MangoPayApi api = new MangoPayApi();
12
13 api.Config.ClientId = "your-client-id";
14 api.Config.ClientPassword = "your-api-key";
15
16 var myUser = new UserNaturalOwnerPostDTO
17 {
18 Tag = "Created using the Mangopay .NET SDK",
19 Email = "alice.smith@example.com",
20 FirstName = "Alice",
21 LastName = "Smith",
22 Address = new Address
23 {
24 AddressLine1 = "17 Rue de la République",
25 City = "Paris",
26 PostalCode = "75001",
27 Country = CountryIso.FR
28 },
29 Birthday = new DateTime(1985, 3, 15),
30 Nationality = CountryIso.FR,
31 CountryOfResidence = CountryIso.FR
32 };
33
34 var idempotencyKey = "pk7urhkW55KpTHf44567-d";
35
36 var createNaturalUser = await api.Users.CreateOwnerAsync(myUser, idempotencyKey);
37
38 foreach (PropertyInfo prop in createNaturalUser.GetType().GetProperties())
39 {
40 var propValue = prop.GetValue(createNaturalUser);
41 if (propValue != null)
42 {
43 Console.Write($"{prop.Name}: ");
44
45 if (prop.Name == "Address")
46 {
47 var address = propValue as Address;
48 if (address != null)
49 {
50 Console.WriteLine($"{address.AddressLine1}, {address.AddressLine2}, {address.City}, {address.PostalCode}, {address.Country}");
51 }
52 }
53 else
54 {
55 Console.WriteLine(propValue);
56 }
57 }
58 }
59 }
60}

In order to retrieve the request made using the idempotency key:

Call - View API Response
1using MangoPay.SDK;
2using System.Reflection;
3
4class ViewResponse
5{
6 static async Task Main(string[] args)
7 {
8 MangoPayApi api = new MangoPayApi();
9
10 api.Config.ClientId = "your-client-id";
11 api.Config.ClientPassword = "your-api-key";
12
13 var idempotencyKey = "pk7urhkW55KpTHf44567-d";
14
15 var result = await api.Idempotent.GetAsync(idempotencyKey);
16
17 foreach (PropertyInfo prop in result.GetType().GetProperties())
18 {
19 var propValue = prop.GetValue(result);
20 if (propValue != null)
21 {
22 Console.Write($"{prop.Name}: ");
23 Console.WriteLine(propValue);
24 }
25 }
26 }
27}
Output
1StatusCode: 200
2ContentLength: 717
3ContentType: application/json; charset=utf-8
4Date: Fri, 22 Mar 2024 14:13:38 GMT
5RequestURL: https://api.sandbox.mangopay.com/v2.01/your-client-id/users/natural
6Resource: MangoPay.SDK.Entities.GET.UserNaturalDTO
7CreationDate: 1/1/0001 12:00:00 AM

Pagination

For endpoints that support pagination, you can use the Pagination object. 

In the object, you need to specify the page and items per page to return.

As a result, the answer will be paginated, and the total number of items and the total number of pages will be provided.

For example, with the GET List all Users endpoint :

1using MangoPay.SDK;
2using MangoPay.SDK.Entities;
3using System.Reflection;
4
5class ListAllUsers {
6 static async Task Main(string[] args)
7 {
8 MangoPayApi api = new MangoPayApi();
9
10 api.Config.ClientId = "your-client-id";
11 api.Config.ClientPassword = "your-api-key";
12
13 var myUsers = await api.Users.GetAllAsync(new Pagination(1, 100));
14
15 foreach (var user in myUsers)
16 {
17 foreach (PropertyInfo prop in user.GetType().GetProperties())
18 {
19 var propValue = prop.GetValue(user);
20 if (propValue != null)
21 {
22 Console.Write($"{prop.Name}: ");
23 Console.WriteLine(propValue);
24 }
25 }
26 Console.WriteLine();
27 }
28 }
29}

Rate limiting status

Rate limiting in Mangopay restricts the frequency of API requests a client can make over a defined period, automatically updating the limit with each request and blocking additional requests if the limit is exceeded until it resets. For more information, see the rate limiting article.

Call - View a user
1using MangoPay.SDK;
2using MangoPay.SDK.Entities;
3using RestSharp;
4using System.Reflection;
5
6class ViewUser
7{
8 static async Task Main(string[] args)
9 {
10 MangoPayApi api = new MangoPayApi();
11
12 api.Config.ClientId = "your-client-id";
13 api.Config.ClientPassword = "your-api-key";
14
15 var myUser = await api.Users.GetNaturalAsync("user_m_01HRCAJT98VPWE4DHBTC8N8KA0");
16 var response = await Task.Run(() => api.LastRequestInfo);
17
18 Console.WriteLine($"Method: {response.Request.Method}");
19 Console.WriteLine($"Resource: {response.Request.Resource}");
20 Console.WriteLine("Headers:");
21 foreach (var header in response.Request.Parameters.Where(p => p.Type == ParameterType.HttpHeader))
22 {
23 Console.WriteLine($"{header.Name}: {header.Value}");
24 }
25 var requestBody = response.Request.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody)?.Value;
26 if (!string.IsNullOrEmpty((string?)requestBody))
27 {
28 Console.WriteLine($"Body: {requestBody}");
29 }
30
31 // Display Response details
32 Console.WriteLine("\nResponse Details:");
33 Console.WriteLine($"Response type: {response.Response.GetType().FullName}");
34 foreach (PropertyInfo prop in response.GetType().GetProperties())
35 {
36 var propValue = prop.GetValue(response);
37 Console.Write($"{prop.Name}: ");
38 Console.WriteLine(propValue);
39 }
40
41 foreach (PropertyInfo prop in myUser.GetType().GetProperties())
42 {
43 var propValue = prop.GetValue(myUser);
44 if (propValue != null)
45 {
46 Console.Write($"{prop.Name}: ");
47
48 if (prop.Name == "Address")
49 {
50 var address = propValue as Address;
51 if (address != null)
52 {
53 Console.WriteLine($"{address.AddressLine1}, {address.AddressLine2}, {address.City}, {address.PostalCode}, {address.Country}");
54 }
55 }
56 else
57 {
58 Console.WriteLine(propValue);
59 }
60 }
61 }
62 }
63}
Output
1Method: Get
2Resource: /v2.01/your-client-id/users/natural/user_m_01HRCAJT98VPWE4DHBTC8N8KA0
3Headers:
4User-Agent: MangoPay V2 SDK .NET 3.16.0.0
5Authorization: bearer f8cc4ce612524a11afac04abbf0798d6
6
7Response Details:
8Response type: RestSharp.RestResponse`1[[MangoPay.SDK.Entities.GET.UserNaturalDTO, MangoPay.SDK, Version=3.16.0.0, Culture=neutral, PublicKeyToken=null]]
9Request: RestSharp.RestRequest
10Response: RestSharp.RestResponse`1[MangoPay.SDK.Entities.GET.UserNaturalDTO]
11RateLimitingCallsAllowed:
12RateLimitingCallsRemaining: 2294
13RateLimitingTimeTillReset: 1711642500
14FirstName: Alice
15LastName: Smith
16Address: 17 Rue de la République, , Paris, 75001, FR
17Birthday: 3/15/1985 12:00:00 AM
18Nationality: FR
19CountryOfResidence: FR
20TermsAndConditionsAccepted: False
21UserCategory: OWNER
22PersonType: NATURAL
23Email: alice.smith@example.com
24KYCLevel: LIGHT
25Id: user_m_01HRCAJT98VPWE4DHBTC8N8KA0
26Tag: Created using the Mangopay .NET SDK
27CreationDate: 3/7/2024 11:25:39 AM

Unit tests

All unit tests are placed under the MangoPay.SDK.Tests directory.

Error handling

The SDK provides the ResponseException class to wrap HTTP errors returned by the API. You can use a standard try-catch block to target the class and add your custom logic, for example:

1try
2{
3 await this.Api.Wallets.GetAsync(wallet.Id, "USER_PRESENT");
4}
5catch (ResponseException ex)
6{
7 // use ex details for custom logic
8}