Download the PHP package puntodev/mercadopago-fake without Composer
On this page you can find all versions of the php package puntodev/mercadopago-fake. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download puntodev/mercadopago-fake
More information about puntodev/mercadopago-fake
Files in puntodev/mercadopago-fake
Package mercadopago-fake
Short Description Fake MercadoPago API Client for testing
License MIT
Homepage https://github.com/puntodev/mercadopago-fake
Informations about the package mercadopago-fake
mercadopago-fake
A fake MercadoPago API server for testing Laravel applications. It replaces the real puntodev/mercadopago client with a mock implementation that simulates the full checkout flow without hitting the MercadoPago API.
Installation
Activation
Set the environment variable in your .env or phpunit.xml:
The service provider auto-registers and swaps the MercadoPago binding in the container with MercadoPagoFake.
How It Works
The library has four main parts:
MercadoPagoFake
Implements MercadoPago and manages global test state. Stores preferences, payments, and merchant orders in a file-based cache, records method calls for assertions, and provides a reset() method to clean up between tests.
MercadoPagoFakeApi
Implements MercadoPagoApi with mock implementations:
createPaymentPreference(array $order)— Generates a fake preference ID, stores it in cache, and returns the expected response structure includinginit_pointandsandbox_init_point.findMerchantOrders(array $query)— Returns an empty list of merchant orders.findMerchantOrderById(string $id)— Retrieves a stored merchant order. Throws aRequestExceptionif not found.findPayments(array $query)— Returns an empty list of payments.findPaymentById(string $id)— Retrieves a stored payment. Throws aRequestExceptionif not found.
FakeCheckoutController
Exposes HTTP routes that simulate MercadoPago's checkout UI:
| Method | Route | Description |
|---|---|---|
| GET | /mercadopago-fake/checkout/{preferenceId} |
Displays a styled checkout page with Pay, Decline, and Cancel buttons |
| POST | /mercadopago-fake/checkout/{preferenceId}/approve |
Simulates approval and posts a webhook (IPN) to your app's notification_url |
| POST | /mercadopago-fake/checkout/{preferenceId}/decline |
Marks the payment as declined and redirects to the failure URL |
| GET | /mercadopago-fake/checkout/{preferenceId}/cancel |
Redirects to the failure back URL |
MercadoPagoFakeServiceProvider
When MERCADOPAGO_USE_FAKE is true, it binds MercadoPagoFake as a singleton in place of MercadoPago, registers the checkout routes, and loads the Blade views.
Checkout Flow
Usage
Automated Tests
Manual Browser Testing
Start your Laravel app with MERCADOPAGO_USE_FAKE=true and navigate to the init_point URL returned by createPaymentPreference(). The checkout page lets you click Pay, Decline, or Cancel to test the full flow, including IPN webhooks hitting your application.
Test Helpers
| Method | Description |
|---|---|
MercadoPagoFake::storePreference($id, $preference) |
Store a preference in the fake cache |
MercadoPagoFake::getStoredPreference($id) |
Retrieve a stored preference |
MercadoPagoFake::storePayment($id, $payment) |
Store a payment in the fake cache |
MercadoPagoFake::getStoredPayment($id) |
Retrieve a stored payment |
MercadoPagoFake::storeMerchantOrder($id, $order) |
Store a merchant order in the fake cache |
MercadoPagoFake::getStoredMerchantOrder($id) |
Retrieve a stored merchant order |
MercadoPagoFake::markPaymentAsDeclined($id) |
Mark a payment as declined |
MercadoPagoFake::isPaymentDeclined($id) |
Check if a payment is declined |
MercadoPagoFake::recordCall($method, $args) |
Record a method call |
MercadoPagoFake::getCalls($method) |
Get recorded calls, optionally filtered by method |
MercadoPagoFake::reset() |
Clear all stored state and recorded calls |
Development
Code style is enforced with Laravel Pint (laravel
preset, see pint.json). The test suite is fully isolated — it never reaches the network,
so no MercadoPago credentials are required.
Please run composer format before opening a pull request. See CONTRIBUTING.md
for the full contribution guide.
Requirements
- PHP ^8.5
- Laravel 13+
puntodev/mercadopago^7.0
Changelog
See CHANGELOG.md for the list of changes per version.
Releases are cut from GitHub's "Generate release notes" button (grouping configured
in .github/release.yml). When a release is published, the
update-changelog workflow writes its notes
into CHANGELOG.md and commits them back to main.