PHPackages                             puntodev/mercadopago - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. puntodev/mercadopago

ActiveLibrary[API Development](/categories/api)

puntodev/mercadopago
====================

MercadoPago API Client

v6.0.0(2mo ago)27.0k↓77%11MITPHPPHP &gt;=8.4 &lt;9.0CI failing

Since Oct 11Pushed 1w ago2 watchersCompare

[ Source](https://github.com/puntodev/mercadopago)[ Packagist](https://packagist.org/packages/puntodev/mercadopago)[ Docs](https://github.com/puntodev/mercadopago)[ RSS](/packages/puntodev-mercadopago/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (8)Versions (35)Used By (1)

MercadoPago API Client for Laravel
==================================

[](#mercadopago-api-client-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c1b9b8291ea4d8a5020315dc6949b341675d353fd6d7a40de0b4dcd92ba3805b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70756e746f6465762f6d65726361646f7061676f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/puntodev/mercadopago)[![Total Downloads](https://camo.githubusercontent.com/a0573dc4c91149ccf83a63167e3ae598294a9f76c56cf3e3c5d936f12ccb2718/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70756e746f6465762f6d65726361646f7061676f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/puntodev/mercadopago)

A lightweight Laravel package that wraps the [MercadoPago API](https://www.mercadopago.com.ar/developers)to create Checkout preferences and look up merchant orders and payments. It uses Laravel's HTTP client under the hood and caches the OAuth2 access token automatically.

Requirements
------------

[](#requirements)

- PHP `>=8.4  env('MERCADOPAGO_API_CLIENT_ID'),
    'client_secret' => env('MERCADOPAGO_API_CLIENT_SECRET'),
    'use_sandbox' => env('SANDBOX_GATEWAYS', false),
];
```

The API host is always `api.mercadopago.com`. MercadoPago distinguishes sandbox from production through your credentials/test users: when creating a preference the response includes both an `init_point` (production) and a `sandbox_init_point` (sandbox) checkout URL. The `use_sandbox` flag is surfaced through `usingSandbox()` so your application can decide which checkout URL to use.

Usage
-----

[](#usage)

### Resolving the client

[](#resolving-the-client)

Inject the `MercadoPago` contract (or use the `MercadoPago` facade) and obtain a `MercadoPagoApi` instance. Use `defaultClient()` to use the configured credentials, or `withCredentials()` to override them at runtime (e.g. for multi-tenant setups):

```
use Puntodev\MercadoPago\MercadoPago;

public function __construct(private MercadoPago $mercadoPago) {}

// With the credentials from config/mercadopago.php
$api = $this->mercadoPago->defaultClient();

// Or with per-request credentials
$api = $this->mercadoPago->withCredentials($clientId, $clientSecret);
```

### Building a payment preference

[](#building-a-payment-preference)

`PaymentPreferenceBuilder` produces the payload for the Checkout Preferences API. Items are added through the nested `PaymentPreferenceItemBuilder` returned by `item()`. The `pending` / `failure` back URLs default to the success URL, `auto_return` is `all`, and an expiration window is only sent when provided:

```
use Puntodev\MercadoPago\PaymentPreferenceBuilder;

$preference = (new PaymentPreferenceBuilder())
    ->item()
        ->title('My custom product')
        ->unitPrice(23.20)
        ->quantity(1)
        ->currency('ARS')      // defaults to ARS
        ->make()
    ->externalId('your-internal-id')
    ->payerFirstName('John')
    ->payerLastName('Doe')
    ->payerEmail('john@example.com')
    ->notificationUrl('https://example.com/mp/ipn')
    ->successBackUrl('https://example.com/return')
    ->binaryMode(true)
    ->make();
```

### Creating a preference and looking up orders/payments

[](#creating-a-preference-and-looking-up-orderspayments)

```
$created = $api->createPaymentPreference($preference);

// Send the buyer to the appropriate checkout URL
$checkoutUrl = $api->usingSandbox()
    ? $created['sandbox_init_point']
    : $created['init_point'];

// Later, look up merchant orders and payments
$orders = $api->findMerchantOrders(['external_reference' => 'your-internal-id']);
$order = $api->findMerchantOrderById($orderId);

$payments = $api->findPayments(['external_reference' => 'your-internal-id']);
$payment = $api->findPaymentById($paymentId);
```

All methods return the decoded JSON response as an `array` (or `null`) and throw `Illuminate\Http\Client\RequestException` on HTTP errors.

Testing
-------

[](#testing)

```
composer test            # runs PHPUnit
composer test-coverage   # generates HTML coverage report
```

> **Note:** the test suite (`tests/MercadoPagoApiTest.php`) makes **real HTTP calls to the MercadoPago API**. You must provide valid credentials via `MERCADOPAGO_API_CLIENT_ID` and `MERCADOPAGO_API_CLIENT_SECRET`. `phpunit.xml.dist`forces `SANDBOX_GATEWAYS=true`.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Releasing
---------

[](#releasing)

Releases are cut from GitHub and the changelog is kept in sync automatically:

1. Merge the pull requests you want to ship into `master`. Label them so the notes group nicely (`security`, `enhancement`, `bug`, `dependencies`, `documentation`); grouping is configured in [`.github/release.yml`](.github/release.yml).
2. On GitHub, go to **Releases → Draft a new release**, create a `vX.Y.Z` tag following [SemVer](https://semver.org/), and click **Generate release notes**.
3. **Publish** the release. Packagist picks up the new tag, and the [`update-changelog.yml`](.github/workflows/update-changelog.yml) workflow writes the release notes into `CHANGELOG.md` and commits them back to `master`.

The `Unreleased` section in the changelog is just an anchor — release notes flow from the published GitHub release, so there is no changelog to edit by hand.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Mariano Goldman](https://github.com/puntodev)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance91

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 80.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~79 days

Total

26

Last Release

89d ago

Major Versions

v1.1.1 → v2.0.02021-05-22

v2.1.2 → v3.0.02023-03-18

v3.0.1 → v4.0.02024-04-07

v4.0.5 → v5.0.02025-05-02

v5.1.2 → v6.0.02026-03-29

PHP version history (8 changes)v0.0.1PHP ^7.4

1.0.0PHP ^7.4|^8.0

v2.0.0PHP ^8.0

v3.0.0PHP ^8.1

v4.0.0PHP ^8.2

v4.0.5PHP ^8.3

v5.1.0PHP &gt;=8.3 &lt;9.0

v5.1.2PHP &gt;=8.4 &lt;9.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7201db0e06c12ae2e12e1cf4ee5806b5b465dc538bee3cab6bfb1c0ec52e4dce?d=identicon)[Mariano Goldman](/maintainers/Mariano%20Goldman)

---

Top Contributors

[![marianogoldman](https://avatars.githubusercontent.com/u/959563?v=4)](https://github.com/marianogoldman "marianogoldman (33 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")

---

Tags

mercadopagopuntodev

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/puntodev-mercadopago/health.svg)

```
[![Health](https://phpackages.com/badges/puntodev-mercadopago/health.svg)](https://phpackages.com/packages/puntodev-mercadopago)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[simplestats-io/laravel-client

Analytics for Laravel. Track visitors, registrations, and payments. Discover which channels actually drive revenue, not just traffic. Server-side, GDPR compliant, ad-blocker proof.

5019.3k](/packages/simplestats-io-laravel-client)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1348.1k1](/packages/jasara-php-amzn-selling-partner-api)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

252.5k](/packages/eslazarev-wildberries-sdk)[files.com/files-php-sdk

Files.com PHP SDK

2478.1k](/packages/filescom-files-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
