fedeisas/mercadopago-sdk-php

MercadoPago PHP SDK https://developers.mercadopago.com/

v1.0.0 2017-06-24 23:49 UTC

This package is auto-updated.

Last update: 2021-09-29 02:03:27 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Install

Via Composer

$ composer require fedeisas/mercadopago-sdk-php

Or as a dependency in your project's composer.json:

{
    "require": {
        "fedeisas/mercadopago-sdk-php": "1.0"
    }
}

Basic checkout

Configure your credentials

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

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

Preferences

Get an existent Checkout preference

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

var_dump($preference);

Create a Checkout preference

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

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

var_dump($preference);

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

Payments/Collections

Search for payments

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

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

var_dump($searchResult);

Get payment data

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

Cancel (only for pending payments)

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

var_dump($result);

Refund (only for accredited payments)

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

var_dump($result);

Customized checkout

Use an access token:

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

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

Create payment

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

Create customer

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

Get customer

$mp->getClient()->get(
    '/v1/customers/CUSTOMER_ID',
    [],
    ['access_token' => 'SOME_ACCESS_TOKEN']
);

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email federicoisas@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.