- Copy lib/mercadopago.php to your project desired folder.
- Get your CLIENT_ID and CLIENT_SECRET in the following address:
- Argentina: https://www.mercadopago.com/mla/herramientas/aplicaciones
- Brazil: https://www.mercadopago.com/mlb/ferramentas/aplicacoes
- Mexico: https://www.mercadopago.com/mlm/herramientas/aplicaciones
- Venezuela: https://www.mercadopago.com/mlv/herramientas/aplicaciones
- Colombia: https://www.mercadopago.com/mco/herramientas/aplicaciones
require_once ('mercadopago.php');
$mp = new MP ("CLIENT_ID", "CLIENT_SECRET");
require_once ('mercadopago.php');
$mp = new MP ("LL_ACCESS_TOKEN");
$accessToken = $mp->get_access_token();
print_r ($accessToken);
$preference = $mp->get_preference("PREFERENCE_ID");
print_r ($preference);
$preference_data = array (
"items" => array (
array (
"title" => "Test",
"quantity" => 1,
"currency_id" => "USD",
"unit_price" => 10.4
)
)
);
$preference = $mp->create_preference($preference_data);
print_r ($preference);
$preference_data = array (
"items" => array (
array (
"title" => "Test Modified",
"quantity" => 1,
"currency_id" => "USD",
"unit_price" => 20.4
)
)
);
$preference = $mp->update_preference("PREFERENCE_ID", $preference_data);
print_r ($preference);
###Searching:
$filters = array (
"id"=>null,
"site_id"=>null,
"external_reference"=>null
);
$searchResult = $mp->search_payment ($filters);
print_r ($searchResult);
- Go to Mercadopago IPN configuration:
- Argentina: https://www.mercadopago.com/mla/herramientas/notificaciones
- Brasil: https://www.mercadopago.com/mlb/ferramentas/notificacoes
- Mexico: https://www.mercadopago.com/mlm/herramientas/notificaciones
- Venezuela: https://www.mercadopago.com/mlv/herramientas/notificaciones
- Colombia: https://www.mercadopago.com/mco/herramientas/notificaciones
require_once ('mercadopago.php');
header("Content-type: text/plain");
$mp = new MP ("CLIENT_ID", "CLIENT_SECRET");
$paymentInfo = $mp->get_payment_info ($_GET["id"]);
header ("", true, $paymentInfo["status"]);
print_r ($paymentInfo);
$result = $mp->cancel_payment($_GET["ID"]);
// Show result
print_r ($result);
$result = $mp->refund_payment($_GET["ID"]);
// Show result
print_r ($result);
You can access any other resource from the MercadoPago API using the generic methods:
// Get a resource, with optional URL params. Also you can disable authentication for public APIs
$mp->get ("/resource/uri", [params], [authenticate=true]);
// Create a resource with "data" and optional URL params.
$mp->post ("/resource/uri", data, [params]);
// Update a resource with "data" and optional URL params.
$mp->put ("/resource/uri", data, [params]);
// Delete a resource with optional URL params.
$mp->delete ("/resource/uri", [params]);
For example, if you want to get the Sites list (no params and no authentication):
$sites = $mp->get ("/sites", null, false);
print_r ($sites);