Prerequisites
Before deploying to production, ensure you have:- PHP
^8.2installed on your production server - Laravel
^12.0configured and working - Valid MercadoPago production credentials (access token, public key, webhook secret)
- HTTPS enabled on your domain
- Composer available for dependency installation
Environment Variables
Configure production environment
Set the following environment variables in your production
.env file:Install dependencies
Install package dependencies with production optimizations:The
--no-dev flag excludes development dependencies, and --optimize-autoloader improves class loading performance.Disabling Demo Routes
Demo routes are automatically disabled in production when:MERCADOPAGO_ENABLE_DEMO_ROUTES=falsein your.envAPP_ENVis set to anything other thanlocalortesting
src/Http/Middleware/EnsureDemoRoutesEnabled.php:18-28 enforces this protection:
/api/mercadopago/health/api/mercadopago/payment-methods/api/mercadopago/preferences/api/mercadopago/payments/api/mercadopago/customers/api/mercadopago/test-users
The webhook route (
POST /api/mercadopago/webhooks) remains active in all environments as it’s required for production operations.Cache Optimization
Optimize Laravel’s configuration and route caching for production performance:Runtime Environment Configuration
The package automatically configures the MercadoPago SDK runtime based on your Laravel environment:- Local/Testing: Uses
localruntime mode - Production: Uses
serverruntime mode
In most cases, you don’t need to set this variable. The package selects the appropriate runtime automatically.
Production Deployment Checklist
Use this checklist before deploying to production:Security configuration
-
MERCADOPAGO_ENABLE_DEMO_ROUTES=false -
MERCADOPAGO_WEBHOOK_SECRETconfigured - HTTPS enabled and enforced
- Production credentials stored securely
- No credentials committed to repository
Application setup
- Dependencies installed with
--no-dev --optimize-autoloader - Configuration cached with
php artisan config:cache - Routes cached with
php artisan route:cache - Package discovery completed
Monitoring and logging
- Centralized logging configured
- Error monitoring for
401,422, and500responses - Webhook endpoint monitoring active
- Alert system configured for payment failures
MercadoPago configuration
- Webhook URL registered in MercadoPago dashboard
- Webhook URL points to your HTTPS domain
- Webhook secret matches between MercadoPago and your
.env - Production credentials tested
Testing Production Deployment
After deployment, verify your setup:1. Verify Demo Routes Are Disabled
404 Not Found
2. Verify Webhook Is Active
200 or 401 (if signature validation is active)
3. Trigger a Real Webhook
Create a test payment through MercadoPago’s interface and verify your webhook receives and processes the notification correctly.Post-Deployment Operations
Configuration Updates
When updating environment variables:Package Updates
When updating the package version:Troubleshooting Production Issues
Demo Routes Still Accessible
Symptom: Demo routes return200 in production
Solution:
- Verify
MERCADOPAGO_ENABLE_DEMO_ROUTES=falsein.env - Verify
APP_ENV=production - Clear and rebuild config cache:
Webhook Returns 422
Symptom:Mercado Pago access token is not configured.
Solution:
- Verify
MERCADOPAGO_ACCESS_TOKENis set in.env - Clear config cache:
- Verify credentials are not expired
Package Routes Not Found
Symptom: All MercadoPago routes return404
Solution:
Next Steps
Security Best Practices
Implement security measures for production
Webhooks
Handle webhook notifications properly