Skip to content

nicoriff/Lexim-MercadoPago-Sdk

 
 

Repository files navigation

Unofficial Mercado Pago SDK for .NET

Build Status:

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 versions supported:

  • .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

Installation

Install Nuget Package Lexim.MercadoPago.Sdk using your favorite package manager.

Quick Start

1. Import the Mercado Pago SDK.

using MercadoPago;

2. Setup your credentials

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

3. Creating a Preference for Web (a.k.a "basic") checkout

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 = "augustus_mckenzie@gmail.com"
    }
};

// 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.

4. Handling Errors

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:

    errorstructure

  • 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.

Support

Use the issues tab if you have any questions or find bugs.

About

Unofficial Mercado Pago SDK for .NET

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.0%
  • PowerShell 1.0%