healthia/laravel-usps
Composer 安装命令:
composer require healthia/laravel-usps
包简介
USPS API for Laravel 11. Forked from johnpaulmedina/laravel-usps for PHP 8.3+ / Laravel 11
README 文档
README
Laravel-USPS is a composer package that allows you to integrate the USPS Address / Shipping API / Rates Calculator. This package is ported from @author Vincent Gabriel https://github.com/VinceG/USPS-php-api
- Requires a valid USPS API Username
- Tested on Laravel 10
Installation
Begin by installing this package through Composer. Run this command from the Terminal:
composer require johnpaulmedina/laravel-usps
Laravel integration
For Laravel 5.5 and later, this package will be auto discovered and registered.
To wire this up in your Laravel 5.4 project you need to add the service provider.
Open config/app.php, and add a new item to the providers array.
Johnpaulmedina\Usps\UspsServiceProvider::class,
Then you must also specify the alias in config/app.php. Add a new item to the Aliases array.
'Usps' => Johnpaulmedina\Usps\Facades\Usps::class,
This will allow integration by adding the Facade Use Usps;
Laravel Config
Add your USPS username config in config/services.php.
'usps' => [ 'username' => "XXXXXXXXXXXX", 'testmode' => false, ],
Example Controller Usage
The only method completed for Laravel is the Usps::validate, Usps::rate which is defined in vendor/johnpaulmedina/laravel-usps/src/Usps/Usps.php. As this package was developed for internal use I did not bring over all the features but you are more than welcome to contribute the methods you need and I will merge them. I suggest looking at the original PHP-Wrapper by @VinceG USPS PHP-Api as I ported those clases and autoloaded them to use in the Usps.php file.
<?php namespace App\Http\Controllers; use App\Http\Requests; use Illuminate\Support\Facades\Request; use Johnpaulmedina\Usps; class USPSController extends Controller { public function index() { return response()->json( Usps::validate( Request::input('Address'), Request::input('Zip'), Request::input('Apartment'), Request::input('City'), Request::input('State') ) ); } public function trackConfirm() { return response()->json( Usps::trackConfirm( Request::input('id') ) ); } public function trackConfirmRevision1() { return response()->json( Usps::trackConfirm( Request::input('id'), 'Acme, Inc' ) ); } public function rate(Request $request) { $usps_rate = Usps::rate( [ 'Service' => $request->input('Service', 'PRIORITY COMMERCIAL'), 'FirstClassMailType' => $request->input('FirstClassMailType', ''), 'ZipOrigination' => $request->input('ZipOrigination', '91601'), 'ZipDestination' => $request->input('ZipDestination', $zipcode), 'Pounds' => $request->input('Pounds', $weight), 'Ounces' => $request->input('Ounces', 0), 'Container' => $request->input('Container', 'VARIABLE'), 'Machinable' => $request->input('Machinable', 'True'), ] ); $usps_return_rate = Arr::get($usps_rate, 'rate.RateV4Response.Package.Postage.Rate'); $usps_return_weight = Arr::get($usps_rate, 'rate.RateV4Response.Package.Pounds'); return response()->json([ 'rate' => $usps_return_rate, 'weight'=> $usps_return_weight, 'usps' => $usps_rate ]); } }
Contributors
@pdbreen @bredmor @scs-ben @daveore090
@VinceG Original README.MD
USPS PHP API
This wrapper allows you to perform some basic calls to the USPS api. Some of the features currently supported are:
- Rate Calculator (Both domestic and international)
- Zip code lookup by address
- City/State lookup by zip code
- Verify address
- Create Priority Shipping Labels
- Create Open & Distribute Shipping Labels
- Create International Shipping Labels (Express, Priority, First Class)
- Service Delivery Calculator
- Confirm Tracking
Requirements
- PHP >= 8.1
- USPS API Username
-
- Laravel 10
Authors
- Vincent Gabriel http://vadimg.com (Original PHP-Wrapper)
healthia/laravel-usps 适用场景与选型建议
healthia/laravel-usps 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「usps」 「laravel usps」 「laravel10」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 healthia/laravel-usps 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 healthia/laravel-usps 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 healthia/laravel-usps 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple PHP class for United States Postal Service (USPS) addresses
PHP wrapper for USPS Web Tools API
The PHP SDK of TrackingMore API
A PHP library for connecting with multiple carriers (FedEx, UPS, USPS) using Shippo.
Symfony bundle for Geonames API
The PHP SDK of 51Tracking API
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-27