1. Go to this page and download the library: Download gam6itko/dpd-carrier 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/ */
gam6itko / dpd-carrier example snippets
use Gam6itko\DpdCarrier\Enum\OrderStatusName;
use Gam6itko\DpdCarrier\Enum\PaymentType;
use Gam6itko\DpdCarrier\Enum\ServiceCode;
use Gam6itko\DpdCarrier\Enum\ServiceVariant;
use Gam6itko\DpdCarrier\Type\Order\ClientAddress;
use Gam6itko\DpdCarrier\Type\Order\Header;
use Gam6itko\DpdCarrier\Type\Order\Order;
use Gam6itko\DpdCarrier\Type\Order\OrderStatus;
use Gam6itko\DpdCarrier\WebService\OrderWebService;
$svc = new OrderWebService('DPD_CLIENT_NUMBER', 'DPD_CLIENT_KEY', true); //switch 3rd argument to FALSE on production
// create order
$senderAddress = (new ClientAddress())
->setTerminalCode('M13')
->setName('ACME LTD')
->setContactFio('John Doe')
->setContactPhone('123 012 301 20 12');
$receiverAddress = (new ClientAddress())
->setName('John Lock')
->setContactFio('John Lock')
->setContactPhone('123456')
->setInstructions('fragile')
->setTerminalCode('OEL');
$pickupDate = new \DateTime('next month monday');
$header = (new Header())
->setDatePickup($pickupDate->format('Y-m-d'))
->setSenderAddress($senderAddress);
$order = (new Order())
->setOrderNumberInternal('gam6itko/dpd-carrier/' . uniqid())
->setServiceCode(ServiceCode::PCL)
->setServiceVariant(ServiceVariant::TerminalToTerminal)
->setCargoNumPack(1)
->setCargoWeight(10.23)
->setCargoValue(0.45)
->setCargoRegistered(true)
->setCargoCategory('something special')
->setPaymentType(PaymentType::Receiver)
->setReceiverAddress($receiverAddress);
$result = $svc->createOrder($header, $order);
print 'OrderStatus structure:' . PHP_EOL;
print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL . PHP_EOL;
use Gam6itko\DpdCarrier\Type\DeliveryOptions;
use Gam6itko\DpdCarrier\Type\DeliveryPoint;
use Gam6itko\DpdCarrier\WebService\CalculatorWebService;
// service cost calculation
$svc = new CalculatorWebService('DPD_CLIENT_NUMBER', 'DPD_CLIENT_KEY', true); //switch 3rd argument to FALSE on production
$pickup = new DeliveryPoint(49694102); // Москва
$delivery = new DeliveryPoint(195664561); //Рязань
$options = (new DeliveryOptions(true, true))
->setWeight(7.88)
->setVolume(0.04092)
->setDeclaredValue(34999);
$arrayOfServiceCost = $svc->getServiceCost2($pickup, $delivery, $options);
$serviceCostObject = $arrayOfServiceCost[0];
print 'ServiceCost structure:' . PHP_EOL;
print json_encode($serviceCostObject, JSON_PRETTY_PRINT);
use Gam6itko\DpdCarrier\Enum\ServiceCode;
use Gam6itko\DpdCarrier\Type\DeliveryPoint;
use Gam6itko\DpdCarrier\WebService\GeographyWebService;
$svc = new GeographyWebService('DPD_CLIENT_NUMBER', 'DPD_CLIENT_KEY', true); //switch 3rd argument to FALSE on production
//getCitiesCashPay
$arrayOfCity = $svc->getCitiesCashPay('RU'); //about 16868 elements
$cityObject = $arrayOfCity[0];
print 'City structure:' . PHP_EOL;
print json_encode($cityObject, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
//getParcelShops
$point = (new DeliveryPoint())
->setCountryCode('RU')
->setRegionCode(77);
$arrayOfParcelShop = $svc->getParcelShops($point); //about 179 elements
$parcelShop = $arrayOfParcelShop[0];
print 'ParcelShop structure:' . PHP_EOL;
print json_encode($parcelShop, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
//terminalsSelfDelivery2
$arrayOfTerminal = $svc->getTerminalsSelfDelivery2(); //about 159 elements
$terminal = $arrayOfTerminal[0];
print 'Terminal structure:' . PHP_EOL;
print json_encode($terminal, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
$tracingSvc = new TracingWebService('DPD_CLIENT_NUMBER', 'DPD_CLIENT_KEY'); // only prod
do {
$stateParcels = $tracingSvc->getStatesByClient();
if ($stateParcels->getDocId() === 0 || null === $stateParcels->getStates()) {
return;
}
// processing $stateParcels
// говорим DPD, что обработали эти статусы
$tracingSvc->confirm($stateParcels->getDocId());
//Показывает, выбраны ли в текущем запросе все новые состояния по клиенту (значение true),
// или был достигнут лимит записей в одном запросе и для продолжения необходим ещё один запрос (значение false)
} while (empty($stateParcels->isResultComplete()));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.