chrishardie / laravel-usps-addresses
Laravel package that provides a simple facade to the USPS Addresses API
Package info
github.com/ChrisHardie/laravel-usps-addresses
pkg:composer/chrishardie/laravel-usps-addresses
Fund package maintenance!
Requires
- php: ^8.1
- illuminate/contracts: ^10.0|^11.0||^12.0
- spatie/laravel-data: ^4
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
README
Laravel package that provides a simple facade to the USPS Addresses API
Installation
You can install the package via composer:
composer require chrishardie/laravel-usps-addresses
Define required variables in .env, available from your app's configuration in the USPS Developers Dashboard:
USPS_CLIENT_ID= USPS_CLIENT_SECRET=
You can optionally publish the config file with:
php artisan vendor:publish --tag="laravel-usps-addresses-config"
This is the contents of the published config file:
return [ 'base_url' => env('USPS_ADDRESSES_BASE_URL', 'https://apis.usps.com/addresses/v3'), 'oauth' => [ 'token_url' => env('USPS_OAUTH_TOKEN_URL', 'https://apis.usps.com/oauth2/v3/token'), 'client_id' => env('USPS_CLIENT_ID'), 'client_secret' => env('USPS_CLIENT_SECRET'), 'scope' => 'addresses', ], 'timeout' => 10, ];
Usage
use UspsAddress; $result = UspsAddress::verify([ 'streetAddress' => '2704 Erie Ave', 'city' => 'Cincinnati', 'state' => 'OH', ]); if ($result->isValid()) { echo $result->address->streetAddress; };
Methods available correspond to available API endpoints:
UspsAddress::verify(): Returns the best standardized address for a given address.UspsAddress::cityState(): Returns the city and state for a given ZIP Code.UspsAddress::zipCode(): Returns the ZIP Code for a given address.
View the USPS API documentation for details about available parameters and responses.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.