项目作者: jackbayliss

项目描述 :
DHL XML Wrapper for Laravel, easily get Quotes, Routing or Tracking.
高级语言: PHP
项目地址: git://github.com/jackbayliss/laravel-dhl-api.git
创建时间: 2020-07-16T12:49:03Z
项目社区:https://github.com/jackbayliss/laravel-dhl-api

开源协议:MIT License

下载


Laravel DHL XML API

I needed a DHL wrapper so I could efficiently provide courier quotes to customers- I did find one. But, it needed to be adjusted to work for my needs- this is effectively the edited version to provide Quotes, Routing and Tracking.

Getting Started

Prerequisites

This should work fine on Laravel>=5.7.28, if your version of Laravel does not support auto linking you will need to add \jackbayliss\DHLApi\DHLAPIProvider::class into your providers array located in config/app.php

Installing

composer require jackbayliss/laravel-dhl-api

Usage Examples

Config setup

In order to use the wrapper you’ll need to setup a few things in your Config.php file- or alternatively you .env file if you don’t want to use the config.

You’ll need to set from_country_code,from_post_code,account_number,siteid,password in your config

or alternatively set DHL_SITEID,DHL_PASSWORD,DHL_ACCOUNT_NUMBER, DHL_FROM_COUNTRYCODE,DHL_FROM_POSTCODE in your .env don’t forget to edit the config to be null for all the entries.

Quotation

This is typically used to get shipping quotes, as well as the time for transit etc.

  1. $quote = new \jackbayliss\DHLApi\Calls\GetQuote();
  2. $quote->declaredValue(10)->reference("0999999999990393939333333333")
  3. ->currency("GBP")->toCountryCode("DE")->toPostalCode("91056")->setPieces([
  4. array("height" => 10,"width" => 10 ,"depth" => 2,"weight" => 0.5)
  5. ]);
  6. $quote->getResponse();

Tracking

Self explanitory- it’ll track a parcel for you.

  1. $tracking = new \jackbayliss\DHLApi\Calls\GetTracking();
  2. $tracking = $tracking->reference("0999999999990393939333333333")->trackingNumber("8564385550");
  3. $tracking->getResponse();

Routing

Used to provide routing information about a parcel to a particular address.

  1. $routing = new \jackbayliss\DHLApi\Calls\GetRouting();
  2. $routing = $routing->reference("0999999999990393939333333333")->address([
  3. 'RegionCode' => 'EU',
  4. 'RequestType' => 'O',
  5. 'Address1' => 'Oracle Parkway,',
  6. 'Address2' => 'Thames Valley Park (TVP)',
  7. 'Address3' => 'Berkshire',
  8. 'PostalCode' => 'RG6 1RA',
  9. 'City' => 'Reading',
  10. 'Division' => 'RE',
  11. 'CountryCode' => 'GB',
  12. 'CountryName' => 'United Kingdom',
  13. 'OriginCountryCode' => 'GB'
  14. ]);
  15. $routing->getResponse();

Methods

These methods can be linked to any of the above core API classes.

getResponse() - This will execute the cURL request and return the XML data as an Object.

getRawResponse() - This will return the XML response from the DHL API as A String.

toXML() - This will return the XML you sent to the DHL API as A String.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details