sergeevpasha/laravel-dellin

Laravel 的 Dellin API 包装器

v1.6.0 2024-07-21 08:07 UTC

README

Maintainability Test Coverage CodeFactor Generic badge Generic badge

Laravel Dellin API 包装器

允许您

  • 通过查询字符串查找城市
  • 通过城市 ID 和查询字符串查找街道
  • 通过城市 ID 查找城市内的终点站
  • 计算配送

先决条件

您需要获取 Dellin API 密钥、登录名和密码。密钥可以在 https://dev.dellin.ru/registration 获取

安装

composer require sergeevpasha/laravel-dellin

配置

此软件包有一些配置值

'key'        => env('DELLIN_KEY', null),
'login'      => env('DELLIN_LOGIN', null),
'password'   => env('DELLIN_PASSWORD', null),
'prefix'     => 'dellin',
'middleware' => ['web']

如果您只需要使用 DellinClient,您可以完全跳过此配置。否则,您可以使用默认选项并在 .env 文件中指定一些数据

  • DELLIN_KEY
  • DELLIN_LOGIN
  • DELLIN_PASSWORD

为了充分利用预定义的路由,您需要发布配置

php artisan vendor:publish --provider="SergeevPasha\Dellin\Providers\DellinServiceProvider" --tag="config"

现在您可以根据需要更改路由前缀和中间件

用例 #1

安装后,您可以简单地导入客户端

use SergeevPasha\Dellin\Libraries\DellinClient;

首先,让我们初始化我们的客户端

$client = new DellinClient('key');
/* 
    You may also authorize your user and get a session ID.
    You may use it in getPrice() method to adjust prices (Authorized users have lower prices)
*/
$session = client->authorize('login', 'password);

现在我们可以使用这些方法

$client->findCity(string $query)
$client->findCityStreet(int $city, string $query)
$client->getCityTerminals(int $city, bool $arrival = true)
/* This one requires a Delivery Object, see next to see how to build it */
$client->getPrice(Delivery $delivery)

配送对象

要构建配送对象,您需要将数组传递给 fromArray() 方法,就像这样

Delivery::fromArray([
    'session_id'             => '12345', // User Session ID, Not required
    'delivery_type'          => '1', // Delivery Type, see available Delivery Types below
    'arrival_shipping_type'  => '1', // Shipping Type, see available Shipping Types below
    /* Only one of the following is required */
    'arrival_terminal_id'    => '123'
    'arrival_address_id'     => '123'
    'arrival_street_code'    => '123'
    'arrival_city_code'      => '123'
    /* --- */
    /* Next lines are NOT required */
    'arrival_worktime_start' => '12:30', // Time format HH:MM
    'arrival_worktime_end'   => '13:00',
    'arrival_break_start'    => '15:30',
    'arrival_break_end'      => '16:00',
    'arrival_exact_time'     => '1', // Boolean flag to show that there should be an exact time pickup a cargo
    'arrival_freight_lift'   => '1', // Boolean flag, specify if there is a lift on arrival location
    'arrival_to_floor'       => '10', // Floor level to deliver
    'arrival_carry'          => '100', // Meters to deliver
    'arrival_requirements'   => [
        '0x92fce2284f000b0241dad7c2e88b1655',
    ], // You can get these codes from getSpecialRequirements() method
    'derival_produce_date'   => '2020-10-10' // Date, when this order should be done (YYYY-MM-DD)
    /* Below are the same specs, but for the derival */
    'derival_shipping_type'  => '1', // Shipping Type, see available Shipping Types below
    'derival_terminal_id'    => '123'
    'derival_address_id'     => '123'
    'derival_street_code'    => '123'
    'derival_city_code'      => '123'
    'derival_worktime_start' => '12:30', // Time format HH:MM
    'derival_worktime_end'   => '13:00',
    'derival_break_start'    => '15:30',
    'derival_break_end'      => '16:00',
    'derival_exact_time'     => '1', // Boolean flag to show that there should be an exact time pickup a cargo
    'derival_freight_lift'   => '1', // Boolean flag, specify if there is a lift on arrival location
    'derival_to_floor'       => '10', // Floor level to deliver
    'derival_carry'          => '100', // Meters to deliver
    'derival_requirements'   => [
        '0x92fce2284f000b0241dad7c2e88b1655',
    ]
    'packages'               => [
        '0x838fc70baeb49b564426b45b1d216c15'
    ], // You can get these codes from getAvailablePackages() method
    'ac_docs_send'           => '1', // Boolean flag to send accompanying documents
    'ac_docs_return'         => '1', // Boolean flag to return accompanying documents
    'requester_role'         => '1', // Requester Role, see available Requester Roles below
    'requester_uid'          => 'xxxx-xxxx' // Who is ordering delivery. You can get this UID from getCounterparties() method
    'cargo_quantity'         => '1', // Amount of packages to ship
    'cargo_length'           => '10', // Max package Length in Meters
    'cargo_height'           => '10', // Max package Height in Meters
    'cargo_width'            => '10', // Max package Width in Meters
    'cargo_weight'           => '10', // Weight in KG
    'cargo_total_volume'     => '0.05, // Volume in M3
    'cargo_total_weight'     => '10', // Total Weight in KG
    /* Next lines are NOT required */
    'cargo_oversized_weight' => '10', // Total Weight of oversized packages
    'cargo_oversized_volume' => '10', // Total Volume of oversized packages
    /* Only one is required */
    'cargo_freight_uid'      => 'xxxx-xxx', // Freight UID
    'cargo_freight_name'     => 'mybook', // Freight Name
    /* --- */
    'cargo_hazard_class'     => '1.1' // Cargo hazard level. Default and recommended is 0, unsless you know what you are doing
    'insurance_value'        => '100000', // Insurance value
    'insurance_term'         => '1', // Boolean flag, that specifies that you need to insure delivery time too
    'payment_city'           => '7700000000000000000000000' // KLADR Code of payment city
    'payment_type'           => '1', // Payment type, see below
])

可用的配送类型

    AUTO = 0
    EXPRESS = 1
    LETTER = 2
    AVIA = 3
    SMALL = 4

可用的支付类型

    CASH = 0
    NONCASH = 1

可用的请求者角色

    SENDER = 0
    RECEIVER = 1
    PAYER = 2
    THIRD = 3

可用的运输类型

    ADDRESS = 0
    TERMINAL = 1

用例 #2

有一些预定义的路由,将合并到您的路由中。您可以通过使用 php artisan routes:list 检查它。它实际上暴露了相同的方法给路由,所以应该很清楚如何使用它。有关如何使用的更多信息,请参阅 src/ 文件夹。