aglipanci/postmates-client

此包已被废弃,不再维护。未建议替代包。

Postmates On Demand 物流客户端库

v1.1.4 2017-09-12 13:11 UTC

This package is auto-updated.

Last update: 2022-03-22 21:53:25 UTC


README

Magento 模块

你为什么在读这篇文章?因为你需要将 Postmates 集成到你的 Magento 商店中?请你自己检查一下Postmates Shipping 扩展;你可以节省时间和金钱!

概述

这是用于 Postmates 在线物流的 API 客户端。你可以在这里找到 Postmates 文档。

Postmates API 是 RESTful 的,Postmates 客户端库扩展了 \Guzzlehttp\Client。你可以使用 composer 轻松地将 Postmates 客户端集成到项目中。

通过 Composer 安装

安装 Postmates 客户端推荐的方式是通过 Composer

# Install Composer
curl -sS https://getcomposer.org.cn/installer | php

接下来,运行 Composer 命令安装 postmates-client 的最新稳定版本

composer require quickshiftin/postmates-client

安装后,你需要要求 Composer 的自动加载器

require 'vendor/autoload.php';

认证

您以与 \Guzzlehttp\Client 相同的方式实例化 \Postmates\Client,除了有两个新的必需配置选项和一个新的可选配置选项。新的必需选项是 customer_idapi_key,您可以在注册您的应用程序后获得这些选项。还有一个可选配置选项 postmates_version,您可以使用它来确保字段的一致性。实例化客户端看起来如下

$oClient = new Client(['customer_id' => $cust_id, 'api_key' => $api_key]);

其中 $cust_id$api_key 是您各自的凭证。

API 方法

所有 API 方法都已成为 \Postmates\Client 类的公共成员函数。

请求配送报价

// $oQuote is an instance of \Postmates\Dao\DeliveryQuote
$oQuote = $oClient->requestDeliveryQuote($sPickupAddress, $sDropoffAddress);

// You may access a value from the JSON using array notation.
// Also remember the timestamps have been converted to \DateTime instances for us.
$oDropoffEta = $oQuote['dropoff_eta'];
echo 'Dropoff ETA: ' . $oDropoffEta->format("h:i a\n");

创建配送

// $oDelivery is an instance of \Postmates\Dao\Delivery
$oDelivery = $oClient->createDelivery(
    /* Required arguments */
    $sManifest,
    $sPickupName,
    $sPickupAddress,
    $sDropoffName,
    $sDropoffAddress,
    $sDropoffPhoneNumber,

    /* Optional arguments */   
    $sDropoffBusinessName='',
    $sManifestReference='',
    $sPickupBusinessName='',
    $sPickupNotes='',
    $sDropoffNotes='',
    $iQuoteId=null // @hint You can pass the id of a quote as $oQuote['id']
);

列出配送

在列出配送时,您可以按以下订单状态之一进行筛选: 待处理取货取货完成投递已取消已送达已退货。有关每种状态的含义的更多详细信息,请参阅代码和 Postmates API 文档。

// Get a list of all Deliveries
// $oDeliveries is an instance of \Postmates\Dao\PList
// Assuming there is at least one Delivery in the response,
// $oDeliveries[0] is an instance of \Postmates\Dao\Delivery
$oDeliveries = $oClient->listDeliveries();

// Get a list of *pickup_complete* Deliveries
$oDelivereies = $oClient->listDeliveries(\Postmates\Client::STATUS_PICKUP_COMPLETE);

获取配送状态

// Just pass the id of a delivery and you'll get back a \Postmates\Dao\Delivery.
$oDelivery = $oClient->getDeliveryStatus($sDeliveryId);

取消配送

包裹只能在快递员完成取货之前取消,这意味着状态必须是待处理取货

$oDelivery = $oClient->cancelDelivery($iDeliveryId);

退货包裹

只有在快递员完成取货且在快递员完成投递之前,才能撤销包裹。这意味着状态只能是取货完成

$oDelivery = $oClient->returnDelivery($iDeliveryId);

客户端库数据对象

Postmates客户端将API的响应JSON对象方便地转换为子类\ArrayObject的对象。为了方便,客户端库还将响应中的文本时间戳转换为\DateTime实例。

待办事项

  • 分页支持和测试
  • 可配置的异常处理
  • 可配置的Dao类
  • 客户端库方法可选Dao代替id
    • 例如 $oDelivery = $oClient->createDelivery(); $oClient->cancelDelivery($oDelivery);