PHP code example of gunjanpatel / dhl-parcel-api

1. Go to this page and download the library: Download gunjanpatel/dhl-parcel-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/ */

    

gunjanpatel / dhl-parcel-api example snippets




use DHL\Client\Soap as DhlSoapClient;
use DHL\Data\Shipper;
use DHL\Data\Receiver;
use DHL\Data\Shipment as ShipmentDetail;
use DHL\Request\Business\CreateShipment;

// Our company info
$shipper = new Shipper(
	[
		'company_name'   => 'Garnio Aps',
		'street_name'    => 'Clayallee',
		'street_number'  => '241',
		'zip'            => '14165',
		'city'           => 'Berlin',
		'email'          => '[email protected]',
		'phone'          => '01788338795',
		'contact_person' => 'Gunjan Patel',
		'comment'        => '',
	]
);

$customer_details = [
	'name'           => 'Gunjan Patel',
	'street_name'    => 'Clayallee',
	'street_number'  => '12',
	'zip'            => 14165,
	'city'           => 'Berlin',
	'email'          => '[email protected]',
	'phone'          => '1234567890',
	'contact_person' => 'Gunjan Patel',
	'comment'        => 'Just test',
];

$receiver = new Receiver($customer_details);

$detail = new ShipmentDetail(
	[
		'product'       => 'V01PAK',
		'accountNumber' => '2222222222220101',
		// 'customerReference'           => '',     // Optional
		'shipmentDate'  => date('Y-m-d'),
		// 'returnShipmentAccountNumber' => $config['ekp'],       // Optional
		// 'returnShipmentReference'     => '',     // Optional
	]
);

// Needs to convert weight into KG
$detail->item(['weight' => 10])
	->notify('[email protected]');

$shipment = new CreateShipment;
$shipment->setOrderId(123456)
	->detail($detail)
	->shipper($shipper)
	->receiver($receiver)
	->labelType('B64');

$client = new DhlSoapClient(true);

$response = $client->call($shipment);

echo "<pre>";
print_r($response);
echo "</pre>";




use DHL\Client\Soap as DhlSoapClient;
use DHL\Request\Business\Label;

$client = new DhlSoapClient(true);

$label = new Label('1234567890987654321');
$response = $client->call($label);

echo "<pre>";
print_r($response);
echo "</pre>";