jsamhall/shipengine
Composer 安装命令:
composer require jsamhall/shipengine
包简介
A PHP wrapper for the accessing and interacting with the ShipEngine v1 API.
关键字:
README 文档
README
A PHP wrapper for the accessing and interacting with the ShipEngine v1 API.
Not actively maintained though functional for my own needs. Use at your own discretion
How to use
$addressFormatter = new Acme\AddressFormatter; // implements Address\FormatterInterface $shipEngine = new jsamhall\ShipEngine\ShipEngine('your_shipengine_api_key', $addressFormatter); $carriers = $shipEngine->listCarriers();
Example
Minimal example to implement the Quick Start example:
use jsamhall\ShipEngine\Address\ArrayFormatter; use jsamhall\ShipEngine\ShipEngine; use jsamhall\ShipEngine\Address\Address; use jsamhall\ShipEngine\Shipment\Package; use jsamhall\ShipEngine\Labels\Shipment; use jsamhall\ShipEngine\Carriers\USPS\ServiceCode; $to = new Address(); $to->setName('Mickey and Minnie Mouse'); $to->setPhone('+1 (714) 781-456'); $to->setCompanyName('The Walt Disney Company'); $to->setAddressLine1('address_line1'); $to->setCityLocality('Burbank'); $to->setStateProvince('CA'); $to->setPostalCode('91521'); $to->setCountryCode('US'); $to->setAddressResidentialIndicator('No'); $from = new Address; $from->setName('Mickey and Minnie Mouse'); $from->setPhone('+1 (714) 781-456'); $from->setCompanyName('The Walt Disney Company'); $from->setAddressLine1('address_line1'); $from->setCityLocality('Burbank'); $from->setStateProvince('CA'); $from->setPostalCode('91521'); $from->setCountryCode('US'); $from->setAddressResidentialIndicator('No'); $weight = new Package\Weight(1.0); $dimensions = new Package\Dimensions(10.0, 15.0, 8.0); $package = new Package($weight, $dimensions); $shipment = new Shipment(ServiceCode::priorityMail(), $to, $from, [$package]); $addressFormatter = new ArrayFormatter(); $shipEngine = new ShipEngine('your_shipengine_api_key', $addressFormatter); $testMode = true; $label = $shipEngine->createLabel($shipment, $testMode);
Addresses
ShipEngine expects a certain address format. This Library offers the Address\Address class which conforms
to this format. All methods that require an Address as part of the request (e.g., validation, rating, labels etc.)
expect an Address\Address in order to ensure consistency and compatibility.
You should write an implementation Address\FormatterInterface that extracts data from your domain-specific
Address in the format expected by the ShipEngine API. This implementation is a constructor argument for the
Address\Factory class which will translate your Domain's Address Model to an instance of Address\Address
This formatter is available in the public interface of the jsamhall\ShipEngine instance:
/** @var Acme\Domain\Address $domainAddress */ $domainAddress = $this->addressRepository->find(1234); $shipEngineAddress = $shipEngine->formatAddress($domainAddress); // now $shipEngineAddress can be used for building e.g. an instance of Labels\Shipment
Tracking
Retrieve tracking information for a package using its carrier code and tracking number. This requires the ShipEngine Advanced plan or higher, and the carrier must be connected to your ShipEngine account.
use jsamhall\ShipEngine\ShipEngine; use jsamhall\ShipEngine\Address\ArrayFormatter; $shipEngine = new ShipEngine('your_shipengine_api_key', new ArrayFormatter()); $tracking = $shipEngine->trackPackage('usps', '9405511899223197428490'); $tracking->getStatusCode(); // e.g. "DE" (see Tracking\StatusCode constants) $tracking->getStatusDescription(); // e.g. "Delivered" $tracking->isDelivered(); // bool $tracking->getActualDeliveryDate(); // ?\DateTime foreach ($tracking->getEvents() as $event) { printf("%s — %s (%s)\n", $event->getOccurredAt() ? $event->getOccurredAt()->format('c') : 'n/a', $event->getDescription(), $event->getCityLocality() ); }
The first argument accepts either a carrier code string ("usps", "fedex", "ups") or a
Carriers\CarrierCode value object. If the carrier is not connected to your account the call
throws Exception\ApiErrorResponse.
Information
Please visit https://www.shipengine.com/ for information regarding, and to sign up for the ShipEngine platform.
Please visit https://docs.shipengine.com/docs for ShipEngine's official API documentation.
This project is in no way associated to or endorsed by ShipEngine, ShipStation or any of their partners.
ShipEngine and ShipStation are registered trademarks. All rights reserved.
jsamhall/shipengine 适用场景与选型建议
jsamhall/shipengine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 577 次下载、GitHub Stars 达 5, 最近一次更新时间为 2017 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「shipstation」 「shipengine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jsamhall/shipengine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jsamhall/shipengine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jsamhall/shipengine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A php wrapper for ShipStation's rest api
A php wrapper for ship station's rest api
A Craft CMS plugin for integrating Craft Commerce with ShipStation
An updated and maintained PHP Wrapper for ShipStation's rest api, forked from michaelb/ship-station, docs @ https://shipstation.docs.apiary.io/
Wrapper around ShipEngine API
PHP library for the ShipEngine API.
统计信息
- 总下载量: 577
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-06