|
DHL-PHP-SDK
v0.4
A wrapper for the DHL-XML-API Version 2
|
composer require petschko/dhl-php-sdkYou need to add a small snipped, which autoload all the required files for you. Wherever you want to use it, you have to add this line:
That's it, now you can start to do all the Configuration for you DHL-Logic (Explained in the next steps)
This is just a very basic Tutorial how you can use the DHL-PHP-SDK, I will add more tutorials & examples to the example to the directory.
First you need to setup your DHL-Credentials:
TEST-Credentials:
LIVE-Credentials
You've set all of the Required Information so far. Now you can Perform several Actions.
Please note, that you need the \Petschko\DHL\Credentials Object with Valid Login-Information for that.
\Petschko\DHL\Credentials **(Req)** - Login Information\Petschko\DHL\ShipmentDetails **(Req)** - Details of a Shipment\Petschko\DHL\ShipmentOrder **(Req)** - A whole Shipment\Petschko\DHL\Sender **(Req)** - Sender Details
\Petschko\DHL\ReturnReceiver (Optional) - Return Receiver Details
\Petschko\DHL\Service (Optional) - Service Details (Many Configurations for the Shipment)\Petschko\DHL\IdentCheck (Very Optional) - Ident-Check Details, only needed if turned on in Service\Petschko\DHL\BankData (Optional) - Bank-Information\Petschko\DHL\ExportDocument (Optional) - Export-Document Information\Petschko\DHL\ExportDocPosition (Optional) - Export-Document Position Item details\Petschko\DHL\BusinessShipment **(Req)** - Manages all Actions + Information\Petschko\DHL\Version (Parent)\Petschko\DHL\Response **(Req|Auto)** - Response Information\Petschko\DHL\Version (Parent)\Petschko\DHL\LabelData **(Req|Auto)** - Label Response Information\Petschko\DHL\Version (Parent)And one of them:
\Petschko\DHL\Receiver **(Req)** - Receiver Details
\Petschko\DHL\Filial (Optional) - Receiver-Details (Post-Filial)
\Petschko\DHL\PackStation (Optional) - Receiver-Details (Pack-Station)
\Petschko\DHL\Sender, \Petschko\DHL\Receiver & \Petschko\DHL\ReturnReceiver Object(s)You have to create a Sender and a Receiver. They are similar to set, just the XML creation is different so you have to use different Objects for that.
If you want to lookup all values, you can search trough the \Petschko\DHL\SendPerson & \Petschko\DHL\Address Classes.
Lets start with the Sender, in the most cases you =). Create a \Petschko\DHL\Sender Object:
Setup all Required Information
You can also add more Information, but they are Optional:
This was the sender Object, you can set all the same Information with the \Petschko\DHL\Receiver + \Petschko\DHL\ReturnReceiver Class.
Note: You can also use \Petschko\DHL\PackStation or \Petschko\DHL\Filial instead of \Petschko\DHL\Receiver. Please note, that they need some extra information.
You don't need to create the \Petschko\DHL\ReturnReceiver Object if you don't want a return Label.
\Petschko\DHL\Service ObjectYou can also setup more details for your Shipment by using the \Petschko\DHL\Service Object. It's an optional Object but may you should look, what you can set to this Object.
I'll not explain the Service-Object because there are too many settings. Please look into the Service-PHP-File by yourself. The fields are well documented.
\Petschko\DHL\BankData ObjectYou can also use the \Petschko\DHL\BankData Object. Bank data can be provided for different purposes. E.g. if COD (Cash on Delivery) is booked as service, bank data must be provided by DHL customer (mandatory server logic). The collected money will be transferred to specified bank account.
You can look to the PHP-File of the \Petschko\DHL\BankData-Object, and checkout what you can set there. I will not explain it here.
\Petschko\DHL\ExportDocument & \Petschko\DHL\ExportDocPosition Object(s)Sometimes you need to create a Export-Document, in that case you need these both Objects. Please inform yourself what you need to do here.
\Petschko\DHL\ShipmentDetails ObjectNow you need to setup the Shipment-Details for your Shipment (like Size/Weight etc). You can do that with the \Petschko\DHL\ShipmentDetails Object.
You can setup details for that, if you need. If you don't set them, it uses the default values _(This Part is Optional)_
\Petschko\DHL\ShipmentOrder ObjectNow you need to create the ShipmentOrder, which is explained here. First we need to create the Object
This is the main Object of our Shipment, so we need to add all Child-Object to it. These are Required
If you want to add even more details, there are some more optional values to set
\Petschko\DHL\BusinessShipment ObjectFinally you can add all together. You have to create the \Petschko\DHL\BusinessShipment Object
If you want to use a specific WSDL-File (or remote), you can set it: _(Else you don't need this part)_
Here you can add the ShipmentOrder:
Now you can set how the Label should get returned and some other stuff:
All set? Fine, now you can finally made the Create-Shipment-Order-Request. Save the Response to a var
First you have to check if the Value is not false
You can get several Information from the \Petschko\DHL\Response Object. Please have a look down where I describe the \Petschko\DHL\Response Class.
Please note, that you need the \Petschko\DHL\Credentials Object with Valid Login-Information for that.
You also need the Shipment-Number(s), from the Shipment(s), that you want to cancel/delete.
\Petschko\DHL\Credentials **(Req)** - Login Information\Petschko\DHL\BusinessShipment **(Req)** - Manages all Actions + Information\Petschko\DHL\Version (Parent)\Petschko\DHL\Response **(Req|Auto)** - Response Information\Petschko\DHL\Version (Parent)\Petschko\DHL\LabelData **(Req|Auto)** - Label Response Information\Petschko\DHL\Version (Parent)Deleting one or multiple Shipment(s) is not very hard, it just works like this:
Same like when creating a Shipment-Order, the Response is false if the Request failed. For more Information about the Response, look down where I describe the \Petschko\DHL\Response Class.
Please note, that you need the \Petschko\DHL\Credentials Object with Valid Login-Information for that.
You also need the Shipment-Number(s), from the Shipment(s), where you want to Re-Get Label(s).
\Petschko\DHL\Credentials **(Req)** - Login Information\Petschko\DHL\BusinessShipment **(Req)** - Manages all Actions + Information\Petschko\DHL\Version (Parent)\Petschko\DHL\Response **(Req|Auto)** - Response Information\Petschko\DHL\Version (Parent)\Petschko\DHL\LabelData **(Req|Auto)** - Label Response Information\Petschko\DHL\Version (Parent)Same like deleting, re-getting Labels is not this hard. You can simply re-get Labels:
If the request failed, you get false as usual else a \Petschko\DHL\Response Object.
Please note, that you need the \Petschko\DHL\Credentials Object with Valid Login-Information for that.
You also need the Shipment-Number for the Manifest _(If you need it, you will know how to use this)_.
I personally don't know for what is this for, but it works!
\Petschko\DHL\Credentials **(Req)** - Login Information\Petschko\DHL\BusinessShipment **(Req)** - Manages all Actions + Information\Petschko\DHL\Version (Parent)\Petschko\DHL\Response **(Req|Auto)** - Response Information\Petschko\DHL\Version (Parent)\Petschko\DHL\LabelData **(Req|Auto)** - Label Response Information\Petschko\DHL\Version (Parent)It works like deleting Shipments:
If the request failed, you get false else a \Petschko\DHL\Response Object. For more Information about the Response, look down where I describe the \Petschko\DHL\Response Class.
Please note, that you need the \Petschko\DHL\Credentials Object with Valid Login-Information for that.
I personally also don't know for what is this for, but it works!
\Petschko\DHL\Credentials **(Req)** - Login Information\Petschko\DHL\BusinessShipment **(Req)** - Manages all Actions + Information\Petschko\DHL\Version (Parent)\Petschko\DHL\Response **(Req|Auto)** - Response Information\Petschko\DHL\Version (Parent)The syntax is quite simple, you just need to specify the date where you want to have the manifest:
If the request failed, you get false else a \Petschko\DHL\Response Object. For more Information about the Response, look down where I describe the \Petschko\DHL\Response Class.
\Petschko\DHL\Response ObjectIf you get a Response that is not false, you have to mess with the \Petschko\DHL\Response Object.
This Object helps you, to get easy to your Goal. You can easily get the Values you need by using the getters. _(IDEs will detect them automatic)_
I will explain which values you can get from the Response-Object
You can get all these values for MULTI-Requests as well, but it's a bit different... First you can request how many items we got from the response by using:
You can access every item by using $response->getLabelData((null|int) $index);. When you use null, you get the whole array, else the specific \Petschko\DHL\LabelData-Item chosen by the index.
You can get the values like this: (For the first item for example)
Just to show you a simple loop, how you can handle every Request-Item:
If a value is not set you get usually null as result. Not every Action fills out all of these values!
You can also take a look at the Class Constants, they are helping you to identify the Status-Codes:
That's all so far