bkuhl/simple-ups
Composer 安装命令:
composer require bkuhl/simple-ups
包简介
Fetch rates, track packages and verify addresses via the UPS API
关键字:
README 文档
README
An easy to use PHP UPS Library for tracking, rates and address validation
README Contents
## Features- Address Validation - Ensure an address is valid before it's accepted by your application
- Address Correction - If an address is invalid, we'll help you correct it
- Track Packages - See current status, recent activity, delivery requirements (signature, etc.), insurance details and more
- Shipping Rates - Get shipping estimates for packages
You can install the library via Composer by running:
composer require bkuhl/simple-ups:1.*
## Usage1.* versions will maintain PHP 5.3 compatibility.
dev-masterwill increase the PHP version requirement for future, 2.* versions.
SimpleUPS is currently only available in a static context with the following methods:
- SimpleUPS::getRates()
- SimpleUPS::isValidRegion()
- SimpleUPS::getSuggestedRegions()
- SimpleUPS::trackByTrackingNumber()
- SimpleUPS::isValidAddress()
- SimpleUPS::getCorrectedAddress()
- SimpleUPS::getSuggestedAddresses()
- SimpleUPS::setAuthentication()
- SimpleUPS::getAccountNumber()
- SimpleUPS::getAccessLicenseNumber()
- SimpleUPS::getPassword()
- SimpleUPS::getUserId()
- SimpleUPS::setShipper()
- SimpleUPS::getShipper()
- SimpleUPS::setCurrencyCode()
- SimpleUPS::setDebug()
- SimpleUPS::getDebugOutput()
Validating an address can be useful to ensure an address that a user provides can be shipped to.
$address = new Address(); $address->setStreet('1001 North Alameda Street'); $address->setStateProvinceCode('CA'); $address->setCity('Los Angeles'); $address->setPostalCode(90012); $address->setCountryCode('US'); try { var_dump(UPS::isValidAddress($address)); // true } catch(Exception $e) { //unable to validate address }### Region Validation
If an address fails, validating the region can help you determine if the city, state and zip is valid even if the street address isn't.
$address = new Address(); $address->setStreet('xx North Alameda Street'); $address->setStateProvinceCode('CA'); $address->setCity('Los Angeles'); $address->setPostalCode(90012); $address->setCountryCode('US'); try { if (!UPS::isValidAddress($address)) var_dump(UPS::isValidRegion($address)); // true } catch(Exception $e) { //unable to validate region or address }### Tracking Shipments
Tracking numbers may contain multiple shipments, and shipments may contain multiple packages, and activity is associated with packages.
try { /* @var $shipment \SimpleUPS\Track\SmallPackage\Shipment */ foreach (UPS::trackByTrackingNumber('1Z4861WWE194914215') as $shipment) foreach ($shipment->getPackages() as $package) foreach ($package->getActivity() as $activity) if ($activity->getStatusType()->isDelivered()) echo 'DELIVERED'; } catch (TrackingNumberNotFoundException $e) { //Tracking number does not exist } catch (Exception $e) { //Unable to track package } var_dump(UPS::isValidAddress($address)); // false### Fetching Rates
try { //set shipper $fromAddress = new \SimpleUPS\InstructionalAddress(); $fromAddress->setAddressee('Mark Stevens'); $fromAddress->setStreet('10571 Pico Blvd'); $fromAddress->setStateProvinceCode('CA'); $fromAddress->setCity('Los Angeles'); $fromAddress->setPostalCode(90064); $fromAddress->setCountryCode('US'); $shipper = new \SimpleUPS\Shipper(); $shipper->setNumber('xxxxxxx'); $shipper->setAddress($fromAddress); UPS::setShipper($shipper); //define a shipping destination $shippingDestination = new \SimpleUPS\InstructionalAddress(); $shippingDestination->setStreet('220 Bowery'); $shippingDestination->setStateProvinceCode('NY'); $shippingDestination->setCity('New York'); $shippingDestination->setPostalCode(10453); $shippingDestination->setCountryCode('US'); //define a package, we could specify the dimensions of the box if we wanted a more accurate estimate $package = new \SimpleUPS\Rates\Package(); $package->setWeight('7'); $shipment = new \SimpleUPS\Rates\Shipment(); $shipment->setDestination($shippingDestination); $shipment->addPackage($package); echo 'Rates: '; echo '<ul>'; foreach (UPS::getRates($shipment) as $shippingMethod) echo '<li>'.$shippingMethod->getService()->getDescription().' ($'.$shippingMethod->getTotalCharges().')</li>'; echo '</ul>'; } catch (Exception $e) { //doh, something went wrong echo 'Failed: ('.get_class($e).') '.$e->getMessage().'<br/>'; echo 'Stack trace:<br/><pre>'.$e->getTraceAsString().'</pre>'; }
bkuhl/simple-ups 适用场景与选型建议
bkuhl/simple-ups 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.86k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2014 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ups」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bkuhl/simple-ups 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bkuhl/simple-ups 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bkuhl/simple-ups 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The PHP SDK of TrackingMore API
A PHP library for connecting with multiple carriers (FedEx, UPS, USPS) using Shippo.
The PHP SDK of 51Tracking API
Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.
This SDK will help you generate the access token using PHP . Using this access token you will be able to connect to widgets supported by UPS.
PHP UPS API
统计信息
- 总下载量: 20.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-06-25