PHP code example of kskby / dpd

1. Go to this page and download the library: Download kskby/dpd 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/ */

    

kskby / dpd example snippets



$config = new \Ipol\DPD\Config\Config([
    'KLIENT_NUMBER_BY'   => '...',
    'KLIENT_KEY_BY'      => '...',
    'KLIENT_CURRENCY'    => 'BYN',
    'KLIENT_CURRENCY_BY' => 'BYN',
    'API_DEF_COUNTRY'    => 'BY',
    'IS_TEST'            => true,
]);

$config = new \Ipol\DPD\Config\Config([
    // параметры авторизации
]);

$shipment = new \Ipol\DPD\Shipment($config);

// города отправления и назначения (должны быть в БД)
$shipment->setSender('Беларусь', 'Гомельская', 'г. Гомель');
$shipment->setReceiver('Беларусь', 'Минская', 'г. Минск');

// от терминала / до двери
$shipment->setSelfPickup(true);
$shipment->setSelfDelivery(false);

$goods = [
    [
        'NAME'       => 'Название товара',
        'QUANTITY'   => 1,
        'PRICE'      => 1000,
        'VAT_RATE'   => 'Без НДС',
        'WEIGHT'     => 1000, // граммы
        'DIMENSIONS' => [
            'LENGTH' => 100, // мм
            'WIDTH'  => 200,
            'HEIGHT' => 200,
        ],
    ],
];

$shipment->setItems($goods, 1000);

// опционально: тип плательщика и платёжная система (для НПП / комиссий)
$shipment->setPaymentMethod(1, 1);

$calc = $shipment->calculator();

// оптимальный тариф
$tariff = $calc->calculate();

// конкретный тариф
$tariff = $calc->calculateWithTariff('PCL');

class Converter implements \Ipol\DPD\Currency\ConverterInterface
{
    // реализация
}

$tariff = $calc
    ->setCurrencyConverter(new Converter())
    ->calculate('USD');

$config = new \Ipol\DPD\Config\Config([
    // ...
]);

$shipment = new \Ipol\DPD\Shipment($config);
// параметры отправления...

$order = \Ipol\DPD\DB\Connection::getInstance($config)->getTable('order')->makeModel();
$order->orderId = 'Внешний код заказа';
$order->setShipment($shipment);

$order->serviceCode = 'PCL';
// или вручную: $order->serviceVariant = ['SELF_PICKUP' => true, 'SELF_DELIVERY' => false];

$order->pickupDate = '2026-08-06';
$order->pickupTimePeriod = '9-18';

$order->senderName = 'Наименование отправителя';
$order->senderFio = 'ФИО отправителя';
$order->senderPhone = 'Телефон отправителя';
$order->senderTerminalCode = 'Код терминала отправления';

$order->receiverName = 'Наименование получателя';
$order->receiverFio = 'ФИО получателя';
$order->receiverPhone = 'Телефон получателя';
$order->receiverStreet = 'Улица';
$order->receiverStreetabbr = 'ул.';
$order->receiverHouse = 'дом';
$order->receiverComment = 'инструкция для курьера';

$result = $order->dpd()->create();

// $order->dpd()->cancel();
// $order->dpd()->checkStatus();
// $order->dpd()->getLabelFile();
// $order->dpd()->getInvoiceFile();

$orderId = 1;
$order = \Ipol\DPD\DB\Connection::getInstance($config)->getTable('order')->getByOrderId($orderId);
$order->dpd()->cancel();

$orderTable    = \Ipol\DPD\DB\Connection::getInstance($config)->getTable('order');
$locationTable = \Ipol\DPD\DB\Connection::getInstance($config)->getTable('location');
$terminalTable = \Ipol\DPD\DB\Connection::getInstance($config)->getTable('terminal');

$items = $terminalTable->find([
    'where' => 'NPP_AVAILABLE = "Y"',
])->fetchAll();

// dpd-check-status.php
$config = new \Ipol\DPD\Config\Config([
    // параметры
]);

\Ipol\DPD\Agents::checkOrderStatus($config);

$data = [
    'PARAM1' => 'Параметр 1',
    'PARAM2' => [
        'SUB1' => 'п 2.1',
        'SUB2' => 'п 2.2',
    ],
];

$convertData = \Ipol\DPD\Utils::convertEncoding($data, 'windows-1251', 'UTF-8');