Giter Site home page Giter Site logo

sdk-ruby's Introduction

MercadoPago SDK module for Payments integration

Install

gem install mercadopago-sdk

Basic checkout

Configure your credentials

require 'mercadopago.rb'

$mp = MercadoPago.new('CLIENT_ID', 'CLIENT_SECRET')

Preferences

Get an existent Checkout preference

preference = $mp.get_preference('PREFERENCE_ID')

puts $preferenceResult

Create a Checkout preference

preference_data = {
			"items": [
				{
					"title": "testCreate", 
					"quantity": 1, 
					"unit_price": 10.2, 
					"currency_id": "ARS"
				}
			]
		}
preference = $mp.create_preference(preference_data)

puts preference

Update an existent Checkout preference

preferenceDataToUpdate = Hash["items" => Array(Array["title"=>"testUpdated", "quantity"=>1, "unit_price"=>2])]

preferenceUpdate = $mp.update_preference("PREFERENCE_ID", preferenceDataToUpdate)

puts preferenceUpdate

Payments/Collections

Search for payments

filters = Array["id"=>null, "external_reference"=>null]

searchResult = $mp.search_payment(filters)

puts searchResult

Get payment data

paymentInfo = $mp.get_payment("ID")

puts paymentInfo

Cancel (only for pending payments)

result = $mp.cancel_payment("ID");

// Show result
puts result

Refund (only for accredited payments)

result = $mp.refund_payment("ID");

// Show result
puts result

Customized checkout

Configure your credentials

require 'mercadopago.rb'

$mp = MercadoPago.new('ACCESS_TOKEN')

Create payment

$mp.post ("/v1/payments", payment_data);

Create customer

$mp.post ("/v1/customers", Hash["email" => "[email protected]"]);

Get customer

$mp.get ("/v1/customers/CUSTOMER_ID");

Generic methods

You can access any other resource from the MercadoPago API using the generic methods:

// Get a resource, with optional URL params. Also you can disable authentication for public APIs
$mp.get ("/resource/uri", [params], [authenticate=true])

// Create a resource with "data" and optional URL params.
$mp.post ("/resource/uri", data, [params])

// Update a resource with "data" and optional URL params.
$mp.put ("/resource/uri", data, [params])

// Delete a resource with optional URL params.
$mp.delete ("/resource/uri", [params])

For example, if you want to get the Sites list (no params and no authentication):

$sites = $mp.get ("/sites", null, false)

puts $sites

sdk-ruby's People

Contributors

hcasatti avatar joelibaceta avatar sebagun avatar matiascompiano avatar chrismo avatar jvillarejo avatar munshkr avatar fpiruzi avatar gnumarcelo avatar marcoschicote avatar ceneon avatar

Watchers

James Cloos 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.