fedeisas / mercadopago-sdk-php
MercadoPago PHP SDK https://developers.mercadopago.com/
v1.0.0
2017-06-24 23:49 UTC
Requires
- php: ~5.6|~7.0
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- php-vcr/php-vcr: ^1.3
- php-vcr/phpunit-testlistener-vcr: ^2.0
- phpunit/phpunit: ~5.7
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2024-10-29 05:04:57 UTC
README
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
- 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
- Chile: https://www.mercadopago.com/mlc/herramientas/aplicaciones
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'] );
- View more Custom checkout related APIs in Developers Site
- Argentina: https://www.mercadopago.com.ar/developers
- Brazil: https://www.mercadopago.com.br/developers
- Mexico: https://www.mercadopago.com.mx/developers
- Venezuela: https://www.mercadopago.com.ve/developers
- Colombia: https://www.mercadopago.com.co/developers
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.