Giter Club home page Giter Club logo

lexim-mercadopago-sdk's Introduction

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 = "[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.

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.

lexim-mercadopago-sdk's People

Contributors

dotfede avatar gdzachary avatar joelibaceta avatar delias-silva avatar hdlopez avatar mminestrelli avatar agustinfrancesconi avatar pachae avatar gzacharyktz avatar gustavohennig avatar janee avatar matiasgualino avatar

Watchers

José Luis Orihuela Conde avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.