AI resources

Receive payments with cards

Server-Side

Bricks makes it easy to send payment to MercadoPago through the Backend. The data received by Brick in the onSubmit function is exactly what is needed to call the Mercado Pago Payment API.

  1. In the current structure of your integration, find the call to Payments API.
<?php  
    require_once 'vendor/autoload.php';

    MercadoPago\SDK::setAccessToken("ENV_ACCESS_TOKEN");
    //...
    $payment = new MercadoPago\Payment();
    $payment->transaction_amount = 100;
    $payment->token = $token;
    $payment->description = "Blue shirt";
    $payment->installments = $installments;
    $payment->payment_method_id = $payment_method_id;
    $payment->issuer_id = $issuer_id;
    $payment->payer = array(
    "email" => "test_payer@example.com"
    );
    // Guarda y postea el pago
    $payment->save();
    //...
    // Imprime el estado del pago
    echo $payment->status;
    //...
?>
The fields required to send are token, transaction_amount, payment_method_id and the payer.email.
  1. Replace it with the Checkout Bricks integration.

You can find payment status in status value.

<?php
  require_once 'vendor/autoload.php';
  MercadoPago\SDK::setAccessToken("YOUR_ACCESS_TOKEN");
  $payment = new MercadoPago\Payment();
  $payment->transaction_amount = (float)$_POST['transactionAmount'];
  $payment->token = $_POST['token'];
  $payment->installments = (int)$_POST['installments'];
  $payment->payment_method_id = $_POST['paymentMethodId'];
  $payment->issuer_id = (int)$_POST['issuer'];
  $payer = new MercadoPago\Payer();
  $payer->email = $parsed_body['payer']['email'];
  $payer->identification = array(
     "type" => $parsed_body['payer']['identification']['type'],
     "number" => $parsed_body['payer']['identification']['number']
   );
  $payment->payer = $payer;
  $payment->save();
  $response = array(
      'status' => $payment->status,
      'status_detail' => $payment->status_detail,
      'id' => $payment->id
  );
  echo json_encode($response);

?>