jsamhall / shipengine
ShipEngine v1 API访问和交互的PHP包装器。
1.0.1
2021-11-03 16:05 UTC
Requires
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2024-09-21 13:21:03 UTC
README
ShipEngine v1 API访问和交互的PHP包装器。
尽管该包对于我的需求来说是功能性的,但并未积极维护。请自行决定是否使用。
如何使用
$addressFormatter = new Acme\AddressFormatter; // implements Address\FormatterInterface $shipEngine = new jsamhall\ShipEngine\ShipEngine('your_shipengine_api_key', $addressFormatter); $carriers = $shipEngine->listCarriers();
示例
实现快速开始示例的最小示例
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);
地址
ShipEngine期望特定的地址格式。此库提供了符合该格式的Address\Address类。所有需要地址作为请求部分的方法(例如,验证、评分、标签等)都期望使用Address\Address以确保一致性和兼容性。
您应该编写一个实现Address\FormatterInterface,该接口从您领域特定的地址中提取数据,并符合ShipEngine API期望的格式。这个实现是Address\Factory类的构造函数参数,它将您的领域地址模型转换为Address\Address实例。
此格式化程序在jsamhall\ShipEngine实例的公共接口中可用。
/** @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
信息
请访问https://www.shipengine.com/获取有关ShipEngine平台的信息并注册。
请访问https://docs.shipengine.com/docs获取ShipEngine官方API文档。
此项目与ShipEngine、ShipStation或其任何合作伙伴没有任何关联或支持。
ShipEngine和ShipStation是注册商标。保留所有权利。