/sdk-php

MercadoPago PHP SDK

Primary LanguagePHP

MercadoPago SDK module for Payments integration

Usage:

  1. Copy lib/mercadopago.php to your project desired folder.

...with your credentials:

require_once ('mercadopago.php');

$mp = new MP ("CLIENT_ID", "CLIENT_SECRET");

...with your long live access token:

require_once ('mercadopago.php');

$mp = new MP ("LL_ACCESS_TOKEN");

Get your Access Token:

$accessToken = $mp->get_access_token();

print_r ($accessToken);

Using MercadoPago Checkout

Get an existent Checkout preference:

$preference = $mp->get_preference("PREFERENCE_ID");

print_r ($preference);

Create a Checkout 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);

Others items to use

Update an existent Checkout 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);

Using MercadoPago Payment

###Searching:

$filters = array (
        "id"=>null,
        "site_id"=>null,
        "external_reference"=>null
    );

$searchResult = $mp->search_payment ($filters);

print_r ($searchResult);

More search examples

Receiving IPN notification:

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);

Cancel (only for pending payments):

$result = $mp->cancel_payment($_GET["ID"]);

// Show result
print_r ($result);

Refund (only for accredited payments):

$result = $mp->refund_payment($_GET["ID"]);

// Show result
print_r ($result);

About Cancel & Refund

Generic resources methods

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);