The official Mercado Pago .NET SDK.
.NET Standard 2.1+, .NET Core 2.0+, and .NET Framework 6.0+.
If you are using previous versions of .NET Framework in your project, please refer to the older versions of the SDK.
Use one of the following options, depending on your preferred environment.
- 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 "mercadopago-sdk". - Click on the
mercadopago-sdk
package, select the appropriate version and click Install.
Using the Package Manager
Install-Package mercadopago-sdk
dotnet add package mercadopago-sdk
Using the NuGet Command Line Interface (CLI)
nuget install mercadopago-sdk
First time using Mercado Pago? Create your Mercado Pago account.
Copy your Access Token
in the credentials panel and replace the text YOUR_ACCESS_TOKEN
with it.
To generate a card token
read the Checkout API documentation.
using System;
using System.Threading.Tasks;
using MercadoPago.Client.Payment;
using MercadoPago.Config;
using MercadoPago.Resource.Payment;
MercadoPagoConfig.AccessToken = "YOUR_ACCESS_TOKEN";
var request = new PaymentCreateRequest
{
TransactionAmount = 10,
Token = "CARD_TOKEN",
Description = "Payment description",
Installments = 1,
PaymentMethodId = "visa",
Payer = new PaymentPayerRequest
{
Email = "test.payer@email.com",
}
};
var client = new PaymentClient();
Payment payment = await client.CreateAsync(request);
Console.WriteLine($"Payment ID: {payment.Id}");
All methods that make API calls accept an optional RequestOptions
object. This can be used to configure some special options of the request, such as changing credentials or custom headers.
using MercadoPago.Client;
using MercadoPago.Http;
var requestOptions = new RequestOptions();
requestOptions.AccessToken = "YOUR_ACCESS_TOKEN";
requestOptions.CustomHeaders.Add(Headers.IDEMPOTENCY_KEY, "YOUR_IDEMPOTENCY_KEY");
// ...
var client = new PaymentClient();
Payment payment = await client.CreateAsync(request, requestOptions);
using System.Net;
using System.Net.Http;
using MercadoPago.Config;
using MercadoPago.Http;
var handler = new HttpClientHandler
{
Proxy = new WebProxy(proxyUrl),
UseProxy = true,
};
var httpClient = new HttpClient(handler);
MercadoPagoConfig.HttpClient = new DefaultHttpClient(httpClient);
The SDK automatically retries requests on intermittent failures. The default max number of attempts is 2.
using MercadoPago.Config;
using MercadoPago.Http;
var retryStrategy = new DefaultRetryStrategy(5);
MercadoPagoConfig.RetryStrategy = retryStrategy;
Visit our Developer Site for further information regarding:
Check our SDK docs to explore all available functionalities.
All contributions are welcome, ranging from people wanting to triage issues, others wanting to write documentation, to people wanting to contribute code.
Please read and follow our contribution guidelines. Contributions not following this guidelines will be disregarded. The guidelines are in place to make all of our lives easier and make contribution a consistent process for everyone.
If you require technical support, please contact our support team at developers.mercadopago.com.
MIT license. Copyright (c) 2021 - Mercado Pago / Mercado Libre
For more information, see the LICENSE file.