Build Status:
This is an unofficial version of the MercadoPago SDK for .NET.
It has several improvements currently not present in the official version:
- .NET Standard 2.0 support
- Bug fixes
- Per-request Access-Token
- Cleaner API surface
- LINQ Provider
- A Simpler, cleaner and safer IPN Notification Handler
- Before-request Data Validations
- Improved error handling
- Async support (.NET Standard / .NET Core only)
- .NET Standard 2.0 and all platforms that support it (.NET Core, Mono, Xamarin, Unity, etc)
- .NET Framework 4.0 and above on Windows platforms
- Legacy 1.x versions of the SDK support .NET Framework 3.5
Install Nuget Package Lexim.MercadoPago.Sdk using your favorite package manager.
using MercadoPago;
For Web-checkout:
MercadoPago.SDK.ClientId = "YOUR_CLIENT_ID";
MercadoPago.SDK.ClientSecret = "YOUR_CLIENT_SECRET";
For API or custom checkout:
MercadoPago.SDK.AccessToken = "YOUR_ACCESS_TOKEN";
Tip: You can obtain your MercadoPago credentials here
using System.Diagnostics;
using MercadoPago.Common;
using MercadoPago.DataStructures.Preference;
using MercadoPago.Resources;
// Remember to set your MercadoPago credentials! (see step 2)
// Create a preference object
var preference = new Preference
{
Items =
{
new Item
{
Id = "1234",
Title = "Small Silk Plate",
Quantity = 5,
CurrencyId = CurrencyId.ARS,
UnitPrice = 44.23m
}
},
Payer = new Payer
{
Email = "[email protected]"
}
};
// save to MercadoPago
preference.Save();
// the InitPoint property contains the URL of the web checkout screen for this preference
Process.Start(preference.InitPoint);
You can find more examples in the
MercadoPagoSDK.Samples
folder.
There are 3 kinds of errors that you may get when interacting with this SDK:
-
All Non-successful HTTP responses from the MercadoPago API will result in an exception.
-
HTTP responses in the range 400-500 will result in an exception with an
Error
property, with the following structure: -
Before-request Validation errors will result in an exception with a clear, detailed message about the relevant resource and property.
See the Handling Exceptions Example for details.
Use the issues tab if you have any questions or find bugs.