PHP code example of fedeisas / mercadopago-sdk-php

1. Go to this page and download the library: Download fedeisas/mercadopago-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fedeisas / mercadopago-sdk-php example snippets


use MercadoPago\MercadoPago;
use MercadoPago\Http\GuzzleClient;

$mp = new MercadoPago(new GuzzleClient());
$mp->setCredentials('CLIENT_ID', 'CLIENT_SECRET');

$preference = $mp->getPreference('PREFERENCE_ID');

var_dump($preference);

$preference_data = [
    'items' => [
        [
            'title' => 'Test',
            'quantity' => 1,
            'currency_id' => 'USD',
            'unit_price' => 10.4,
        ]
    ]
];

$preference = $mp->createPreference($preference_data);

var_dump($preference);

$preference_data = [
    'items' => [
        [
            'title' => 'Test Modified',
            'quantity' => 1,
            'currency_id' => 'USD',
            'unit_price' => 20.4,
        ]
    ]
];

$preference = $mp->updatePreference('PREFERENCE_ID', $preference_data);

var_dump($preference);

$filters = [
    'id' => null,
    'site_id' => null,
    'external_reference' => null,
];

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

var_dump($searchResult);

use MercadoPago\MercadoPago;
use MercadoPago\Http\GuzzleClient;

$mp = new MercadoPago(new GuzzleClient());
$mp->setCredentials('CLIENT_ID', 'CLIENT_SECRET');
$paymentInfo = $mp->getPayment('PAYMENT_ID');

var_dump($paymentInfo);

$result = $mp->cancelPayment('PAYMENT_ID');

var_dump($result);

$result = $mp->refundPayment('PAYMENT_ID');

var_dump($result);

use MercadoPago\MercadoPago;
use MercadoPago\Http\GuzzleClient;

$mp = new MercadoPago(new GuzzleClient());
$mp->setAccessToken('SOME_ACCESS_TOKEN');

$mp->getClient()->post(
    '/v1/payments',
    $paymentData,
    ['access_token' => 'SOME_ACCESS_TOKEN']
);

$mp->getClient()->post(
    '/v1/customers',
    ['email' => '[email protected]'],
    ['access_token' => 'SOME_ACCESS_TOKEN']
);

$mp->getClient()->get(
    '/v1/customers/CUSTOMER_ID',
    [],
    ['access_token' => 'SOME_ACCESS_TOKEN']
);
 bash
$ composer 
json
{
    "edeisas/mercadopago-sdk-php": "1.0"
    }
}