项目作者: msztorc

项目描述 :
DPD Polska - API wrapper
高级语言: PHP
项目地址: git://github.com/msztorc/php-dpd-api.git
创建时间: 2017-03-17T21:45:50Z
项目社区:https://github.com/msztorc/php-dpd-api

开源协议:MIT License

下载


php-dpd-api

Set of PHP classes to handle API of courier services (DPD Poland)

Build Status
License

Installation

  1. composer require msztorc/php-dpd-api

or

  1. git clone https://github.com/msztorc/php-dpd-api.git

of course you can also download zip file, unpack and include to your project

Configuration file

Main configuration is located in config.php file

  1. 'fid' => '1495',
  2. 'username' => 'test', // username for api calls
  3. 'password' => 'KqvsoFLT2M', // password for api calls
  4. 'wsdl' => 'https://dpdservicesdemo.dpd.com.pl/DPDPackageObjServicesService/DPDPackageObjServices?WSDL',
  5. 'lang_code' => 'PL', // lang code (required for api v2)
  6. 'api_version' => 2, // version of api methods (available api version: 1 or 2)
  7. 'debug' => true, // debug errors to logfile
  8. 'log_path' => 'logs' // path of log files

Usage

Full example

  1. <?php
  2. use DPD\Services\DPDService;
  3. $sender = [
  4. 'fid' => '1495',
  5. 'name' => 'Janusz Biznesu',
  6. 'company' => 'INCO',
  7. 'address' => 'Chmielna 10',
  8. 'city' => 'Warszawa',
  9. 'postalCode' => '00999',
  10. 'countryCode' => 'PL',
  11. 'email'=> 'biuro@_inco.pl',
  12. 'phone' => '+22123456',
  13. ];
  14. $dpd = new DPDService();
  15. $dpd->setSender($sender);
  16. $parcels = [
  17. 0 => [
  18. 'content' => 'antyramy',
  19. 'customerData1' => 'Uwaga szkło!',
  20. 'weight' => 8,
  21. ],
  22. 1 => [
  23. 'content' => 'ulotki',
  24. 'weight' => 5,
  25. ],
  26. ];
  27. $receiver = [
  28. 'company' => 'ABC Sp. z o.o.',
  29. 'name' => 'Jan Kowalski',
  30. 'address' => 'Wielicka 10',
  31. 'city' => 'Krakow',
  32. 'postalCode' => '30552',
  33. 'countryCode' => 'PL',
  34. 'phone' => '+12 555221112',
  35. 'email'=> 'biuro@a_b_c.pl',
  36. ];
  37. //send a package
  38. $result = $dpd->sendPackage($parcels, $receiver, 'SENDER');
  39. $pickupAddress = [
  40. 'fid' => '1495',
  41. /*'name' => 'Janusz Biznesu',
  42. 'company' => 'INCO',
  43. 'address' => 'Chmielna 10',
  44. 'city' => 'Warszawa',
  45. 'postalCode' => '00999',
  46. 'countryCode' => 'PL',
  47. 'email'=> 'biuro@_inco.pl',
  48. 'phone' => '+22123456',*/
  49. ];
  50. // generate speedlabel in default, pdf/a4 format
  51. $speedlabel = $dpd->generateSpeedLabelsByPackageIds([$result->packageId], $pickupAddress);
  52. // save speedlabel to pdf file
  53. file_put_contents('pdf/slbl-pid' . $result->packageId . '.pdf', $speedlabel->filedata);
  54. // generate protocol
  55. $protocol = $dpd->generateProtocolByPackageIds([$result->packageId], $pickupAddress);
  56. // save protocol to pdf file
  57. file_put_contents('pdf/prot-pid' . $result->packageId . '.pdf', $protocol->filedata);
  58. // pickup
  59. $pickupDate = '2017-08-23';
  60. $pickupTimeFrom = '13:00';
  61. $pickupTimeTo = '16:00';
  62. $contactInfo = [
  63. 'name' => 'Janusz Biznesu',
  64. 'company' => 'INCO',
  65. 'phone' => '12 5555555',
  66. 'email' => 'januszbiznesu@_inco.pl',
  67. 'comments' => 'proszę dzownić domofonem'
  68. ];
  69. // pickup call
  70. $pickup = $dpd->pickupRequest([$protocol->documentId], $pickupDate, $pickupTimeFrom, $pickupTimeTo, $contactInfo, $pickupAddress);

Postcode verify

  1. <?php
  2. use DPD\Services\DPDService;
  3. $dpd = new DPDService();
  4. $pc1 = $dpd->checkPostCode('UB3 5HL', 'GB'); //ok
  5. $pc2 = $dpd->checkPostCode('00-999', 'PL'); //ok
  6. $pc3 = $dpd->checkPostCode('33 100'); //ok
  7. $pc4 = $dpd->checkPostCode('33100'); //ok
  8. $pc5 = $dpd->checkPostCode('00-000'); //wrong

For more examples see unit tests

Notes

For current API specification you should contact with IT support of DPD Poland. http://www.dpd.com.pl/

License

MIT