PHP code example of ashirchkov / yandex-logistics

1. Go to this page and download the library: Download ashirchkov/yandex-logistics library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ashirchkov / yandex-logistics example snippets

 php
 

nt = new GuzzleHttp\Client();
$apiKey = '<your API-key>';
$testMode = true; // Если установлен true, запросы будут отправляться к тестовому API сервису Yandex

$apiClient = new AlexeyShirchkov\Yandex\Logistics\Client($psr18Client, $apiKey, $testMode); 
 php
$params = [
    'tariff' => 'self_pickup',
    'source' => [
        'platform_station_id' => '4eb18cc4-329d-424d-a8a8-abfd8926463d',
    ],
    'destination' => [
        'platform_station_id' => '0530d1b2-58be-4dba-8d69-3fb86fd61c9c',
    ],
    'total_assessed_price' => 100000,
    'total_weight' => 1000,
]

$response = $apiClient->anotherDay()->calculate()->calculatePrice($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$stationId = '4eb18cc4-329d-424d-a8a8-abfd8926463d';

$params = [
    'self_pickup_id' => '0530d1b2-58be-4dba-8d69-3fb86fd61c9c',
    'send_unix' => true,
];

$response = $apiClient->anotherDay()->calculate()->calculateIntervals($stationId, $params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$response = $apiClient->anotherDay()->location()->getGeoIdByAddress('Москва');

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$params = [
    'type' => 'terminal',
];

$response = $apiClient->anotherDay()->location()->getPointList($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$params = [
    'info' => [
        'operator_request_id' => '1234',
    ],
    'recipient_info' => [
        'first_name' => 'Иван',
        'phone' => '+79999999999',
    ],
    'billing_info' => [
        'payment_method' => 'already_paid',
    ],
    'source' => [
        'platform_station' => [
            'platform_id' => '4eb18cc4-329d-424d-a8a8-abfd8926463d',
        ],
    ],
    'destination' => [
        'type' => 'platform_station',
        'platform_station' => [
            'platform_id' => '0530d1b2-58be-4dba-8d69-3fb86fd61c9c',
        ],
    ],
    'places' => [
        [
            'barcode' => '1234567890',
            'physical_dims' => [
                'predefined_volume' => 100,
                'weight_gross' => 1000,
            ],
        ],
    ],
    'items' => [
        [
            'name' => 'Ручка шариковая (цвет синий)',
            'count' => 5,
            'article' => 'a123456',
            'billing_details' => [
                'assessed_unit_price' => 10000,
                'unit_price' => 10000,
            ],
            'place_barcode' => '1234567890',
        ],
        [
            'name' => 'Ручка шариковая (цвет красный)',
            'count' => 5,
            'article' => 'a654321',
            'billing_details' => [
                'assessed_unit_price' => 20000,
                'unit_price' => 20000,
            ],
            'place_barcode' => '1234567890',
        ],
    ],
    'last_mile_policy' => 'self_pickup',
];

$response = $apiClient->anotherDay()->order()->createOrder($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$offerId = '<your offer_id>'; // offer_id, полученный после выполнения createOrder

$response = $apiClient->anotherDay()->order()->confirmOrder($offerId);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$response = $apiClient->anotherDay()->order()->getOrder($requestId);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$params = [
    'from' => (new DateTime('today'))->getTimestamp(),
    'to' => (new DateTime('tomorrow'))->getTimestamp(),
];

$response = $apiClient->anotherDay()->order()->getOrders($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$params = [
    'recipient_info' => [
        'name' => 'Пётр'
    ]
];

$response = $apiClient->anotherDay()->order()->editOrder($requestId, $params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$params = [
    'destination' => [
        'type' => 'platform_station'
    ],
];

$response = $apiClient->anotherDay()->order()->redeliveryOrder($requestId, $params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$response = $apiClient->anotherDay()->order()->orderStatusHistory($requestId);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$response = $apiClient->anotherDay()->order()->cancelOrder($requestId);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$requestIds = [
    '<your request_id>' // список request_id, полученных после выполнения confirmOrder
];

$response = $apiClient->anotherDay()->label()->generateLabels($requestIds);

if ($response->isSuccess()) {
    file_put_contents(__DIR__ . '/labels.pdf', $response->getResult());
} else {
    var_dump($response->getErrors());
}
 php
$params = [
    'request_ids' => [
        '<your request_id>' // список request_id, полученных после выполнения confirmOrder
    ]
]

$response = $apiClient->anotherDay()->label()->getHandoverAct($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}