deliverea/deliverea-php

此包的最新版本(0.0.25)没有可用的许可信息。

此包的官方存储库似乎已消失,因此已将其冻结。

0.0.25 2018-07-23 08:34 UTC

README

Deliverea PHP API 库

这是用于与 Deliverea API 集成的官方库,目前处于测试阶段,因此如果您有任何想要贡献的bug或修复,请通过 Pull Requests 进行。

兼容性

安装

composer require deliverea/deliverea-php 0.0.9

方法

  • 获取客户承运商
  • 获取客户服务
  • 获取运输费率
  • 获取运输到货时间估计
  • 获取服务信息
  • 新建运输
  • 获取收集截止时间
  • 获取投放点
  • 新建收集
  • 获取运输标签
  • 获取运输
  • 获取运输
  • 获取运输跟踪

异常

使用这些异常的 try-catch 或简单地使用标准 \Exception 包装所有请求。

  • \Deliverea\Exception\CurlException
  • \Deliverea\Exception\ErrorResponseException
  • \Deliverea\Exception\UnexpectedResponseException

####示例

try {
    $deliverea->newShipment($shipment, 32, $address);
} catch (\Deliverea\Exception\CurlException $e) {

} catch (\Deliverea\Exception\ErrorResponseException $e) {

} catch (\Deliverea\Exception\UnexpectedResponseException $e) {

}

获取客户承运商

$delivereaClient->getClientCarriers();

获取客户服务

此方法中的所有参数都是可选的,状态可以是 0、1 或 null。

$delivereaClient->getClientServices(
    'Carrier Code',
    'Service Code',
    'Service Region',
    'Service Type',
    'Status'
);

获取运输费率

$delivereaClient->getShipmentsRates(
    new CountryCode('ES'),
    new ZipCode('08018'),
    new CountryCode('ES'),
    new ZipCode('07800'),
    new ParcelDimensions(2.0,1.0,1.0,1.0),
    new ParcelWeight(1.5)
);

获取运输到货时间估计

$delivereaClient->getShipmentTimeArrivalEstimation(
    new CountryCode('ES'),
    new ZipCode('08018'),
    new CountryCode('ES'),
    new ZipCode('07800'),
    new \DateTime()
);

获取服务信息

$delivereaClient->getServiceInfo(
    'Carrier Code',
    'Service Code',
    'From Country Code',
    'From Zip Code',
    'To Country Code',
    'To Zip Code'
);

新建运输

// Create API Client
$deliverea = new \Deliverea\Deliverea('apiuser', 'apisecret');


// Enable Sandbox
$deliverea->setSandbox(true);

// Create shipment
$shipment = new \Deliverea\Model\Shipment(1, substr(md5(strtotime('now')), 0, 14), new \DateTime(), 'custom',
    'ovirtual', 'ovirtual-servicio-19');

$fromAddress = new Address(
    'Full Name',
    'Address',
    'City',
    'Zip Code',
    'Country Code',
    'Phone'
);

$toAddress = new \Deliverea\Model\Address(
    'Full name',
    'Address',
    'City',
    'Zip Code',
    'Country Code',
    'Phone'
);

$shipment = $deliverea->newShipment($shipment, $fromAddress, $toAddress);

要添加特定承运商的参数,可以将其分配给对象本身。

$shipment->parcel_type = "DOCUMENTS";

获取收集截止时间

$cutoffHour = $this->delivereaClient->getCollectionCutoffHour([
            'zip_code' => '12345',
            'country_code' => 'ES',
            'service_code' => 'ovirtual-servicio-19',
            'carrier_code' => 'ovirtual'
        ]);

获取投放点

$deliverea->getDropPoints([
    'country_code' => 'ES',
    'zip_code' => '08018',
    'carrier_code' => 'mondialRelay',
]);

新建收集

// Create API Client
$deliverea = new \Deliverea\Deliverea('apiuser', 'apisecret');


// Create collection
$collection = new \Deliverea\Model\Collection(substr(md5(strtotime('now')), 0, 14), new \DateTime(),
    'ovirtual', 'ovirtual-servicio-19', '11:00', '16:00');

$fromAddress = new Address(
    'Full Name',
    'Address',
    'City',
    'Zip Code',
    'Country Code',
    'Phone'
);

$toAddress = new \Deliverea\Model\Address(
    'Full name',
    'Address',
    'City',
    'Zip Code',
    'Country Code',
    'Phone'
);

$collection = $deliverea->newCollection($collection, $fromAddress, $toAddress);

获取运输标签

$deliverea->getShipmentLabel('dlvrref');

获取运输

$deliverea->getShipment('dlvrref');

通过 API 中的筛选器获取运输(不包括跟踪事件)

$deliverea->getShipments([
    'filter_shipping_dlvr_ref' => 'dlvrref'
    ...
]);

获取运输跟踪

$deliverea->getShipmentTracking('dlvrref');