Giter Site home page Giter Site logo

dhl-express-php-sdk's Introduction

Unoffical DHL Express PHP SDK

This unoffical library is wrapping some functions of the DHL Express JSON/REST API (called MyDHL_API).

To get a SDK for standard DHL shipping, please have a look at the great SDK from Petschko i've used for inspiration.

Requirements

  • test (and live) credentials from the DHL Express Tech Contact
  • PHP-Version 5.5 or higher (It may work on older Versions, but I don't offer Support for these)
  • Guzzle installed

Compatibility

This Project is written for the MyDHL API v1.

Install

You can use Composer to install the package to your project:

composer require alex-le/dhl-express-php-sdk

Supported API Operations

Operation supported
RateRequest no
ShipmentRequest yes
TrackingRequest no
DocumentRetrieve no
updateShipment no
requestPickup no

Usage

see examples for basic examples and scripts to generate test labels (see below)

Request Access to live API

To get the credentials for the live account, DHL requested test labels for some scenarios:

The test scripts can be found in the examples folder:

  1. National shipping with saturday delivery - test_1.php
  2. National shipping time option and 2 packages - test_2.php
  3. International shipping not liable to duty - test_3.php
  4. International shipping liable to duty - test_4.php
  5. International shipping liable to duty with service DDP - test_5.php
  6. International shipping liable to duty with different payment account - test_6.php

Things i've learned during testing the API

  • The "InternationalDetail" part is mandatory even if its national package
  • StreetName and StreetNumber in der Address don't have any effect right now, the "StreetLines" field is always used
  • Company Name in the Recipient address is the name on the package (first line)
  • Package Dimensions are mandatory, but they don't have to be exact (DHL will check them anyway) - so it is possible to always use the smallest package size you have
  • "StreetLine" could not be used for any additional name - use "StreetLines2" for this - always use it for street name and number

More details will follow soon. This package is WIP.

dhl-express-php-sdk's People

Contributors

adiconquerors avatar alex-le avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

dhl-express-php-sdk's Issues

Call to a member function isSuccessful() on boolean

Hi I am new to this API. I quickly setup up your example for international delivery without duty but I am getting Call to a member function isSuccessful() on boolean

Any ideas?

I am using it with PHP 7.2 with Laravel 7.11.0 on Windows 10 Xampp.

Edit:
I should also say that my endpooint from DHL is https://express.api.dhl.com/mydhlapi/test/ instead of https://wsbexpress.dhl.com/rest/sndpt/ and the docs refers to shipment instead of ShipmentRequest as in your vendor file https://github.com/alex-LE/dhl-express-php-sdk/blob/master/src/ShipmentRequest.php

I have tried both yours and my endpoint with both shipment and ShipmentRequest

with your endpoint

https://wsbexpress.dhl.com/rest/sndpt/ShipmentRequest

Array ( [0] => The Shipper Account is invalid. [1] => Process failure occurred. Process ID associated for that transaction (201012585) )
null

with my endpoint

https://express.api.dhl.com/mydhlapi/test/ShipmentRequest

Call to a member function isSuccessful() on boolean

with my endpoint

https://express.api.dhl.com/mydhlapi/test/shipments
from here https://developer.dhl.com/api-reference/dhl-express-mydhl-api#reference-docs-section%create-shipment

Call to a member function isSuccessful() on boolean

Commercial Invoice

Hello, I get these errors when I try to create a commercial invoice, can you help me to solve it?

My Code
`
$credentials = new Credentials(true);
$credentials
->setUsername('xxx')
->setPassword('xxx');

$customerLogo = new CustomerLogo();
$customerLogo
	->setLogoImage(base64_encode(file_get_contents('https://xxx.com/xxx.png')))
	->setLogoImageFormat(CustomerLogo::IMAGE_FORMAT_PNG);

$labelOptions = new LabelOptions();
$labelOptions
	->setCustomerLogo($customerLogo)
	->setHideAccountInWaybillDocument("false")
	->setAllInOnePDF("true")
	->setRequestDHLCustomsInvoice("true");

$specialService = new SpecialService();
$specialService
	->setServiceType(SpecialService::INTERNATIONAL_DUTY_NEUTRAL_DELIVERY_SERVICE);

$shipmentInfo = new ShipmentInfo();
$shipmentInfo
	->setDropOffType(ShipmentInfo::DROP_OFF_TYPE_REGULAR_PICKUP)
	->setServiceType(ShipmentInfo::SERVICE_TYPE_EXPRESS_WORLDWIDE_NON_DOC)
	->setAccount('xxx')
	->setCurrency($ordersItemCurrency)
	->setUnitOfMeasurement(ShipmentInfo::UNIT_OF_MEASRUREMENTS_KG_CM)
	->setLabelType(ShipmentInfo::LABEL_TYPE_PDF)
	->setLabelTemplate(ShipmentInfo::LABEL_TEMPLATE_ECOM_TC_A4)
	->setCustomsInvoiceTemplate("COMMERCIAL_INVOICE_03")
	->setPaperlessTradeEnabled(true)
	->addSpecialService($specialService)
	->setLabelOptions($labelOptions);



$shipperContact = new Contact();
$shipperContact
	->setPersonName($data['dhlConfig']['dhlConfig_personalName'])
	->setCompanyName($data['dhlConfig']['dhlConfig_companyName'])
	->setPhoneNumber($data['dhlConfig']['dhlConfig_phone'])
	->setEmailAddress('[email protected]');

$shipperAddress = new Address();
$shipperAddress
	->setStreetLines($data['dhlConfig']['dhlConfig_address1'] . " " . $data['dhlConfig']['dhlConfig_address2'])
	->setCity($data['dhlConfig']['dhlConfig_city'])
	->setPostalCode($data['dhlConfig']['dhlConfig_postalCode'])
	->setCountryCode('TR');

$shipper = new Shipper();
$shipper
	->setContact($shipperContact)
	->setAddress($shipperAddress);

$recipientContact = new Contact();
$recipientContact
	->setPersonName($ordersFullName)
	->setCompanyName($ordersFullName)
	->setPhoneNumber($ordersPhone)
	->setEmailAddress($ordersEmail);

$recipientAddress = new Address();
$recipientAddress
	->setStreetLines($ordersAddress1 . " " . $ordersAddress2 . " " . $ordersAddress3)
	->setCity($ordersCity)
	->setPostalCode($ordersPostalCode)
	->setCountryCode($ordersCountry);

$recipient = new Recipient();
$recipient
	->setContact($recipientContact)
	->setAddress($recipientAddress);

$ship = new Ship();
$ship
	->setShipper($shipper)
	->setRecipient($recipient);

$package1 = new RequestedPackage();
$package1
	->setWeight($ordersWeight)
	->setDimensions($ordersWidth, $ordersHeight, $ordersLength)
	->setCustomerReferences('Box 1');

$packages = new Packages();
$packages
	->addRequestedPackage($package1);

$commodities = new Commodities();
$commodities
	->setDescription($data['ordersItems'][0]['ordersItem_name'])
	->setCustomsValue($totalItems);

$exportLineItems = new ExportLineItems();
$jj = 1;
foreach ($data['ordersItems'] as $orderItem) {
	$exportLineItem = new ExportLineItem();
	$exportLineItem
		->setItemNumber($jj)
		->setQuantity($orderItem['ordersItem_quantity'])
		->setItemDescription($orderItem['ordersItem_name'])
		->setUnitPrice($orderItem['ordersItem_unitPrice'])
		->setNetWeight(1)
		->setGrossWeight(1)
		->setManufacturingCountryCode("TR");

	$exportLineItems
		->addexportLineItem($exportLineItem);
	$jj++;
}

$exportDeclaration = new ExportDeclaration();
$exportDeclaration
	->setExportLineItems($exportLineItems)
	->setInvoiceNumber($ordersOrderNumber);
$exportDeclaration
	->setInvoiceDate(date('Y-m-d'));

// The InternationalDetail seems to be required even if its a domestic package
$internationalDetail = new InternationalDetail();
$internationalDetail
	->setCommodities($commodities)
	->setContent(InternationalDetail::CONTENT_NON_DOCUMENTS)
	->setExportDeclaration($exportDeclaration);

// $documentImage = new DocumentImage();
// $documentImage
// 	->setDocumentImageType(DocumentImage::DOCUMENT_IMAGE_TYPE_INVOICE)
// 	->setDocumentImage(DocumentImage::DOCUMENT_IMAGE_TYPE_COMMERCIAL_INVOICE)
// 	->setDocumentImageFormat(DocumentImage::DOCUMENT_IMAGE_FORMAT_PDF);

$timestamp = new DateTime("now", new DateTimeZone("Europe/Berlin"));
$timestamp->modify('+3 days');

if ($ordersSendMethod == 1) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_DELIVERY_DUTY_PAID)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "DDP ";
} elseif ($ordersSendMethod == 2) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_DELIVERED_AT_PLACE)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "DAP ";
} elseif ($ordersSendMethod == 3) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_EX_WORKS)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "EXW ";
} elseif ($ordersSendMethod == 4) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_CARRIAGE_AND_INSURANCE_PAID_TO)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "CIP ";
} elseif ($ordersSendMethod == 5) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_DELIVERY_DUTY_PAID)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$termsOfSale = "DAT";
	$atrValue .= "DAT ";
} elseif ($ordersSendMethod == 6) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_DELIVERY_DUTY_PAID)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$termsOfSale = "DPU";
	$atrValue .= "DPU ";
} elseif ($ordersSendMethod == 7) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_FREE_CARRIER)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "FCA ";
} elseif ($ordersSendMethod == 8) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_CARRIAGE_PAID_TO)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "CPT ";
} elseif ($ordersSendMethod == 9) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_FREE_ALONGSIDE_SHIP)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "FAS ";
} elseif ($ordersSendMethod == 10) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_FREE_ON_BOARD)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "FOB ";
} elseif ($ordersSendMethod == 11) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_COST_AND_FREIGHT)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "CFR ";
} elseif ($ordersSendMethod == 12) {
	$requestedShipment = new RequestedShipment();
	$requestedShipment
		->setShipmentInfo($shipmentInfo)
		->setShipTimestamp($timestamp)
		->setPaymentInfo(RequestedShipment::PAYMENT_INFO_COST_INSURANCE_AND_FREIGHT)
		->setShip($ship)
		->setPackages($packages)
		->setInternationalDetail($internationalDetail);
	$atrValue .= "CIF ";
}

$shipment = new ShipmentRequest($credentials);
$shipment->setRequestedShipment($requestedShipment);
$responses = $shipment->send();`

[ISC.0082.9460] No matching enumeration value ------------ shipreq:ShipmentRequest/RequestedShipment/ShipmentInfo/LabelOptions/HideAccountInWaybillDocument
Process failure occurred. Process ID associated for that transaction (521012451)

[ISC.0082.9460] No matching enumeration value ------------ shipreq:ShipmentRequest/RequestedShipment/ShipmentInfo/LabelOptions/RequestDHLCustomsInvoice

[ISC.0082.9460] No matching enumeration value ------------ /shipreq:ShipmentRequest/RequestedShipment/ShipmentInfo/LabelOptions/DetachOptions/AllInOnePDF

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.