Publishing the Configuration
While the package works with environment variables alone, you can optionally publish the configuration file for advanced customization.config/mercadopago.php in your Laravel application.
Environment Variables
All configuration options can be set via environment variables in your.env file.
Required Configuration
Your Mercado Pago access token. This is used by the SDK to authenticate API requests.Where to find it: Mercado Pago Dashboard → Your integrations → Credentials
.env
Optional Configuration
Your Mercado Pago public key. Used for frontend integrations like card tokenization.
.env
Secret used to validate webhook HMAC signatures. Highly recommended for production.When configured, the webhook endpoint validates the
x-signature header to ensure notifications are authentic..env
If not configured, webhooks will be accepted without signature validation (
validated: false in the response).Prefix for all registered routes (webhook and demo endpoints).Results in routes like:
.env
POST /api/payments/webhooksGET /api/payments/health
Enable or disable demo routes. Demo routes are always disabled in production regardless of this setting.Demo routes only respond when:
.env
- This is set to
trueAND APP_ENVislocalortesting
Forces the Mercado Pago SDK runtime environment. If not set, the package automatically uses:
localwhenAPP_ENVislocalortestingserverin all other environments
.env
Configuration File Structure
The publishedconfig/mercadopago.php file looks like this:
config/mercadopago.php
Example Configurations
- Local Development
- Production
- Testing
.env
- Demo routes are accessible
- Webhook validation is enabled
- SDK uses
localruntime automatically
Configuration Reference Table
| Variable | Required | Default | Description |
|---|---|---|---|
MERCADOPAGO_ACCESS_TOKEN | Yes | - | SDK authentication token for API calls |
MERCADOPAGO_PUBLIC_KEY | No | - | Public key for frontend integrations |
MERCADOPAGO_WEBHOOK_SECRET | Recommended | - | Secret for validating webhook signatures |
MERCADOPAGO_ROUTE_PREFIX | No | api/mercadopago | Prefix for all registered routes |
MERCADOPAGO_ENABLE_DEMO_ROUTES | No | true | Enable demo routes (only works in local/testing) |
MERCADOPAGO_RUNTIME_ENVIRONMENT | No | Auto-detected | Force SDK runtime: local or server |
Verifying Configuration
After configuring the package, verify your setup using the health check endpoint:Test the health endpoint
The health endpoint is available when demo routes are enabled:Expected response:
Security Best Practices
Development
- Use test credentials from Mercado Pago test users
- Keep
MERCADOPAGO_ENABLE_DEMO_ROUTES=truefor easier testing - Webhook secret is optional but recommended
Production
Use production credentials
Replace all test credentials with production access tokens and public keys from your Mercado Pago account.
Configure webhook secret
Always set
MERCADOPAGO_WEBHOOK_SECRET to validate incoming webhook notifications..env
Disable demo routes
Explicitly disable demo routes in production:Even if left enabled, they won’t respond in production environments.
.env
Use HTTPS
Ensure your webhook endpoint is accessible via HTTPS. Mercado Pago requires secure webhook URLs.
Troubleshooting
”Mercado Pago access token is not configured”
Solution: SetMERCADOPAGO_ACCESS_TOKEN and clear config cache:
Demo routes returning 404
Causes:MERCADOPAGO_ENABLE_DEMO_ROUTESis nottrueAPP_ENVis notlocalortesting- Routes are cached without the middleware
Webhook returning 401 Unauthorized
Cause: HMAC signature validation is failing. Check:MERCADOPAGO_WEBHOOK_SECRETmatches the secret configured in Mercado Pago dashboard- The request includes
x-signatureandx-request-idheaders - The
data.idparameter is present in the query string or payload
Configuration changes not taking effect
Solution: Clear and recache configuration:Next Steps
Using Services
Learn how to inject and use the package services in your application
Demo Endpoints
Explore the webhook and demo routes registered by the package