Download the PHP package m4dev/laravel-usps without Composer
On this page you can find all versions of the php package m4dev/laravel-usps. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-usps
USPS Laravel Package
A comprehensive Laravel package for USPS shipping integration with support for address validation, rate calculation, label creation, and package tracking using the USPS API v3 with OAuth2 authentication.
Features
- OAuth2 Authentication: Secure authentication using client credentials
- Address Validation: Validate and standardize addresses using USPS API v3
- Rate Calculation: Get shipping rates for different USPS services with caching support
- Label Creation: Generate shipping labels in PDF format with tracking numbers
- Package Tracking: Track packages and automatically update shipment status
- Rate Caching: Cache rates to reduce API calls and improve performance
- Rate Shopping: Compare rates across multiple USPS services
- Database Integration: Store shipments and tracking information
- Artisan Commands: Built-in commands for testing and maintenance
Requirements
- PHP 8.1 or higher
- Laravel 10.0 or 11.0
- cURL extension
- JSON extension
- Valid USPS Developer Account
Installation
-
Install via Composer:
-
Publish the configuration file:
-
Run the migrations:
- Configure your environment variables in
.env:
Getting USPS API Credentials
- Go to the USPS Developer Portal
- Create an account or log in
- Register your application
- You'll receive a
client_idandclient_secret - Use these credentials in your
.envfile
Note: The modern USPS API v3 uses OAuth2 authentication with client credentials, not API keys.
Quick Start
Basic Usage Example
Detailed Usage
Address Validation
Getting Shipping Rates
Creating Shipping Labels
Package Tracking
Using the Facade
Artisan Commands
Test USPS Connection
Update Tracking Information
Clean Up Expired Cache
Configuration Options
Service Types
Configure available USPS services in config/usps.php:
Rate Shopping
Enable automatic rate comparison:
Caching
Configure rate caching:
Working with Models
UspsShipment Model
Advanced Usage
Batch Operations
Custom Exception Handling
Controller Example
Testing
Run the test suite:
Environment Setup for Testing
Create a .env.testing file:
Scheduled Tasks
Add to your app/Console/Kernel.php to automatically update tracking:
Error Handling Best Practices
- Always validate addresses before creating labels
- Handle rate limits with proper delays between requests
- Cache rates to reduce API calls
- Log errors for debugging and monitoring
- Use try-catch blocks around all USPS API calls
API Rate Limits
The USPS API has rate limits. The package includes:
- Automatic delays between batch operations
- OAuth token caching to reduce auth requests
- Rate caching to minimize API calls
Troubleshooting
Common Issues
- Authentication Errors: Verify your client_id and client_secret are correct
- Address Validation Failures: Ensure addresses are properly formatted
- Rate Errors: Check weight and dimension limits for selected service
- Label Creation Failures: Verify all required address fields are provided
Debug Mode
Enable debug logging in your .env:
Support
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the [MIT license] (LICENSE.md).
Changelog
v1.0.0
- Initial release with USPS API v3 support
- OAuth2 authentication
- Address validation, rates, labels, and tracking
- Rate caching and shopping features
- Comprehensive test suite
All versions of laravel-usps with dependencies
laravel/framework Version ^10.0|^11.0|^12.0
ext-curl Version *
ext-json Version *