Ir a la tienda Scriptcase

Mercado Pago

This API is available for use in the following countries:

API available for use in some countries

It is also necessary to check the payment methods available in each country, check the updated list on the Mercado Pago website.

To use this API, you need a Mercado Pago account. Access Mercado Pago to log in or create an account if you don’t already have one.

Setting up a Profile

En el menú Herramientas > API, puede crear perfiles de API para utilizarlos en sus proyectos. De esta forma, solo tendrá que informar sus credenciales una vez para usar la API en su proyecto.

Vea cómo obtener las credenciales necesarias para configurar el perfil.

Al realizar el deploy de su proyecto, deberá configurar las credenciales de la API en Prod, accediendo al menú API.

Payment configuration using Mercado Pago API

To create the profile, we must add the following information:

Nombre

Define el nombre para identificar el perfil de la API. Este nombre es único y se utilizará para referenciar el perfil de la API en las aplicaciones de su proyecto.

Mode

El modo define la disponibilidad del Perfil en Scriptcase.

  • Público - Los usuarios de todos los proyectos podrán visualizar y utilizar el perfil creado.

  • Proyecto - Los usuarios podrán visualizar y utilizar el perfil en el proyecto donde fue configurado.

  • Usuario - Solo el usuario que creó el perfil podrá visualizarlo y utilizarlo en las aplicaciones.

Independientemente del modo utilizado para la creación, los perfiles solo pueden ser editados por usuarios con acceso de administrador en el proyecto. Vea cómo definir los niveles de acceso de los usuarios en Scriptcase.

Gateway

Define la API que se utilizará para crear el perfil.

Auth Token

Enter the Access Token generated in the Mercado Pago settings. If you do not have this information, see our article on how to obtain Mercado Pago credentials.

Usage Example

It is possible to offer payment by Card, PIX, Mercado Pago Wallet, bank slip and payment at lottery outlets

See below some examples of using the API with PIX and Bank Slip

Example of payment via PIX

For payments using PIX, it is necessary that the keys are registered with Mercado Pago. See how to register your PIX key with Mercado Pago.

// Calling the API directly in the macro.

$token = 'public_token';

$settings = array('settings' => ['gateway' => 'mercadopago', 'token' => $token] );

$payment = sc_call_api('', $settings);

// Passing the values ​​to the methods: values, description, and payment type.

$payment->transaction_amount = 0.01;

$payment->description = "test";

$payment->payment_method_id = "pix";

// Passing the customer information.

// The "type" parameter can be the email or the CPF (Brazilian tax identification number).

// "type" => "CPF"
// "type" => "email"
// The email, first_name, and last_name parameters cannot be the same as the account administrator's.

$payment->payer = array(
"email" => "contato@scriptcase.com.br",
"first_name" => "Netmake",
"last_name" => "Scriptcase",
"identification" => array(

"type" => "email",
"number" => "contato@scriptcase.com.br"

),
"address"=> array(

"zip_code" => "",
"street_name" => "Av. dos Lusíadas, 23",

"street_number" => "",
"neighborhood" => "",
"city" => "São Paulo" ,

"federal_unit" => "SP"

)
);

//Call to execute the payment method.

$payment->save();

API Response

The response will show the pending payment status and all the information you need to show the buyer.

The transaction_data value will return the data for the QR code.

For more information, access the Mercado Pago documentation for PIX payment integration.

See below for an example of the response.

//ID is the code transaction.
"id": 5466310457,
"status": "pending",
"status_detail": "pending_waiting_transfer",
...,
"transaction_details": {
    "net_received_amount": 0,
    "total_paid_amount": 100,
    "overpaid_amount": 0,
    "external_resource_url": null,
    "installment_amount": 0,
    "financial_institution": null
},
"point_of_interaction": {
    "type": "PIX",
    "sub_type": null,
    "application_data": {
    "name": "NAME_SDK",
    "version": "VERSION_NUMBER"
    },
    "transaction_data": {
    "qr_code_base64": "iVBORw0KGgoAAAANSUhEUgAABRQAAAUUCAYAAACu5p7oAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAIABJREFUeJzs2luO3LiWQNFmI+Y/Zd6vRt36KGNXi7ZOBtcagHD4kNLeiLX33v8DAAAAABD879sDAAAAAAA/h6AIAAAAAGSCIgAAAACQCYoAAAAAQCYoAgAAAACZoAgAAAAAZIIiAAAAAJAJigAAAABAJigCAAAAAJmgCAAAAABkgiIAAAAAkAmKAAAAAEAmKAIAAAAAmaAIAAAAAGSCIgAAAACQCYoAAAAAQCYoAgAAAACZoAgAAAAAZIIiAAAAAJAJigAAAABAJigCA...",
    "qr_code": "00020126600014br.gov.bcb.pix0117john@yourdomain.com0217additional data520400005303986540510.005802BR5913Maria Silva6008Brasilia62070503***6304E2CA",
    "ticket_url": "https://www.mercadopago.com.br/payments/1234544589/ticket?caller_id=123456&hash=123e4567-e89b-12d3-a456-426655440000"

Example of Payment by Boleto (bank slip)

// Chamada da Macro utilizando perfil da API
$payment = sc_call_api('mercadpago');

// Passando os valores para os métodos: valores, descrição e o tipo de pagamento.
$payment->transaction_amount = 100;
$payment->description = "Título do produto";


// Tipo de pagamento para ser usado.
// Pagamento por boleto = $payment->payment_method_id = "bolbradesco";
// Pagamento em lotérica = $payment->payment_method_id = "pec";
$payment->payment_method_id = "bolbradesco";

// Passando as informações do cliente.
// O parâmetro  “type” pode ser o email ou o cpf.
// "type" => "CPF"
// "type" => "email"
// Os parâmetros email, first_name e last_name não podem ser os mesmos do administrador da conta.
" $payment->payer = array(
     "email" => "test@test.com",
     "first_name" => "Test",
     "last_name" => "User",
     "identification" => array(
         "type" => "CPF",
         "number" => "19119119100"
      ),
     "address"=>  array(
         "zip_code" => "06233200",
         "street_name" => "Av. das Nações Unidas",
         "street_number" => "3003",
         "neighborhood" => "Bonfim",
         "city" => "Osasco",
         "federal_unit" => "SP"
      )
   );"

// Chamada da execução do método de pagamento.
$payment->save();


// Retornando a URL gerada e abrindo diretamente na aplicação. 
$page = $payment->transaction_details->external_resource_url;
header("Location: $page");

API Response

The response will show the pending status until the buyer makes the payment.

Additionally, in the response to the request, the external_resource_url parameter will return a URL containing instructions for the buyer to make the payment.

You can redirect them to this same link to complete the payment flow.

For more information, access the Mercado Pago documentation for integration of payments via boleto.

See below an example of the response.

// ID é código da transação.
"id": 5466310457,
    "status": "pending",
    "status_detail": "pending_waiting_payment",
    ...,
    "transaction_details": {
        "net_received_amount": 0,
        "total_paid_amount": 100,
        "overpaid_amount": 0,
        "external_resource_url": "https://www.mercadopago.com/mlb/payments/ticket/helper?payment_id=123456789&payment_method_reference_id= 123456789&caller_id=123456",
        "installment_amount": 0,
        "financial_institution": null,
        "payment_method_reference_id": "1234567890"
    }