PHP code example of slonline / dhlglobalmail
1. Go to this page and download the library: Download slonline/dhlglobalmail 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/ */
slonline / dhlglobalmail example snippets
use SLONline\DHLGlobalMail\Client;
use SLONline\DHLGlobalMail\Model\Order;
use SLONline\DHLGlobalMail\Model\OrderItem;
use SLONline\DHLGlobalMail\Model\Shipment;
use SLONline\DHLGlobalMail\Model\Tracking;
use SLONline\DHLGlobalMail\Exception\DHLGlobalMailRequestException;
$client = new Client('your_client_id', 'your_client_secret');
// Create a order and label
try {
$orer = $client->createOrder([
'customerEkp' => '9012345678',
'orderStatus' => Order::STATUS_FINALIZE,
'paperwork' => [
'contactName' => "Max Mustermann",
'awbCopyCount' => 3,
'jobReference' => "Job ref",
'pickupType' => Paperwork::PICKUP_TYPE_CUSTOMER_DROP_OFF,
"pickupLocation" => "Mustergasse 12",
"pickupDate" => date('Y-m-d'),
"pickupTimeSlot" => Paperwork::TIME_SLOT_MIDDAY,
"telephoneNumber" => "+4935120681234",
],
'items' => [
[
"product" => OrderItem::PRODUCT_GPP,
"serviceLevel" => OrderItem::SERVICE_LEVEL_PRIORITY,
"recipient" => "Alfred J. Quack",
"addressLine1" => "Mustergasse 12",
"addressLine2" => "Hinterhaus",
"addressLine3" => "1. Etage",
"city" => "Dresden",
"destinationCountry" => "DE",
"custRef" => "#REF-2361890-AB",
"recipientPhone" => "+4935120681234",
"recipientEmail" => "[email protected] ",
"postalCode" => "01432",
"shipmentGrossWeight" => 1200,
"returnItemWanted" => false,
"shipmentNaturetype" => OrderItem::SHIPMENT_NATURE_TYPE_SALE_GOODS,
'shipmentCurrency' => 'EUR',
"shipmentAmount" => 100,
],
[
"product" => OrderItem::PRODUCT_GPP,
"serviceLevel" => OrderItem::SERVICE_LEVEL_PRIORITY,
"recipient" => "One Person",
"addressLine1" => "180 St Kilda Rd",
"city" => "Melbourne",
"destinationCountry" => "AU",
"custRef" => "#455",
"recipientPhone" => "+32112122",
"recipientEmail" => "[email protected] ",
"postalCode" => "VIC 3006",
"shipmentGrossWeight" => 120,
"returnItemWanted" => false,
"shipmentNaturetype" => OrderItem::SHIPMENT_NATURE_TYPE_SALE_GOODS,
'shipmentCurrency' => 'EUR',
'contents' => [
[
'contentPieceAmount' => 1,
'contentPieceDescription' => 'test book',
'contentPieceHsCode' => '49019900',
'contentPieceNetweight' => 120,
'contentPieceOrigin' => 'NL',
'contentPieceValue' => '12.50',
],
],
],
[
"product" => OrderItem::PRODUCT_GPP,
"serviceLevel" => OrderItem::SERVICE_LEVEL_PRIORITY,
"recipient" => "Apple Park",
"addressLine1" => "One Apple Park Way",
"city" => "Cupertino",
"state" => 'CA',
"destinationCountry" => "US",
"custRef" => "#455",
"recipientPhone" => "+321232131",
"recipientEmail" => "[email protected] ",
"postalCode" => "95014",
"shipmentGrossWeight" => 120,
"returnItemWanted" => false,
"shipmentNaturetype" => OrderItem::SHIPMENT_NATURE_TYPE_SALE_GOODS,
'shipmentCurrency' => 'EUR',
'shipmentAmount' => 12.5,
'contents' => [
[
'contentPieceAmount' => 1,
'contentPieceDescription' => 'test book',
'contentPieceHsCode' => '49019900',
'contentPieceNetweight' => 120,
'contentPieceOrigin' => 'NL',
'contentPieceValue' => '12.50',
],
],
],
],
]
);
$awb = $order->getShipments()[0]->getAwb();
$awbPdf = $client->getAwbLabelPDF($awb);
$itemsPDF = $client->getItemLabelsPDF($awb);
var_dump($order, $awbPdf);
} catch (DHLGlobalMailRequestException $exception) {
echo $exception->getMessage();
}