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