2017 © Pedro Peláez
 

library dpd-shipping-api

API for DPD HU shipping

image

schiggi/dpd-shipping-api

API for DPD HU shipping

  • Tuesday, February 6, 2018
  • by schiggi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 42 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 5 Versions
  • 24 % Grown

The README.md

dpd-shipping-api

DPD shipping API for Hungarian DPD Weblabel webservice interface via POST requests, (*1)

Installing

The easiest way to install the API is using Composer:, (*2)

composer require schiggi/dpd-shipping-api

Then use your framework's autoload, or simply add:, (*3)

<?php
  require 'vendor/autoload.php';

Getting started

You can start making requests to the Billingo API just by creating a new API instance, (*4)

<?php

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

The API class takes care of the communication between your app and the DPD servers via POST requests., (*5)

Using Monolog to log requests and responses to a log file

Monolog is used optionally to log request/responses with DPD server., (*6)

You need to specific a log dir and optionally a message format when creating a new API instance. Log files while have the name "api-dpd-consumer-{date}.log", (*7)

<?php

  $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}',
      ]
  ]);

General usage

Send parcel data to DPD

<?php
// 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' => 'test@test.de',
    '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);
<?php
// 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'];

Delete parcel

<?php
// 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);

Transfer saved parcel data to internal database after labels have been printed

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

Retrieve parcel status

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

The Versions

07/06 2017

v0.6

0.6.0.0

API for DPD shipping

  Sources   Download

GPL-3.0

The Requires

 

by GYG

30/10 2013

v0.5

0.5.0.0

API for DPD shipping

  Sources   Download

GPL-3.0

The Requires

 

by Avatar And