stack74/sdk-api-parcel-processing

GLS Web API for Parcel Processing SDK

1.1.0 2022-02-14 00:09 UTC

This package is auto-updated.

Last update: 2024-09-14 06:45:19 UTC


README

GLS包裹处理API SDK包提供了一个与以下网络服务的接口

  • GLS包裹处理Web API
  • GLS包裹取消Web API

要求

系统要求

  • PHP 7.1+带有JSON扩展

包要求

  • netresearch/jsonmapper:将JSON响应消息反序列化为PHP对象的映射器
  • php-http/discovery:HTTP客户端和消息工厂实现的发现服务
  • php-http/httplug:可插拔的HTTP客户端抽象
  • php-http/logger-plugin:HTTPlug的HTTP客户端记录插件
  • psr/http-client:PSR-18 HTTP客户端接口
  • psr/http-factory:PSR-7 HTTP消息工厂接口
  • psr/http-message:PSR-7 HTTP消息接口
  • psr/log:PSR-3记录接口

虚拟包要求

  • psr/http-client-implementation:任何提供PSR-18兼容HTTP客户端的包
  • psr/http-factory-implementation:任何提供PSR-7兼容HTTP消息工厂的包
  • psr/http-message-implementation:任何提供PSR-7 HTTP消息的包

开发包要求

  • nyholm/psr7:PSR-7 HTTP消息工厂和消息实现
  • phpunit/phpunit:测试框架
  • php-http/mock-client:HTTPlug模拟客户端实现
  • phpstan/phpstan:静态分析工具
  • squizlabs/php_codesniffer:静态分析工具

安装

$ composer require glsgroup/sdk-api-parcel-processing

卸载

$ composer remove glsgroup/sdk-api-parcel-processing

测试

$ ./vendor/bin/phpunit -c test/phpunit.xml

功能

GLS包裹处理API SDK支持以下功能

  • 创建带标签的运单
  • 取消包裹

创建运单

创建一个或多个包裹的运单并检索运单标签。每个包裹可以订购增值服务。可以单独请求退货标签(“仅退货”)或与常规的“运往”标签一起请求。

公共API

适用于消费的库组件包括

  • 服务
    • 服务工厂
    • 运单服务
    • 数据传输对象构建器
  • 数据传输对象
    • 带包裹的运单
  • 异常

用法

$logger = new \Psr\Log\NullLogger();
$serviceFactory = new \GlsGroup\Sdk\ParcelProcessing\Service\ServiceFactory();
$service = $serviceFactory->createShipmentService('basicAuthUser', 'basicAuthPass', $logger, $sandbox = true);

// REGULAR SHIPMENT
$requestBuilder = new \GlsGroup\Sdk\ParcelProcessing\RequestBuilder\ShipmentRequestBuilder();
$requestBuilder->setShipperAccount($shipperId = '98765 43210');
$requestBuilder->setRecipientAddress(
    $country = 'DE',
    $postalCode = '36286',
    $city = 'Neuenstein',
    $street = 'GLS-Germany-Straße 1 - 7',
    $name = 'Jane Doe'
);
$requestBuilder->addParcel($parcelWeightA = 0.95);
$requestBuilder->addParcel($parcelWeightB = 1.2);
$request = $requestBuilder->create();

$shipment = $service->createShipment($request);

// work with the web service response, e.g. persist label
foreach ($shipment->getLabels() as $i => $label) {
    file_put_contents("/tmp/{$shipment->getConsignmentId()}-{$i}.pdf", $label);
}

// RETURN SHIPMENT
$requestBuilder = new \GlsGroup\Sdk\ParcelProcessing\RequestBuilder\ReturnShipmentRequestBuilder();
$requestBuilder->setShipperAccount($shipperId = '98765 43210');
$requestBuilder->setShipperAddress(
    $country = 'DE',
    $postalCode = '36286',
    $city = 'Neuenstein',
    $street = 'GLS-Germany-Straße 1 - 7',
    $name = 'Jane Doe'
);
$requestBuilder->setRecipientAddress(
    $country = 'DE',
    $postalCode = '36286',
    $city = 'Neuenstein',
    $street = 'GLS Germany-Straße 1 - 7',
    $company = 'GLS Germany'
);
$requestBuilder->addParcel($weight = 0.95, $qrCode = true);
$request = $requestBuilder->create();

$shipment = $service->createShipment($request);

取消包裹

取消一个或多个包裹。

公共API

适用于消费的库组件包括

  • 服务
    • 服务工厂
    • 取消服务
  • 异常

用法

$logger = new \Psr\Log\NullLogger();
$serviceFactory = new \GlsGroup\Sdk\ParcelProcessing\Service\ServiceFactory();
$service = $serviceFactory->createCancellationService('basicAuthUser', 'basicAuthPass', $logger, $sandbox = true);

$cancelledIds = $service->cancelParcels([$parcelIdA = '12345', $parcelIdB = '54321']);