PHP code example of kitdelivery / sdk-kit-api

1. Go to this page and download the library: Download kitdelivery/sdk-kit-api 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/ */

    

kitdelivery / sdk-kit-api example snippets


$client = \service\KitAPI\Factory\SimpleClientFactory::createClient('https://capi.tk-kit.com', 'token');

$client->profile->getList();

$client = \service\KitAPI\Factory\SimpleClientFactory::createClient('https://capi.tk-kit.com', 'token');
$client->tdd->getListCity();

$client = \service\KitAPI\Factory\SimpleClientFactory::createClient('https://capi.tk-kit.com', 'token');
$client->tdd->getListCountry();



namespace Test;

use service\KitAPI\Factory\SimpleClientFactory;
use service\KitAPI\Interfaces\ApiExceptionInterface;
use service\KitAPI\Interfaces\ClientExceptionInterface;

onInterface $exception) {
    echo $exception;
    exit(-1);
}

foreach ($response->countries as $country) {
    printf("Название страны - '%s'. Код страны - '%s'", $country->name, $country->code);
    echo PHP_EOL;
}



namespace Test;

use service\KitAPI\Factory\SimpleClientFactory;
use service\KitAPI\Interfaces\ApiExceptionInterface;
use service\KitAPI\Interfaces\ClientExceptionInterface;
use service\KitAPI\Model\Entity\Geography\Phone;
use service\KitAPI\Model\Request\Geography\GetListAddressRequest;

oreach ($response->addreses as $address) {
    printf("ID адреса - %d. Адрес терминала - %s. ", $address->id, $address->value);
    if ($address->phone) {
        echo PHP_EOL;
        /** @var Phone $value */
        foreach ($address->phone as $value) {
            printf("Номер телефона - %s", $value->value);
            echo PHP_EOL;
        }
        echo PHP_EOL;
    }
}



namespace Test;

use service\KitAPI\Factory\SimpleClientFactory;
use service\KitAPI\Interfaces\ApiExceptionInterface;
use service\KitAPI\Interfaces\ClientExceptionInterface;
use service\KitAPI\Model\Entity\Order\Place;
use service\KitAPI\Model\Request\Order\CalculateRequest;

equest->places = [];

$place = new Place();
$place->height = 100;
$place->width = 60;
$place->length = 80;
$place->weight = 50;
$place->volume = round(1*0.6*0.8, 3);
$place->count_place = 1;
$place->service = ['S089'];

$request->places[] = $place;
$request->delivery = 1;
$request->pick_up = 0;
$request->insurance = 1;
$request->insurance_agent_code = '8000152423';
$request->have_doc = 1;
$request->cargo_type_code = '03';
$request->currency_code = ['RUB'];
$request->all_places_same = 1;

try {
    $response = $client->order->calculate($request);
} catch (ApiExceptionInterface|ClientExceptionInterface $exception) {
    echo $exception;
    exit(-1);
}

$result = $response->getResult();

printf("Тип доставки груза: %s", $result->standart->name);
echo PHP_EOL;
printf("Время доставки груза: %s", $result->standart->time);
echo PHP_EOL;
printf("Общая стоимость доставки груза: %s", $result->standart->cost);
echo PHP_EOL;
echo 'Детальная информация по стоимости доставки:';
echo PHP_EOL;
foreach ($result->standart->detail as $value) {
    printf("- услуга '%s', стоимостью %s рублей", $value->name, $value->price);
    echo PHP_EOL;
}