Overview
The Laravel MercadoPago package configuration controls SDK authentication, webhook security, route registration, and runtime behavior. All options can be set via environment variables or by publishing and modifying the configuration file.Publishing the Configuration File
While the package works with environment variables alone, you can publish the configuration file for advanced customization or programmatic configuration:config/mercadopago.php in your Laravel application, allowing you to access configuration values via config('mercadopago.{key}').
Configuration Options
Your Mercado Pago access token used by the SDK to authenticate API requests.Environment variable: Where to find it: Mercado Pago Dashboard → Your integrations → Credentials
MERCADOPAGO_ACCESS_TOKENDefault: nullThis token is essential for all API operations. Without it, the package services will throw a configuration exception when attempting to make API calls..env
Your Mercado Pago public key used for frontend integrations like card tokenization and Checkout Pro.Environment variable: Use cases:
MERCADOPAGO_PUBLIC_KEYDefault: nullWhile not required for server-side operations, this is necessary if you’re implementing client-side payment flows that require tokenizing card data before sending it to your backend..env
- Card tokenization in the browser
- Frontend validation of card details
- Checkout Pro initialization
Secret used to validate webhook HMAC signatures for enhanced security.Environment variable: How it works:Where to configure: Mercado Pago Dashboard → Your integrations → Webhooks → Signature
MERCADOPAGO_WEBHOOK_SECRETDefault: nullHighly recommended for production environments. When configured, the webhook endpoint validates the x-signature header to ensure notifications are authentic and originate from Mercado Pago..env
- Mercado Pago sends a signature in the
x-signatureheader - The package computes an HMAC hash using this secret
- If signatures match, the webhook is validated
- If not configured, webhooks are accepted without validation
If
webhook_secret is not configured, webhooks will still be processed but the response will include "validated": false.URL prefix for all routes registered by the package, including webhooks and demo endpoints.Environment variable: Example routes with custom prefix:
MERCADOPAGO_ROUTE_PREFIXDefault: "api/mercadopago"This allows you to customize where package routes are mounted in your application’s URL structure..env
POST /api/payments/webhooks(webhook endpoint)GET /api/payments/health(health check)POST /api/payments/preferences(demo preference creation)
stringEnable or disable demo routes for testing and development.Environment variable: Important security note: Demo routes are always disabled in production regardless of this setting. The package checks
MERCADOPAGO_ENABLE_DEMO_ROUTESDefault: trueType: boolean (cast from string in .env)Demo routes provide convenient endpoints for testing the package functionality without writing custom controllers. They’re useful during development but should be disabled in production..env
APP_ENV and only enables demo routes when the environment is local or testing.Conditions for demo routes to be accessible:enable_demo_routesmust betrueANDAPP_ENVmust belocalortesting
GET /api/mercadopago/health- Configuration health checkPOST /api/mercadopago/preferences- Create payment preferencePOST /api/mercadopago/payments- Process paymentGET /api/mercadopago/customers- List customersPOST /api/mercadopago/customers- Create customerGET /api/mercadopago/payment-methods- Get payment methodsPOST /api/mercadopago/test-users- Create test user
Forces the Mercado Pago SDK runtime environment mode.Environment variable: When to override:
MERCADOPAGO_RUNTIME_ENVIRONMENTDefault: null (auto-detected)Type: string|nullPossible values:"local"- Development/testing mode"server"- Production modenull- Auto-detect based onAPP_ENV
- Uses
localwhenAPP_ENVislocalortesting - Uses
serverin all other environments (production, staging, etc.)
.env
- Testing production behavior in local environment
- Debugging SDK issues
- Special deployment scenarios
In most cases, you should leave this unset and let the package auto-detect the appropriate runtime mode.
Configuration File Structure
After publishing, theconfig/mercadopago.php file contains:
config/mercadopago.php
Accessing Configuration Values
You can access configuration values anywhere in your Laravel application:Environment-Specific Examples
- Local Development
- Production
- Testing/CI
- Staging
.env
- Demo routes are accessible at
/api/mercadopago/* - Webhook validation is enabled with test secret
- SDK automatically uses
localruntime mode - Health check available at
/api/mercadopago/health
Configuration Reference Table
| Option | Type | Required | Default | Environment Variable |
|---|---|---|---|---|
access_token | string | Yes | null | MERCADOPAGO_ACCESS_TOKEN |
public_key | string | No | null | MERCADOPAGO_PUBLIC_KEY |
webhook_secret | string | Recommended | null | MERCADOPAGO_WEBHOOK_SECRET |
route_prefix | string | No | "api/mercadopago" | MERCADOPAGO_ROUTE_PREFIX |
enable_demo_routes | boolean | No | true | MERCADOPAGO_ENABLE_DEMO_ROUTES |
runtime_environment | string|null | No | Auto-detected | MERCADOPAGO_RUNTIME_ENVIRONMENT |
Validating Configuration
After configuring the package, verify your setup is correct.Clear configuration cache
If you’ve previously cached configuration, clear it to pick up new values:
Test with health endpoint
When demo routes are enabled, use the health endpoint to verify configuration:Expected response:Response fields:
configured:trueifaccess_tokenis sethas_public_key:trueifpublic_keyis sethas_webhook_secret:trueifwebhook_secretis setenvironment: Current runtime environment (localorserver)
Verify route registration
List all package routes to confirm they use your configured prefix:You should see routes matching your
route_prefix configuration.Security Best Practices
Development Environment
Use test credentials from Mercado Pago test users
Enable demo routes for easier testing (
MERCADOPAGO_ENABLE_DEMO_ROUTES=true)Configure webhook secret even in development for testing validation logic
Use test mode access tokens (starting with
TEST-)Production Environment
Use production credentials from your Mercado Pago account
Configure webhook secret for signature validation (required)
Disable demo routes explicitly (
MERCADOPAGO_ENABLE_DEMO_ROUTES=false)Use HTTPS for all webhook endpoints
Cache configuration for performance (
php artisan config:cache)Rotate credentials periodically and when team members leave
Monitor webhook failures and failed signature validations
Troubleshooting
”Mercado Pago access token is not configured”
Cause: Theaccess_token configuration is missing or empty.
Solution:
- Set
MERCADOPAGO_ACCESS_TOKENin your.envfile - Clear configuration cache:
- Verify the value is loaded:
Demo routes returning 404
Possible causes:MERCADOPAGO_ENABLE_DEMO_ROUTESis nottrueAPP_ENVis notlocalortesting(production environment)- Routes are cached with old configuration
Webhook returning 401 Unauthorized
Cause: Webhook HMAC signature validation is failing. Check:MERCADOPAGO_WEBHOOK_SECRETmatches the secret configured in Mercado Pago dashboard- Request includes required headers:
x-signature,x-request-id - Request includes
data.idparameter in query string or payload
Configuration changes not taking effect
Cause: Laravel’s configuration is cached. Solution:Routes registered with wrong prefix
Cause: Configuration cached beforeroute_prefix was updated.
Solution:
Related Documentation
Installation
Install the package and set up your environment
Credentials Guide
Learn how to obtain and manage Mercado Pago credentials
Webhook Handling
Implement secure webhook processing with signature validation
Production Deployment
Best practices for deploying to production