Authorization and capture

Prerequisites

Available only in:

  • Argentina (Visa, Mastercard, American Express, Naranja, Cencosud, Cabal, Diners, Argencard and Tarjeta Shopping)
  • Brazil
  • Peru

Mercado Pago offers the possibility of performing an authorization hold before generating a capture.

The authorization hold freezes the money on your buyer’s card. This means that when you perform it you have not charged your customer’s card yet. The customer will see the payment only when a capture is made.

Perform an authorization hold

Performing an authorization hold is like making a payment, but adding the capture=false attribute:

<?php  

  MercadoPago\SDK::setAccessToken("ENV_ACCESS_TOKEN");

  $payment = new MercadoPago\Payment();

  $payment->transaction_amount = 100;
  $payment->token = "ff8080814c11e237014c1ff593b57b4d";
  $payment->description = "Title of what you are paying for";
  $payment->installments = 1;
  $payment->payment_method_id = "visa";
  $payment->payer = array(
    "email" => "test_user_19653727@testuser.com"
  );

  $payment->capture=false;

  $payment->save();

?>
import com.mercadopago.*;
MercadoPago.SDK.configure("ENV_ACCESS_TOKEN");

Payment payment = new Payment();

payment.setTransactionAmount(100)
      .setToken('ff8080814c11e237014c1ff593b57b4d')
      .setDescription('Title of what you are paying for')
      .setInstallments(1)
      .setPaymentMethodId("visa")
      .setPayer(new Payer("test_user_19653727@testuser.com"))
      .setCapture(false);

payment.save();

var mercadopago = require('mercadopago');
mercadopago.configurations.setAccessToken(config.access_token);

var payment_data = {
  transaction_amount: 100,
  token: 'ff8080814c11e237014c1ff593b57b4d'
  description: 'Title of what you are paying for',
  installments: 1,
  payment_method_id: 'visa',
  payer: {
    email: 'test_user_3931694@testuser.com'
  },
  capture: false
};

mercadopago.payment.create(payment_data).then(function (data) {
  // Do Stuff...
}).catch(function (error) {
  // Do Stuff...
});

require 'mercadopago'
MercadoPago::SDK.configure(ACCESS_TOKEN: ENV_ACCESS_TOKEN)

payment = MercadoPago::Payment.new()
payment.transaction_amount = 100
payment.token = 'ff8080814c11e237014c1ff593b57b4d'
payment.description = 'Title of what you are paying for'
payment.installments = 1
payment.payment_method_id = "visa"
payment.payer = {
  email: "test_user_19653727@testuser.com"
}
payment.capture = false
payment.save()

Response:

Json

{
  "id": PAYMENT_ID,
  ...
  "status": "authorized",
  "status_detail": "pending_capture",
  ...
  "captured": false,
  ...
}

The response indicates that the payment is authorized and pending capture.

Keep in mind that the money is frozen in the buyer’s card until you decide to capture it, so we recommend that you capture it as soon as possible.

Consideraciones

  • The authorization hold is valid for 5 days. If you do not capture it until that date, it will be cancelled.
  • The authorization may also be rejected or remain pending, just like any other regular payment.

Capture a payment

To be able to charge your customer, you need to capture the money you have held.

It is possible to capture the total amount or part of it.

Capturing the total amount of an authorization hold

To capture the total amount, all you should do is send the capture attribute in true in a HTTP PUT request.

<?php

  MercadoPago\SDK::setAccessToken("ENV_ACCESS_TOKEN");

  $payment = MercadoPago\Payment::find_by_id($payment_id);
  $payment->capture = true;
  $payment->update();

?>
import com.mercadopago.*;
MercadoPago.SDK.configure("ENV_ACCESS_TOKEN");


Payment payment = Payment.load(paymentId);
payment.capture = true;
payment.update();


var mercadopago = require('mercadopago');
mercadopago.configurations.setAccessToken(config.access_token);


require 'mercadopago'
MercadoPago::SDK.configure(ACCESS_TOKEN: ENV_ACCESS_TOKEN)

payment = MercadoPago::Payment.load(paymentId)
payment.capture=true
payment.update()

The request will update the status approved with a status_detail=accredited:

Json

{
  ...
  "status": "approved",
  "status_detail": "accredited",
  ...
  "captured": true,
  ...
}

Whenever you do not specify an amount, the total amount will be captured.

Note

If the authorization hold was successful, the capture operation will always be successful as well.

Capture an amount lower than what was held

In Argentina, it is only available for Visa, Cabal, Master and American Express

If you decide to capture an amount lower than what was held, in addition to sending the capture attribute, you will also need to send the transaction_amount attribute with the new amount.

<?php

  MercadoPago\SDK::setAccessToken("ENV_ACCESS_TOKEN");

  $payment = MercadoPago\Payment::find_by_id($payment_id);
  $payment->transaction_amount = 75;
  $payment->capture = true;
  $payment->update();

?>
import com.mercadopago.*;
MercadoPago.SDK.configure("ENV_ACCESS_TOKEN");


Payment payment = Payment.load(paymentId);
payment.transaction_amount = 75;
payment.capture = true;
payment.update();


var mercadopago = require('mercadopago');
mercadopago.configurations.setAccessToken(config.access_token);


require 'mercadopago'
MercadoPago::SDK.configure(ACCESS_TOKEN: ENV_ACCESS_TOKEN)

payment = MercadoPago::Payment.load(paymentId)
payment.transaction_amount = 75
payment.capture=true
payment.update()

Response:

Json

{
  ...
  "status": "approved",
  "status_detail": "accredited",
  ...
  "transaction_amount": 75,
  ...
  "captured": true,
  ...
}

Note

It is not possible to capture an amount larger than what was held. In order to do this, you need to cancel the authorization hold and perform a new one.

Cancel an authorization hold

If you will not capture the payment, you must cancel the authorization hold so that the frozen money is restored to the card.

To do this, you must update the attribute status of the payment to a cancelled status:

<?php

  MercadoPago\SDK::setAccessToken("ENV_ACCESS_TOKEN");

  $payment = MercadoPago\Payment::find_by_id($payment_id);
  $payment->status = "cancelled";
  $payment->update();

?>
import com.mercadopago.*;
MercadoPago.SDK.configure("ENV_ACCESS_TOKEN");


Payment payment = Payment.load(paymentId);
payment.status = "canceled";
payment.update();


var mercadopago = require('mercadopago');
mercadopago.configurations.setAccessToken(config.access_token);


require 'mercadopago'
MercadoPago::SDK.configure(ACCESS_TOKEN: ENV_ACCESS_TOKEN)

payment = MercadoPago::Payment.load(paymentId)
payment.status = "canceled"
payment.update()

Respuesta:

Json

{
  ...
  "status": "cancelled",
  "status_detail": "by_collector",
  ...
  "captured": false,
  ...
}

Note

Authorizations that have not been captured within the specified period will be automatically cancelled. You will be notified via Webhooks of the payment status change.

La búsqueda no arrojó ningún resultado.

Verifica la la ortografía de los términos de búsqueda o prueba con otras palabras clave.