PHP code example of schiggi / dpd-shipping-api

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

    

schiggi / dpd-shipping-api example snippets



  



  $api = new DPD\API([
      'username' => 'demo',
      'password' => 'o2Ijwe2',
  ]);



  $api = new DPD\API([
      'username' => 'demo',
      'password' => 'o2Ijwe2!',
      'log_dir'  => dirname(__FILE__).'/',
      'log_msg_format' => [
        '{method} {uri} HTTP/{version} {req_body}',
        'RESPONSE: {code} - {res_body}',
      ]
  ]);
 


// Parcel generation. Data will be validated before sending.
$parcel_generate = array(
    'setName1' => 'Alex',
    'setStreet' => 'Kesmark u 4',
    'setCity' => 'Budapest',
    'setCountry' => 'HU',
    'setPcode' => '1158',
    'setWeight' => '1',
    'setNumOfParcel' => 1,
    'setParcelType' => 'BC',
    'setOrderNumber' => '1234',
    'setCodAmount' => '',
    'setCodPurpose' => '',
    'setEmail' => '[email protected]',
    'setPhone' => '0636516516',
    'setSMSNumber' => '0636516516',
    'setRemark' => 'Customer comments',
    ); // Max length 100 chars. Will be normalized through the API

// Will return the parcel number from DPD or error message
$parcel_number = $api->generateParcel($parcel_generate);


// Array of parcel numbers from DPD. Can also be a string with one number
$parcel_array = array('123456789','987654321');

// Returns json array with success message and pdf stream
$parcel_response_json = $api->getParcelLabels($parcel_array);

// Echo to get pdf stream
header("Content-type:application/pdf");
echo $parcel_response_json['pdf'];



// Array of parcel numbers from DPD. Can also be a string with one number
$parcel_array = array('123456789','987654321');

// Returns json array with success message
$parcel_delete_status = $api->deleteParcel($parcel_array);



// returns the numbers of parcels, which have been succesfully transfered
$number_parcels_sent = $api->transferData();



// returns status message as string for parcel_number. One number at a time.
$status_msg = $api->getParcelStatus('123456789');