Giter VIP home page Giter VIP logo

dhl-sdk-api-bcs-returns's Introduction

DHL Paket Retoure API SDK

The DHL Paket Retoure API SDK package offers an interface to the following web services:

  • API Retoure

Requirements

System Requirements

  • PHP 7.2+ with JSON extension

Package Requirements

  • php-http/discovery: Discovery service for HTTP client and message factory implementations
  • php-http/httplug: Pluggable HTTP client abstraction
  • php-http/logger-plugin: HTTP client logger plugin for HTTPlug
  • psr/http-client: PSR-18 HTTP client interfaces
  • psr/http-factory: PSR-7 HTTP message factory interfaces
  • psr/http-message: PSR-7 HTTP message interfaces
  • psr/log: PSR-3 logger interfaces

Virtual Package Requirements

  • psr/http-client-implementation: Any package that provides a PSR-18 compatible HTTP client
  • psr/http-factory-implementation: Any package that provides PSR-7 compatible HTTP message factories
  • psr/http-message-implementation: Any package that provides PSR-7 HTTP messages

Development Package Requirements

  • nyholm/psr7: PSR-7 HTTP message factory & message implementation
  • phpunit/phpunit: Testing framework
  • php-http/mock-client: HTTPlug mock client implementation
  • phpstan/phpstan: Static analysis tool
  • squizlabs/php_codesniffer: Static analysis tool

Installation

$ composer require dhl/sdk-api-bcs-returns

Uninstallation

$ composer remove dhl/sdk-api-bcs-returns

Testing

$ ./vendor/bin/phpunit -c test/phpunit.xml

Features

The DHL Paket Retoure API SDK supports the following features:

Return Label Service

Create a return label PDF or QR code to be scanned by a place of committal (e.g. post office). For return shipments from outside of the EU, a customs document can also be requested.

Public API

The library's components suitable for consumption comprise of

  • service:
    • service factory
    • return label service
    • data transfer object builder
  • data transfer objects:
    • authentication storage
    • booking confirmation with label data

Usage

$authStorage = new \Dhl\Sdk\Paket\Retoure\Auth\AuthenticationStorage(
    'applicationId',
    'applicationToken',
    'user',
    'signature'
);
$logger = new \Psr\Log\NullLogger();

$serviceFactory = new \Dhl\Sdk\Paket\Retoure\Service\ServiceFactory();
$service = $serviceFactory->createReturnLabelService($authStorage, $logger, $sandbox = true);

$requestBuilder = new \Dhl\Sdk\Paket\Retoure\Model\ReturnLabelRequestBuilder();
$requestBuilder->setAccountDetails($receiverId = 'deu');
$requestBuilder->setShipperAddress(
    $name = 'Jane Doe',
    $countryCode = 'DEU',
    $postalCode = '53113',
    $city = 'Bonn',
    $streetName = 'Sträßchensweg',
    $streetNumber = '2'
);

$returnOrder = $requestBuilder->create();
$confirmation = $service->bookLabel($returnOrder);

dhl-sdk-api-bcs-returns's People

Contributors

andreasmueller75 avatar magicsunday avatar mam08ixo avatar sebastian80 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dhl-sdk-api-bcs-returns's Issues

PHP 8.1 support

Hello,

we want to upgrade Laravel 9 to 1, but monolog need psr/log ^2.* support.

Can you please update the dependencies with support for PHP 8.1?

Thank you very much.

Undefined index: qrLabelData for international return labels

I am receiving the following error when using the SDK to create a return label:

Undefined index: qrLabelData in vendor/dhl/sdk-api-bcs-returns/src/Service/ReturnLabelService.php on line 92

So far I received this error while creating a return label for Spain and Finland. I am not sure how many other countries are affected. The line in question:

$qrLabelData = $responseData['qrLabelData'] ?: '';

should probably be:

$qrLabelData = $responseData['qrLabelData'] ?? '';

since it seems the qrLabelData key can be missing entirely. I was able to reproduce this error for both the sandbox and the live API.

ReturnLabelErrorPlugin::createErrorMessage() must be of the type array, null given

Using version 2.0.1 atm, but seems to be the same code in master.

Error:

Argument 1 passed to Dhl\Sdk\Paket\Retoure\Http\ClientPlugin\ReturnLabelErrorPlugin::createErrorMessage() must be of the type array, null given, called in /var/www/html/vendor/dhl/sdk-api-bcs-returns/src/Http/ClientPlugin/ReturnLabelErrorPlugin.php on line 85

Link (master): https://github.com/netresearch/dhl-sdk-api-bcs-returns/blob/master/src/Http/ClientPlugin/ReturnLabelErrorPlugin.php#L85

What happen:
The response body seems to be empty.
So json_decode will return NULL because it cannot decode.
At $this->createErrorMessage() we then provide NULL to an expected array parameter which causes the error.

Info:
DHL currently has some error or maintenance on the retoure API
and i guess they return an empty body.
image

Funktion Retoure: Aufgrund eines Fehlers ist die Funktion aktuell nicht aufrufbar. Die Fehlerbehebung ist bereits in Arbeit. Wir bitte um Entschuldigung für die Unannehmlichkeiten.

Possible solution:

$responseJson = (string)$response->getBody();
$responseData = \json_decode($responseJson, true);
if (!is_array($responseData)) {
    // Could not json_decode body.
    // This could be an empty body due to Maintenance at DHL retoure API.
    $responseData = [];
}
$errorMessage = $this->createErrorMessage($responseData, $response->getReasonPhrase());

Name with special chars: Bad request (Error 400)

Receiving Bad request (Error 400) (and nothing more) from DHL if the name contains special chars like à.

Note: the source of the name string was in my case another api.

When i tried to copy and past the name it worked. Seems to be an encoding problem.

Im posting this because the DHL API does not mention anything about that.

You only get 400 | Fehlerhafter Aufruf(Bad Request). | Syntax des Aufrufs prüfen. from the documentation.

Where: at the shipper address name:

$requestBuilder->setShipperAddress(
    $name = 'Adrià Fernández', // <---------------------
    $countryCode = 'DEU',
    $postalCode = '53113',
    $city = 'Bonn',
    $streetName = 'Sträßchensweg',
    $streetNumber = '2'
);

I fixed this using $name = utf8_encode($name); before sending it to DHL.
But this is more like a quick fix, since the label then prints Ã.

EDIT:
found the actual cause of my problem: i had a regex that was not using the u-option (/.../u ).\

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.