This library provides developers with a simple set of bindings to help you integrate Mercado Pago API to a website and start receiving payments.
Ruby version 2.3 or greater.
Run gem 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.
require 'mercadopago'
sdk = Mercadopago::SDK.new('YOUR_ACCESS_TOKEN')
custom_headers = {
'x-idempotency-key': '<SOME_UNIQUE_VALUE>'
}
custom_request_options = Mercadopago::RequestOptions.new(custom_headers: custom_headers)
payment_data = {
transaction_amount: 100,
token: 'CARD_TOKEN',
description: 'Payment description',
payment_method_id: 'visa',
installments: 1,
payer: {
email: 'test_user_123456@testuser.com'
}
}
result = sdk.payment.create(payment_data, custom_request_options)
payment = result[:response]
puts payment
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.
require 'mercadopago'
request_options = Mercadopago::RequestOptions.new(access_token: 'YOUR_ACCESS_TOKEN')
# ...
result = sdk.payment.create(payment_data, request_options: request_options)
payment = result[:response]
Visit our Dev Site for further information regarding:
Check our official code reference 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.