foodkit/lalamove-php-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

foodkit/lalamove-php-api

最新稳定版本:4.0.0

Composer 安装命令:

composer require foodkit/lalamove-php-api

包简介

PHP client for the Lalamove API

README 文档

README

CircleCI

This provides a PHP wrapper around the Lalamove API (v2 and v3). Currently supports PHP >= 7.4|8.1

Built and maintained by Foodkit.

Running the tests

$ ./vendor/bin/phpunit tests/
PHPUnit 9.5.19 #StandWithUkraine

...............................................                   47 / 47 (100%)

Time: 00:09.259, Memory: 10.00 MB

OK (47 tests, 142 assertions)

Using the library

<?php

$settings = new \Lalamove\Client\V3\Settings(
    'https://sandbox-rest.lalamove.com',
    'API_KEY',
    'API_SECRET',
    \Lalamove\Client\V3\Settings::COUNTRY_SINGAPORE // country
);

$client = new Lalamove\Client\V3\Client($settings);

//////
// Create a quote:
$quotation = new \Lalamove\Requests\V3\Quotation(/* parameters here */);

// ...prepare the quotation object...
$quotationResponse = $client->quotations()->create($quotation);

// Get quotation by id
$quotationDetailsResponse = $client->quotations()->get($quotation->quotationId);

//////
// Create an order
// Provide the quotationID and stopId received from create quote and add contact information for both the sender and recipients
$contact = new \Lalamove\Requests\V3\Contact('Contact Name', '+65991111110', 'stop_id_from_quotation');

// recipient contact and instruction per stop
$recipients = [
    [
        'stopId' => 'stop_id_1',
        'name' => 'name',
        //  Must be a valid number with region code (ex: +65)
        'phone' => '+65991111111',
    ], [
        'stopId' => 'stop_id_2',
        'name' => 'name',
        //  Must be a valid number with region code (ex: +65)
        'phone' => '+65991111112',
    ]
];

$order = new \Lalamove\Requests\V3\Order($quotationId, $sender, $recipients);
$orderResponse = $client->orders()->create($order);

// Fetch order details:
$details = $client->orders()->details($orderResponse->orderId);

// Get the driver:
// driverId from create order or by order details response
$driver = $client->drivers()->get($details->orderId, $details->driverId);

// Cancel the order:
$details = $client->orders()->cancel($orderResponse->orderId);

//////
// Create a webhook
$webhook = new \Lalamove\Requests\V3\Webhook('https://webhook.site/fd8ccc58-7447-4122-8a0c-f9c31eb79ad3');
$webhook = $client->webhooks()->create($webhook));

Errors

The client library will throw exceptions in the case of request (or server) errors.

try {
    $client->orders()->create($order);
} catch (\Lalamove\Exceptions\PaymentRequiredException $ex) {
    echo 'Error: not enough funds in Lalamove wallet to create the order';
}

You can handle these independently (see exceptions in src/Exceptions/), or just catch the supertype Lalamove\Exceptions\LalamoveException to handle all failure cases.

try {
    $client->orders()->create($order);
} catch (\Lalamove\Exceptions\LalamoveException $ex) {
    echo "Error: I don't know what happened, but the request failed for some reason.";
}

Contributing

Open a PR against master. Please use PSR-x conventions for everything and include tests.

Design goals

  • Lean on the IDE. We should leverage the IDE (autocompletion) to help the developer to use the library.
  • Hide the transport mechanism (HTTP) as much as possible. Except when absolutely necessary (e.g endpoint configuration, request timeouts), the end user should not be worried about HTTP concepts when using the library.
  • Interface should be pleasant/unobtrusive to use. The library should remove as much friction from the development process as possible.

License

See LICENSE.

统计信息

  • 总下载量: 5.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-24