Skip to main content

Laravel MercadoPago

A Laravel package for integrating Mercado Pago payment gateway with reusable services and demo endpoints.

Overview

Laravel MercadoPago provides a clean, decoupled integration with the Mercado Pago payment platform. Built for Laravel 12, this package leverages auto-discovery and dependency injection to make payment processing straightforward and maintainable.

Quick Start

Get up and running with your first payment in minutes

Installation

Install and configure the package in your Laravel project

API Reference

Explore all available services and methods

Configuration

Configure credentials and environment settings

Key Features

Auto-Discovery

Automatic Laravel service provider registration

Reusable Services

Dedicated services for preferences, payments, refunds, customers, and cards

Webhook Validation

HMAC signature validation for secure webhook handling

Demo Endpoints

JSON endpoints for development and testing

Environment Config

Flexible configuration via environment variables

Test Users

Test user creation for QA automation

What’s Included

This package provides:
  • PreferenceService - Create payment preferences for checkout flows
  • PaymentService - Process and retrieve payment information
  • CustomerService - Manage customer records
  • CardService - Handle customer payment cards
  • RefundService - Process full and partial refunds
  • PaymentMethodService - List available payment methods
  • WebhookService - Handle and validate Mercado Pago webhooks
  • TestUserService - Create test users for development

Requirements

  • PHP ^8.2
  • Laravel ^12.0
  • Mercado Pago SDK ^3.8

Quick Example

use Fitodac\LaravelMercadoPago\Services\PreferenceService;

class CheckoutController
{
    public function createPreference(PreferenceService $preferenceService)
    {
        $preference = $preferenceService->create([
            'items' => [
                [
                    'title' => 'Product Name',
                    'quantity' => 1,
                    'unit_price' => 100.00
                ]
            ],
            'payer' => [
                'email' => '[email protected]'
            ]
        ]);

        return response()->json([
            'id' => $preference['id'],
            'init_point' => $preference['init_point']
        ]);
    }
}

Getting Started

1

Install the package

Install via Composer in your Laravel project
composer require fitodac/laravel-mercadopago:^1.0
2

Configure credentials

Add your Mercado Pago credentials to .env
MERCADOPAGO_ACCESS_TOKEN=your_access_token
MERCADOPAGO_PUBLIC_KEY=your_public_key
MERCADOPAGO_WEBHOOK_SECRET=your_webhook_secret
3

Start building

Inject services into your controllers and start processing payments

Next Steps

Create Preferences

Learn how to create payment preferences

Process Payments

Handle direct payment processing

Handle Webhooks

Implement webhook notifications

Production Deployment

Deploy securely to production

Build docs developers (and LLMs) love