cpapdotcom / asendia
与Asendia (asendia.com)交互的客户端
Requires
- php: >=5.4
This package is auto-updated.
Last update: 2024-09-12 00:24:21 UTC
README
提供与Asendia的集成。
要求
- PHP 5.4+
安装
使用Composer
$> composer require cpapdotcom/asendia
在早期开发阶段,可能需要更具体的要求
$> composer require cpapdotcom/asendia:^0.0@dev
PSR-4或PSR-0自动加载
配置PSR-4以在src/Cpapdotcom/Asendia
中查找,命名空间前缀为Cpapdotcom\Asendia\
。对于PSR-4,尾部\
非常重要。
配置PSR-0以在src/
中查找类。根据PSR-0实现,命名空间前缀可能设置为Cpapdotcom\Asendia
。
独立
此包包含由Aura提供的独立PSR-4自动加载器。要求从这个包的根目录加载autoload.php
以使此包中的所有类都可用于应用程序。
require_once '/path/to/cpapdotcom-asendia/autoload.php';
基本Manifest使用
Manifest是Asendia全球eFile XML数据导入规范的程序表示。最终结果是创建一个Simple XML Element实例,该实例可由Asendia Web API客户端消费。
Cpapdotcom\Asendia\Manifest
类是Manifest原始类型和工具的代理,用于将Manifest\Manifest
实例和属性集合转换为Simple XML元素。其任务是简化这些任务
为账户创建Manifest
为时间戳创建带有当前日期和时间的Manifest\Manifest
。
use Cpapdotcom\Asendia\Manifest; $manifest = Manifest::createManifestForAccount( $accountNumber, $companyName );
为时间戳创建特定日期和时间的Manifest\Manifest
。
use Cpapdotcom\Asendia\Manifest; $manifest = Manifest::createManifestForAccount( $accountNumber, $companyName, new DateTime('yesterday') );
创建包
创建Manifest\Package
。
use Cpapdotcom\Asendia\Manifest; $package = Manifest::createPackageWithPckId($pckId);
创建项目
创建Manifest\Item
。
use Cpapdotcom\Asendia\Manifest; $package = Manifest::createItemForPackageWithItemId($itemId);
从Manifest创建Simple XML Element
use Cpapdotcom\Asendia\Manifest; $element = Manifest::createXmlFromManifest($manifest);
从属性集合创建Simple XML Element
use Cpapdotcom\Asendia\Manifest; $element = Manifest::createXmlFromProperties($properties);
示例
use Cpapdotcom\Asendia\Manifest; $manifest = Manifest::createManifestForAccount( '123456789012345', 'Your Company Name' ) ->withPackage(Manifest::createPackageWithPckId('BW00709000019') ->withOrderId('89105221002001100217') ->withLastName('Doe') ->withFirstName('Jane') ->withMiddleInitial('S') ->withAddressLines([ '17 Robilliard Way', ]) ->withCity('Sebastopol') ->withProvince('Bonshaw') ->withPostalCode('3356') ->withCountryCode('AU') //->withPhone() //->withEmail() ->withPckWeight('3.58') ->withPckType('M') ->withServiceType('PAR') ->withPckDescription('Clothing') ->withShippingCost('20.21') ->withDutyTaxHandling('10.83') ->withCustomsBarCode('LM473124829US') ->withItem(Manifest::createItemForPackageWithItemId('2929840') ->withItemDescription('Shirt') ->withCustomsDescription('Shirt') ->withQuantity(1) ->withUnitPrice('10.00') ->withCountryOfOrigin('US') ->withHTSNumber('123456789') ) ->withItem(Manifest::createItemForPackageWithItemId('2929841') ->withItemDescription('Pants') ->withCustomsDescription('Pants') ->withQuantity(2) ->withUnitPrice('15.00') ->withCountryOfOrigin('US') ->withHTSNumber('987654321') ) ) ->withPackage(Manifest::createPackageWithPckId('BW00709012345') ->withOrderId('89105221002001100217') ->withLastName('Smith') ->withFirstName('John') ->withMiddleInitial('Q') ->withAddressLines([ '28A CLIFTON ST', 'Apartment 203', ]) ->withCity('CAMPBELLTOWN') ->withProvince('SYDNEY') ->withPostalCode('2560') ->withCountryCode('AU') ->withPhone('jsmith@gmail.com') //->withEmail() ->withPckWeight('1.25') ->withPckType('S') ->withServiceType('PAR') ->withPckDescription('Clothing') //->withShippingCost() //->withDutyTaxHandling() ->withCustomsBarCode('LM473124829US') ->withItem(Manifest::createItemForPackageWithItemId('123456789') ->withItemDescription('Pants') ->withCustomsDescription('100% cotton') ->withQuantity(1) ->withUnitPrice('25.00') ->withCountryOfOrigin('US') //->withHTSNumber() ) ) ; // $manifestAsXml = Manifest::createXmlFromManifest($manifest);
基本Asendia Web API客户端使用
创建Asendia Web API客户端
使用生产WSDL URI从登录名和密码创建Asendia Web API客户端。
use Cpapdotcom\Asendia\WebApiClient\Adapter\Soap\SoapAsendiaWebApiClient; $asendia = SoapAsendiaWebApiClient::fromCredentialsAndProductionWsdl( $login, $password );
使用测试WSDL URI从登录名和密码创建Asendia Web API客户端。
use Cpapdotcom\Asendia\WebApiClient\Adapter\Soap\SoapAsendiaWebApiClient; $asendia = SoapAsendiaWebApiClient::fromCredentialsAndTestingWsdl( $login, $password );
使用指定的WSDL URI从登录名和密码创建Asendia Web API客户端。
use Cpapdotcom\Asendia\WebApiClient\Adapter\Soap\SoapAsendiaWebApiClient; $asendia = SoapAsendiaWebApiClient::fromCredentialsAndWsdl( $login, $password, $wsdl );
示例:如何从当前环境的WSDL URI使用登录名和密码创建Asendia Web API客户端。
use Cpapdotcom\Asendia\WebApiClient\Adapter\Soap\SoapAsendiaWebApiClient; $asendia = SoapAsendiaWebApiClient::fromCredentialsAndWsdl( $login, $password, $env === 'production' ? SoapAsendiaWebApiClient::PRODUCTION_WSDL : SoapAsendiaWebApiClient::TESTING_WSDL );
创建发货
$createdShipment = $asendia->createShipment(); echo $createdShipment->getStatus()."\n"; // should be 'open' echo $createdShipment->getShipment()."\n"; // the number for the newly created shipment
将包裹添加到发货中
$addedShipmentPackages = $asendia->addPackagesToShipment( $shipmentNumber, $manifest, AsendiaWebApiClient::LABEL_TYPE_PDF ); echo $addedShipmentPackages->getShipment()."\n"; // the number for the shipment foreach ($addedShipmentPackages->getPackages() as $package) { echo $package->getPckId()."\n"; // the PckId echo $package->getLabelFile()."\n"; // get the filename for the label }
关闭发货
$closedShipment = $asendia->closeShipment($shipmentNumber); echo $closedShipment->getShipment()."\n"; // the number of the shipment echo $closedShipment->getStatus()."\n"; // should be 'closed'
检索PDF标签
$pdfLabel = $asendia->retrieveLabelAsPdf($filename); echo $pdfLabel->getLabelFile()."\n"; // the filename of the label echo $pdfLabel->getEncodedContent()."\n"; // the base64 encoded content echo $pdfLabel->getContent()."\n"; // the base64 decoded content (binary/raw) $pdfLabel->writeContentToFile('/path/to/whatever.pdf'); // writes content to file
检索JPEG标签
$jpegLabel = $asendia->retrieveLabelAsJpeg($filename); echo $jpegLabel->getLabelFile()."\n"; // the filename of the label echo $jpegLabel->getEncodedContent()."\n"; // the base64 encoded content echo $jpegLabel->getContent()."\n"; // the base64 decoded content (binary/raw) $jpegLabel->writeContentToFile('/path/to/whatever.jpg'); // writes content to file
检索PNG标签
$pngLabel = $asendia->retrieveLabelAsPng($filename); echo $pngLabel->getLabelFile()."\n"; // the filename of the label echo $pngLabel->getEncodedContent()."\n"; // the base64 encoded content echo $pngLabel->getContent()."\n"; // the base64 decoded content (binary/raw) $pngLabel->writeContentToFile('/path/to/whatever.png'); // writes content to file
许可证
MIT,请参阅LICENSE。