Downloads
Stars
Version
This library provides developers with a simple set of bindings to help you integrate Mercado Pago API to a website and start receiving payments.
PHP 7.1, 8.0 y 8.1 or higher
First time using Mercado Pago? Create your Mercado Pago account, if you donβt have one already.
Download Composer if not already installed
On your project directory run on the command line
composer require leonardcodep/mercadopago-sdk-php
Copy the access_token in the credentials section of the page and replace YOUR_ACCESS_TOKEN with it.
That's it! Mercado Pago SDK has been successfully installed.
Simple usage looks like:
<?php
require_once 'vendor/autoload.php'; // You have to require the library from your Composer vendor folder
use MercadoPago\SDK;
use MercadoPago\Entity\Shared\Payment;
use MercadoPago\Entity\Shared\Payer;
try {
SDK::setAccessToken("YOUR_ACCESS_TOKEN"); // Either Production or SandBox AccessToken
$payment = new Payment();
$payment->transaction_amount = 259;
$payment->token = $request->token;
$payment->description = "Compra de productos";
$payment->installments = (int) $request->installments;
$payment->payment_method_id = $request->payment_method_id;
$payment->issuer_id = (int) $request->issuer_id;
$payer = new Payer();
$payerForm = $request->payer;
$payer->email = $payerForm['email'];
$payer->identification = array(
"type" => $payerForm['identification']['type'],
"number" => $payerForm['identification']['number']
);
$payment->payer = $payer;
$payment->save();
if($payment->id === null) {
$error_message = 'Unknown error cause';
if(isset($payment->error)) {
$error_message = $payment->error->message;
}
throw new Exception($error_message);
}
$response = array(
"request" => $request,
"payment_id" => $payment->id,
"status" => $payment->status,
"status_detail" => $payment->status_detail,
);
} catch (Exception $e) {
throw new Exception(trim(trim($e->getMessage()), '"'));
}
?>
Visit our Dev Site for further information regarding:
Check our official code reference to explore all available functionalities.
If you require technical support, please contact our support team at developers.mercadopago.com