PHP code example of devmakis / cdek-api-2.0
1. Go to this page and download the library: Download devmakis/cdek-api-2.0 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/ */
devmakis / cdek-api-2.0 example snippets
$client = new Psr18Client();
$cdek = new \CdekSDK2\Client($client);
$cdek->setAccount('account');
$cdek->setSecure('secure');
// создание заказа
$order = \CdekSDK2\Params\OrderParams::create([...]);
$res = $cdek->orders()->create($order);
if ($res->hasErrors()) {
// Обрабатываем ошибки
foreach ($res->getErrors() as $error) {
//считываем ошибки
}
}
if ($res->isOk()) {
$cdek_order = $cdek->formatResponse($res, \CdekSDK2\Dto\EntityDto::class);
// $cdek_order->entity->uuid;
}
// получение информации о заказе
$res = $cdek->orders()->get($cdek_order->entity->uuid);
if ($res->isOk()) {
$cdek_order = $cdek->formatResponse($res, \CdekSDK2\Dto\OrderDto::class);
}
//получить список офисов
$res = $cdek->offices()->getFiltered(['country_code' => 'kz']);
if ($res->isOk()) {
$pvzlist = $cdek->formatResponseInClass($res, \CdekSDK2\Dto\PickupPointList::class);
// $pvzlist->items;
}