Skip to content

Latest commit

 

History

History
157 lines (115 loc) · 3.62 KB

README.md

File metadata and controls

157 lines (115 loc) · 3.62 KB

php-dpd-api

Set of PHP classes to handle API of courier services (DPD Poland)

Build Status License

Installation

composer require msztorc/php-dpd-api

or

git clone https://github.com/msztorc/php-dpd-api.git

of course you can also download zip file, unpack and include to your project

Configuration file

Main configuration is located in config.php file

'fid' => '1495',
'username' => 'test', // username for api calls
'password' => 'KqvsoFLT2M', // password for api calls
'wsdl' => 'https://dpdservicesdemo.dpd.com.pl/DPDPackageObjServicesService/DPDPackageObjServices?WSDL', 
'lang_code' => 'PL', // lang code (required for api v2)
'api_version' => 2, // version of api methods (available api version: 1 or 2)
'debug' => true, // debug errors to logfile
'log_path' => 'logs' // path of log files

Usage

Full example

<?php

use DPD\Services\DPDService;

$sender = [
    'fid' => '1495',
    'name' => 'Janusz Biznesu',
    'company' => 'INCO',
    'address' => 'Chmielna 10',
    'city' => 'Warszawa',
    'postalCode' => '00999',
    'countryCode' => 'PL',
    'email'=> 'biuro@_inco.pl',
    'phone' => '+22123456',
];  

$dpd = new DPDService();
$dpd->setSender($sender);

$parcels = [
    0 => [
        'content' => 'antyramy',
        'customerData1' => 'Uwaga szkło!',
        'weight' => 8,
    ],
    1 => [
        'content' => 'ulotki',
        'weight' => 5,
    ],
];

$receiver = [
    'company' => 'ABC Sp. z o.o.',
    'name' => 'Jan Kowalski',
    'address' => 'Wielicka 10',
    'city' => 'Krakow',
    'postalCode' => '30552',
    'countryCode' => 'PL',
    'phone' => '+12 555221112',
    'email'=> 'biuro@a_b_c.pl',
];

//send a package
$result = $dpd->sendPackage($parcels, $receiver, 'SENDER');

$pickupAddress = [
    'fid' => '1495',
    /*'name' => 'Janusz Biznesu',
    'company' => 'INCO',
    'address' => 'Chmielna 10',
    'city' => 'Warszawa',
    'postalCode' => '00999',
    'countryCode' => 'PL',
    'email'=> 'biuro@_inco.pl',
    'phone' => '+22123456',*/
];
 
// generate speedlabel in default, pdf/a4 format
$speedlabel = $dpd->generateSpeedLabelsByPackageIds([$result->packageId], $pickupAddress);

// save speedlabel to pdf file
file_put_contents('pdf/slbl-pid' . $result->packageId . '.pdf', $speedlabel->filedata);

// generate protocol
$protocol = $dpd->generateProtocolByPackageIds([$result->packageId], $pickupAddress);

// save protocol to pdf file
file_put_contents('pdf/prot-pid' . $result->packageId . '.pdf', $protocol->filedata);


// pickup

$pickupDate = '2017-08-23';
$pickupTimeFrom = '13:00';
$pickupTimeTo = '16:00';

$contactInfo = [
    'name' => 'Janusz Biznesu',
    'company' => 'INCO',
    'phone' => '12 5555555',
    'email' => 'januszbiznesu@_inco.pl',
    'comments' => 'proszę dzownić domofonem'

];

// pickup call
$pickup = $dpd->pickupRequest([$protocol->documentId], $pickupDate, $pickupTimeFrom, $pickupTimeTo, $contactInfo, $pickupAddress);

Postcode verify

<?php

use DPD\Services\DPDService;

$dpd = new DPDService();

$pc1 = $dpd->checkPostCode('UB3 5HL', 'GB'); //ok

$pc2 = $dpd->checkPostCode('00-999', 'PL'); //ok

$pc3 = $dpd->checkPostCode('33 100'); //ok

$pc4 = $dpd->checkPostCode('33100'); //ok

$pc5 = $dpd->checkPostCode('00-000'); //wrong

For more examples see unit tests

Notes

For current API specification you should contact with IT support of DPD Poland. http://www.dpd.com.pl/

License

MIT