Skip to content

coffeedesk/dpd-api-client-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DPD API PHP Client

Helper model and client classes for DPD APIs.

Parts of the library is automatically generated by the wsdl2phpgenerator package.

Installation with composer

composer require coffeedesk/dpd-api-client-php

Usage

It is good to always use the latest version of a given method.

Generate packages numbers

<?php

require_once __DIR__ . '/vendor/autoload.php';

$client = new \DpdApi\Service\Client(
    'LOGIN',
    'PASSWORD',
    'MASTER_FID',
    'https://dpdservicesdemo.dpd.com.pl/DPDPackageObjServicesService/DPDPackageObjServices?wsdl',
    ['trace' => 1]
);

$sender = new \DpdApi\Service\Model\packageAddressOpenUMLFeV1();
$sender->setName('Sender');
$sender->setAddress('Sender address 22');
$sender->setCity('Warszawa');
$sender->setPostalCode('02454');
$sender->setCountryCode('PL');

$receiver = new \DpdApi\Service\Model\packageAddressOpenUMLFeV1();
$receiver->setName('John Doe');
$receiver->setAddress('Some address 13');
$receiver->setPostalCode('02274');
$receiver->setCity('Warszawa');
$receiver->setCountryCode('PL');

$parcels = [];
$parcel = new \DpdApi\Service\Model\parcelOpenUMLFeV1();
$parcel->setContent('Package content');
$parcel->setWeight('1.5');
array_push($parcels, $parcel);

$packages = [];
$package = new \DpdApi\Service\Model\packageOpenUMLFeV3();
$package->setSender($sender);
$package->setReceiver($receiver);
$package->setPayerType(\DpdApi\Service\Model\payerTypeEnumOpenUMLFeV1::THIRD_PARTY);
$package->setThirdPartyFID('MASTER_FID');
$package->setParcels($parcels);
array_push($packages, $package);


$openUMLFeV3 = new \DpdApi\Service\Model\openUMLFeV3();
$openUMLFeV3->setPackages($packages);

try {
    $client->generatePackagesNumbersV4(
        $openUMLFeV3,
        \DpdApi\Service\Model\pkgNumsGenerationPolicyV1::IGNORE_ERRORS,
        'PL'
    );
} catch (SoapFault $fault) {
    echo $fault->getMessage();
}

Generate sped labels

<?php

require_once __DIR__ . '/vendor/autoload.php';

$client = new \DpdApi\Service\Client(
    'LOGIN',
    'PASSWORD',
    'MASTER_FID',
    'https://dpdservicesdemo.dpd.com.pl/DPDPackageObjServicesService/DPDPackageObjServices?wsdl',
    ['trace' => 1]
);

$parcels = [];
$parcel = new \DpdApi\Service\Model\parcelDSPV1();
$parcel->setWaybill('WAYBILL_NUMBER');
array_push($parcels, $parcel);

$packages = [];
$package = new \DpdApi\Service\Model\packageDSPV1();
$package->setParcels($parcels);
array_push($packages, $package);

$session = new \DpdApi\Service\Model\sessionDSPV1();
$session->setSessionType(\DpdApi\Service\Model\sessionTypeDSPEnumV1::DOMESTIC);
$session->setPackages($packages);

$dpdServicesParams = new \DpdApi\Service\Model\dpdServicesParamsV1();
$dpdServicesParams->setPolicy(\DpdApi\Service\Model\policyDSPEnumV1::IGNORE_ERRORS);
$dpdServicesParams->setSession($session);

try {
    $client->generateSpedLabelsV4(
        $dpdServicesParams,
        \DpdApi\Service\Model\outputDocFormatDSPEnumV1::PDF,
        \DpdApi\Service\Model\outputDocPageFormatDSPEnumV1::LBL_PRINTER,
        \DpdApi\Service\Model\outputLabelTypeEnumV1::BIC3,
        ''
    );
} catch (SoapFault $fault) {
    echo $fault->getMessage();
}

Generate protocol

<?php

require_once __DIR__ . '/vendor/autoload.php';

$client = new \DpdApi\Service\Client(
    'LOGIN',
    'PASSWORD',
    'MASTER_FID',
    'https://dpdservicesdemo.dpd.com.pl/DPDPackageObjServicesService/DPDPackageObjServices?wsdl',
    ['trace' => 1]
);

$parcels = [];
$parcel = new \DpdApi\Service\Model\parcelDSPV1();
$parcel->setWaybill('WAYBILL_NUMBER');
array_push($parcels, $parcel);

$packages = [];
$package = new \DpdApi\Service\Model\packageDSPV1();
$package->setParcels($parcels);
array_push($packages, $package);

$session = new \DpdApi\Service\Model\sessionDSPV1();
$session->setSessionType(\DpdApi\Service\Model\sessionTypeDSPEnumV1::DOMESTIC);
$session->setPackages($packages);

$dpdServicesParams = new \DpdApi\Service\Model\dpdServicesParamsV1();
$dpdServicesParams->setPolicy(\DpdApi\Service\Model\policyDSPEnumV1::IGNORE_ERRORS);
$dpdServicesParams->setSession($session);

try {
    $client->generateProtocolV2(
        $dpdServicesParams,
        \DpdApi\Service\Model\outputDocPageFormatDSPEnumV1::LBL_PRINTER,
        \DpdApi\Service\Model\outputDocFormatDSPEnumV1::PDF
    );
} catch (SoapFault $fault) {
    echo $fault->getMessage();
}

Get events for waybill

<?php

require_once __DIR__ . '/vendor/autoload.php';

$client = new \DpdApi\InfoService\Client(
    'LOGIN',
    'PASSWORD',
    'CHANNEL',
    'https://dpdinfoservices.dpd.com.pl/DPDInfoServicesObjEventsService/DPDInfoServicesObjEvents?wsdl',
    ['trace' => 1]
);

try {
    $client->getEventsForWaybillV1(
        'WAYBILL_NUMBER',
        \DpdApi\InfoService\Model\eventsSelectTypeEnum::ALL,
        'PL'
    );
} catch (SoapFault $fault) {
    echo $fault->getMessage();
}

Regenerate PHP classes from WSDL

If it is necessary, you can generate the classes again, but you may have to change the methods after the generation to avoid errors.

DPD Services

<?php
#generator.php
require_once __DIR__ . '/vendor/autoload.php';

$generator = new Wsdl2PhpGenerator\Generator();
$generator->generate(
    new Wsdl2PhpGenerator\Config([
        'inputFile' => 'https://dpdservices.dpd.com.pl/DPDPackageObjServicesService/DPDPackageObjServices?WSDL',
        'outputDir' => 'src/Service/Model',
        'namespaceName' => 'DpdApi\Service\Model',
    ])
);

DPD InfoServices

<?php
#generator.php

require_once __DIR__ . '/vendor/autoload.php';

$generator = new Wsdl2PhpGenerator\Generator();
$generator->generate(
    new Wsdl2PhpGenerator\Config([
        'inputFile' => 'https://dpdinfoservices.dpd.com.pl/DPDInfoServicesObjEventsService/DPDInfoServicesObjEvents?wsdl',
        'outputDir' => 'src/InfoService/Model',
        'namespaceName' => 'DpdApi\InfoService\Model',
    ])
);

Then we cun run command responsible for generate classes

php generator.php

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages