Initial xentral_oss_20.3.c9ffacf

This commit is contained in:
Alex
2021-05-21 08:49:41 +02:00
parent 5406e4a551
commit 34e5ac43d9
18884 changed files with 2109867 additions and 0 deletions
+238
View File
@@ -0,0 +1,238 @@
<?php
namespace Xentral\Modules\Dhl\Api;
use PHPUnit\Runner\Exception;
use SoapFault;
use SoapHeader;
use SoapVar;
use stdClass;
use Xentral\Modules\Dhl\Exception\InsufficientPermissionsException;
use Xentral\Modules\Dhl\Exception\InvalidCredentialsException;
use Xentral\Modules\Dhl\Request\CreateNationalShipmentRequest;
use Xentral\Modules\Dhl\Request\GetManifestRequest;
use Xentral\Modules\Dhl\Request\GetVersionRequest;
use Xentral\Modules\Dhl\Response\CreateShipmentResponse;
use Xentral\Modules\Dhl\Response\GetVersionResponse;
/**
* Class DhlApi
*
* @package Xentral\Modules\Dhl\api
*/
class DhlApi
{
/** @var string */
private $user;
/** @var string */
private $pass;
/** @var string */
private $accountNumber;
/** @var string */
private $basicUsername;
/** @var string */
private $basicPassword;
/** @var string */
private $endpoint;
/** @var string */
private $senderName;
/** @var string */
private $senderStreetName;
/** @var int */
private $senderStreetNo;
/** @var string */
private $senderZip;
/** @var string */
private $senderCity;
/** @var string */
private $senderCountry;
/** @var string */
private $senderEmail;
/** @var int */
private $versionMajor = 3;
/** @var int */
private $versionMino = 0;
/**
* DhlApi constructor.
*
* @param string $user
* @param string $pass
* @param string $basicUsername
* @param string $basicPassword
* @param string $accountNumber
* @param string $endpoint
* @param string $senderName
* @param string $senderStreetName
* @param int $senderStreetNo
* @param string $senderZip
* @param string $senderCity
* @param string $senderCountry
* @param $senderEmail
*/
public function __construct(
$user,
$pass,
$basicUsername,
$basicPassword,
$accountNumber,
$endpoint,
$senderName,
$senderStreetName,
$senderStreetNo,
$senderZip,
$senderCity,
$senderCountry,
$senderEmail
) {
$this->user = $user;
$this->pass = $pass;
$this->basicUsername = $basicUsername;
$this->basicPassword = $basicPassword;
$this->accountNumber = $accountNumber;
$this->endpoint = $endpoint;
$this->senderName = $senderName;
$this->senderStreetName = $senderStreetName;
$this->senderStreetNo = $senderStreetNo;
$this->senderZip = $senderZip;
$this->senderCity = $senderCity;
$this->senderCountry = $senderCountry;
$this->senderEmail = $senderEmail;
}
/**
* @return GetVersionResponse
*/
public function getVersion()
{
$getVersionRequest = new GetVersionRequest($this->versionMajor, $this->versionMino);
$postFields = $getVersionRequest->toXml(
$this->user,
$this->pass
);
$response = $this->performRequest($postFields, 'getVersion');
return GetVersionResponse::fromResponseXml($response);
}
/**
* @param string $manifestDate
*
* @return GetVersionResponse
*/
public function getManifest($manifestDate)
{
$getManifestRequest = new GetManifestRequest($manifestDate);
$postFields = $getManifestRequest->toXml(
$this->user,
$this->pass
);
$response = $this->performRequest($postFields, 'getManifest');
return GetVersionResponse::fromResponseXml($response);
}
/**
* @param CreateNationalShipmentRequest $createShipmentRequest
*
* @return CreateShipmentResponse
*/
public function createShipment($createShipmentRequest)
{
$postFields = $createShipmentRequest->toXml(
$this->user,
$this->pass,
$this->accountNumber,
$this->senderName,
$this->senderStreetName,
$this->senderStreetNo,
$this->senderZip,
$this->senderCity,
$this->senderCountry,
$this->senderEmail
);
$response = $this->performRequest($postFields, 'createShipmentOrder');
return CreateShipmentResponse::fromResponseXml($response);
}
/**
* @param CreateNationalShipmentRequest $createShipmentRequest
*
* @return CreateShipmentResponse
*/
public function validateShipment($createShipmentRequest)
{
$postFields = $createShipmentRequest->toXml(
$this->user,
$this->pass,
$this->accountNumber,
$this->senderName,
$this->senderStreetName,
$this->senderStreetNo,
$this->senderZip,
$this->senderCity,
$this->senderCountry,
$this->senderEmail
);
$response = $this->performRequest($postFields, 'validateShipment');
return CreateShipmentResponse::fromResponseXml($response);
}
private function performRequest($payload, $method)
{
$curl = curl_init($this->endpoint);
curl_setopt_array(
$curl,
[
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Basic ' . base64_encode("{$this->basicUsername}:{$this->basicPassword}"),
'Content-Type: application/xml; charset=utf-8',
"SOAPAction: urn:{$method}",
],
]
);
$response = curl_exec($curl);
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$this->checkHttpCode($responseCode);
return $response;
}
/**
* @param int $responseCode
*/
private function checkHttpCode($responseCode)
{
switch ($responseCode) {
case 401:
throw new InvalidCredentialsException("");
case 403:
throw new InsufficientPermissionsException();
}
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Xentral\Modules\Dhl;
use Xentral\Core\DependencyInjection\ContainerInterface;
use Xentral\Modules\Dhl\Api\DhlApi;
use Xentral\Modules\Dhl\Factory\DhlApiFactory;
use Xentral\Modules\DocuvitaApi\Exception\ConfigurationMissingException;
final class Bootstrap
{
/**
* @return array
*/
public static function registerServices()
{
return [
'DhlApiFactory' => 'onInitDhlApiFactory',
];
}
/**
* @param ContainerInterface $container
*
* @return DhlApiFactory
*/
public static function onInitDhlApiFactory(ContainerInterface $container)
{
return new DhlApiFactory();
}
}
@@ -0,0 +1,142 @@
<?php
namespace Xentral\Modules\Dhl\Content;
use Xentral\Modules\Dhl\Exception\ContentsDataException;
/**
* Class PackageContent
*
* @package Xentral\Modules\Dhl\Content
*/
class PackageContent
{
/** @var int */
private $amount;
/** @var string */
private $description;
/** @var float */
private $value;
/** @var string ISO-2 */
private $countryOfOrigin;
/** @var string */
private $customsTariffNumber;
/** @var float */
private $weightInKg;
/**
* PackageContent constructor.
*
* @param int $amount
* @param string $description
* @param float $value
* @param string $countryOfOrigin
* @param string $customsTariffNumber
* @param float $weightInKg
*/
public function __construct($amount, $description, $value, $countryOfOrigin, $customsTariffNumber, $weightInKg)
{
$this->checkDescription($description);
$this->checkAmount($description, $amount);
$this->checkWeight($description, $weightInKg);
$this->checkCountryOfOrigin($description, $countryOfOrigin);
$this->checkTariffNumber($description, $customsTariffNumber);
$this->checkValue($description, $value);
$this->description = $description;
$this->amount = $amount;
$this->value = $value;
$this->countryOfOrigin = $countryOfOrigin;
$this->customsTariffNumber = $customsTariffNumber;
$this->weightInKg = $weightInKg;
}
private function checkWeight($itemName, $weight){
if($weight <= 0){
throw new ContentsDataException("Falsches Gewicht von '{$itemName}'");
}
}
private function checkTariffNumber($itemName, $number){
if(empty($number)){
throw new ContentsDataException("Falsche Zolltarifnummer von '{$itemName}'");
}
}
private function checkCountryOfOrigin($itemName, $country){
if(strlen($country) !== 2){
throw new ContentsDataException("Herkunftsland von '{$itemName}' muss ISO-alpha-2 sein");
}
}
private function checkValue($itemName, $value){
if($value <= 0){
throw new ContentsDataException("Falscher wert von '{$itemName}': {$value}");
}
}
private function checkAmount($itemName, $amount){
if($amount <= 0){
throw new ContentsDataException("Falsche Menge bei position '{$itemName}': {$amount}");
}
}
private function checkDescription($description){
if(empty($description)){
throw new ContentsDataException('Fehlende Beschreibung in Positionen');
}
}
/**
* @return float
*/
public function getWeightInKg()
{
return $this->weightInKg;
}
/**
* @return int
*/
public function getAmount()
{
return $this->amount;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @return float
*/
public function getValue()
{
return $this->value;
}
/**
* @return string
*/
public function getCountryOfOrigin()
{
return $this->countryOfOrigin;
}
/**
* @return string
*/
public function getCustomsTariffNumber()
{
return $this->customsTariffNumber;
}
}
@@ -0,0 +1,8 @@
<?php
namespace Xentral\Modules\Dhl\Exception;
class ContentsDataException extends DhlBaseException
{
}
@@ -0,0 +1,15 @@
<?php
namespace Xentral\Modules\Dhl\Exception;
class DhlBaseException extends \RuntimeException implements DhlExceptionInterface
{
public static function fromDhlStatusCode($code, $message)
{
switch ($code){
case 118: return new InvalidCredentialsException($message);
case 1101: return new InvalidRequestDataException($message);
}
return new DhlBaseException($message);
}
}
@@ -0,0 +1,12 @@
<?php
namespace Xentral\Modules\Dhl\Exception;
use Xentral\Core\Exception\ModuleExceptionInterface;
interface DhlExceptionInterface extends ModuleExceptionInterface
{
}
@@ -0,0 +1,13 @@
<?php
namespace Xentral\Modules\Dhl\Exception;
use Throwable;
class InsufficientPermissionsException extends DhlBaseException
{
public function __construct($message = "Unzureichende Rechte", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
@@ -0,0 +1,13 @@
<?php
namespace Xentral\Modules\Dhl\Exception;
use Throwable;
class InvalidCredentialsException extends DhlBaseException
{
public function __construct($message, $code = 0, Throwable $previous = null)
{
parent::__construct("Fehlerhafte Zugangsdaten ({$message})", $code, $previous);
}
}
@@ -0,0 +1,8 @@
<?php
namespace Xentral\Modules\Dhl\Exception;
class InvalidRequestDataException extends DhlBaseException
{
}
@@ -0,0 +1,14 @@
<?php
namespace Xentral\Modules\Dhl\Exception;
use Throwable;
class UnknownProductException extends DhlBaseException
{
public function __construct($message = "Falsch konfiguriertes Produkt", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
@@ -0,0 +1,16 @@
<?php
namespace Xentral\Modules\Dhl\Exception;
use Throwable;
class UnknownProductTypeException extends DhlBaseException
{
static public function fromValid($validValues){
return new UnknownProductTypeException("ProductType muss eines aus folgenden sein: {$validValues}");
}
static public function invalidDescription(){
return new UnknownProductTypeException('Produktbeschreibung muss gegeben sein');
}
}
@@ -0,0 +1,42 @@
<?php
namespace Xentral\Modules\Dhl\Factory;
use Xentral\Modules\Dhl\Api\DhlApi;
/**
* Class DhlApiFactory
*
* @package Xentral\Modules\Dhl\Factory
*/
class DhlApiFactory
{
public static function createProductionInstance(
$user,
$pass,
$accountNumber,
$senderName,
$senderStreetName,
$senderStreetNo,
$senderZip,
$senderCity,
$senderCountry,
$senderEmail
) {
return new DhlApi(
$user,
$pass,
'wawision_2',
'SQBKcoTz8GgOUp31VNyoZfWooSad3n',
$accountNumber,
'https://cig.dhl.de/services/production/soap',
$senderName,
$senderStreetName,
$senderStreetNo,
$senderZip,
$senderCity,
$senderCountry,
$senderEmail
);
}
}
@@ -0,0 +1,226 @@
<?php
namespace Xentral\Modules\Dhl\Request;
use Xentral\Modules\Dhl\Content\PackageContent;
use Xentral\Modules\Dhl\Exception\UnknownProductTypeException;
/**
* Class CreateShipmentRequest
*
* @package Xentral\Modules\Dhl\Request
*/
class CreateInterationalShipmentRequest extends CreateNationalShipmentRequest
{
/** @var string */
private $productType;
/** @var string */
private $productTypeDescription;
/** @var PackageContent[] */
private $packageContents;
public function __construct(
$shipmentDate,
$weight,
$length,
$width,
$height,
$name1,
$name2,
$name3,
$street,
$streetNo,
$zip,
$city,
$country,
$email,
$printOnlyIfCodeable,
$productType,
$productTypeDescription,
$packageContents
) {
parent::__construct(
$shipmentDate,
$weight,
$length,
$width,
$height,
$name1,
$name2,
$name3,
$street,
$streetNo,
$zip,
$city,
$country,
$email,
$printOnlyIfCodeable
);
$this->product = 'V53WPAK';
$this->productType = $productType;
$this->productTypeDescription = $productTypeDescription;
$this->packageContents = $packageContents;
}
/**
* @param $username
* @param $password
* @param $accountNumber
* @param $senderName
* @param $senderStreetName
* @param $senderStreetNo
* @param $senderZip
* @param $senderCity
* @param $senderCountry
* @param $senderEmail
*
* @return string
*/
public
function toXml(
$username,
$password,
$accountNumber,
$senderName,
$senderStreetName,
$senderStreetNo,
$senderZip,
$senderCity,
$senderCountry,
$senderEmail
) {
if (!in_array($this->productType, ['OTHER', 'PRESENT', 'COMMERCIAL_SAMPLE', 'DOCUMENT', 'RETURN_OF_GOODS'])) {
throw UnknownProductTypeException::fromValid(
"'OTHER', 'PRESENT', 'COMMERCIAL_SAMPLE', 'DOCUMENT', 'RETURN_OF_GOODS'"
);
}
$productTypeDescriptionXml = '';
if ($this->productType == 'OTHER') {
if (empty($this->productTypeDescription)) {
throw UnknownProductTypeException::invalidDescription();
}
$productTypeDescriptionXml = "<exportTypeDescription>{$this->productTypeDescription}</exportTypeDescription>";
}
$contentsRoot = new \SimpleXMLElement('<root></root>');
foreach ($this->packageContents as $packageContent){
$contentRoot = $contentsRoot->addChild('ExportDocPosition');
$contentRoot->addChild('description', $packageContent->getDescription());
$contentRoot->addChild('countryCodeOrigin', $packageContent->getCountryOfOrigin());
$contentRoot->addChild('customsTariffNumber', $packageContent->getCustomsTariffNumber());
$contentRoot->addChild('amount', $packageContent->getAmount());
$contentRoot->addChild('netWeightInKG', $packageContent->getWeightInKg());
$contentRoot->addChild('customsValue', $packageContent->getValue());
}
$contentsXml = '';
foreach ($contentsRoot->children() as $child){
$contentsXml .= $child->asXml();
}
$printOnlyIfCodeableActive = $this->printOnlyIfCodeable ? '1' : '0';
$payload = <<<XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cis="http://dhl.de/webservice/cisbase" xmlns:ns="http://dhl.de/webservices/businesscustomershipping/3.0">
<soapenv:Header>
<cis:Authentification>
<cis:user>{$username}</cis:user>
<cis:signature>{$password}</cis:signature>
</cis:Authentification>
</soapenv:Header>
<soapenv:Body>
<ns:CreateShipmentOrderRequest>
<ns:Version>
<majorRelease>3</majorRelease>
<minorRelease>0</minorRelease>
<build>1</build>
</ns:Version>
<ShipmentOrder>
<sequenceNumber>?</sequenceNumber>
<Shipment>
<ShipmentDetails>
<product>{$this->product}</product>
<cis:accountNumber>{$accountNumber}</cis:accountNumber>
<customerReference/>
<shipmentDate>{$this->shipmentDate}</shipmentDate>
<costCentre/>
<ShipmentItem>
<weightInKG>{$this->weight}</weightInKG>
<lengthInCM>{$this->length}</lengthInCM>
<widthInCM>{$this->width}</widthInCM>
<heightInCM>{$this->height}</heightInCM>
</ShipmentItem>
<Service>
</Service>
<Notification>
<recipientEmailAddress/>
</Notification>
</ShipmentDetails>
<Shipper>
<Name>
<cis:name1>{$senderName}</cis:name1>
</Name>
<Address>
<cis:streetName>{$senderStreetName}</cis:streetName>
<cis:streetNumber>{$senderStreetNo}</cis:streetNumber>
<cis:addressAddition/>
<cis:dispatchingInformation/>
<cis:zip>{$senderZip}</cis:zip>
<cis:city>{$senderCity}</cis:city>
<cis:province/>
<cis:Origin>
<cis:countryISOCode>{$senderCountry}</cis:countryISOCode>
<cis:state/>
</cis:Origin>
</Address>
<Communication>
<cis:phone/>
<cis:email>{$senderEmail}</cis:email>
<cis:contactPerson/>
</Communication>
</Shipper>
<Receiver>
<cis:name1>{$this->name1}</cis:name1>
<Address>
<cis:name2>{$this->name2}</cis:name2>
<cis:name3>{$this->name3}</cis:name3>
<cis:streetName>{$this->street}</cis:streetName>
<cis:streetNumber>{$this->streetNo}</cis:streetNumber>
<cis:addressAddition/>
<cis:dispatchingInformation/>
<cis:zip>{$this->zip}</cis:zip>
<cis:city>{$this->city}</cis:city>
<cis:province/>
<cis:Origin>
<cis:countryISOCode>{$this->country}</cis:countryISOCode>
<cis:state/>
</cis:Origin>
</Address>
<Communication>
<cis:phone/>
<cis:email>{$this->email}</cis:email>
<cis:contactPerson/>
</Communication>
</Receiver>
<ExportDocument>
<exportType>{$this->productType}</exportType>
{$productTypeDescriptionXml}
<placeOfCommital>{$senderCity}</placeOfCommital>
<additionalFee>0</additionalFee>
{$contentsXml}
</ExportDocument>
</Shipment>
<PrintOnlyIfCodeable active="{$printOnlyIfCodeableActive}"/>
</ShipmentOrder>
<labelResponseType>B64</labelResponseType>
</ns:CreateShipmentOrderRequest>
</soapenv:Body>
</soapenv:Envelope>
XML;
return $payload;
}
}
@@ -0,0 +1,210 @@
<?php
namespace Xentral\Modules\Dhl\Request;
/**
* Class CreateShipmentRequest
*
* @package Xentral\Modules\Dhl\Request
*/
class CreateNationalShipmentRequest
{
/** @var string */
protected $product;
/** @var string */
protected $shipmentDate;
/** @var float */
protected $weight;
/** @var float */
protected $length;
/** @var float */
protected $width;
/** @var float */
protected $height;
/** @var string */
protected $name1;
/** @var string */
protected $name2;
/** @var string */
protected $name3;
/** @var string */
protected $street;
/** @var string */
protected $streetNo;
/** @var string */
protected $zip;
/** @var string */
protected $city;
/** @var string */
protected $country;
/** @var string */
protected $email;
/** @var boolean */
protected $printOnlyIfCodeable;
/**
* CreateShipmentRequest constructor.
*
* @param string $shipmentDate
* @param float $weight
* @param float $length
* @param float $width
* @param float $height
* @param string $name1
* @param string $name2
* @param string $name3
* @param string $street
* @param string $streetNo
* @param string $zip
* @param string $city
* @param string $country
* @param string $email
* @param boolean $printOnlyIfCodeable
*/
public function __construct(
$shipmentDate,
$weight,
$length,
$width,
$height,
$name1,
$name2,
$name3,
$street,
$streetNo,
$zip,
$city,
$country,
$email,
$printOnlyIfCodeable
) {
$this->product = 'V01PAK';
$this->shipmentDate = $shipmentDate;
$this->weight = $weight;
$this->length = $length;
$this->width = $width;
$this->height = $height;
$this->name1 = $name1;
$this->name2 = $name2;
$this->name3 = $name3;
$this->street = $street;
$this->streetNo = $streetNo;
$this->zip = $zip;
$this->city = $city;
$this->country = $country;
$this->email = $email;
$this->printOnlyIfCodeable = $printOnlyIfCodeable;
}
/**
* @param string $username
* @param string $password
* @param string $accountNumber
* @param string $senderName
* @param string $senderStreetName
* @param string $senderStreetNo
* @param string $senderZip
* @param string $senderCity
* @param string $senderCountry
* @param string $senderEmail
*
* @return string
*/
public function toXml($username, $password, $accountNumber, $senderName, $senderStreetName, $senderStreetNo, $senderZip, $senderCity, $senderCountry, $senderEmail)
{
$printOnlyIfCodeableActive = $this->printOnlyIfCodeable ? '1' : '0';
$payload = <<<XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cis="http://dhl.de/webservice/cisbase" xmlns:ns="http://dhl.de/webservices/businesscustomershipping/3.0">
<soapenv:Header>
<cis:Authentification>
<cis:user>{$username}</cis:user>
<cis:signature>{$password}</cis:signature>
</cis:Authentification>
</soapenv:Header>
<soapenv:Body>
<ns:CreateShipmentOrderRequest>
<ns:Version>
<majorRelease>3</majorRelease>
<minorRelease>0</minorRelease>
<build>1</build>
</ns:Version>
<ShipmentOrder>
<sequenceNumber>?</sequenceNumber>
<Shipment>
<ShipmentDetails>
<product>{$this->product}</product>
<cis:accountNumber>{$accountNumber}</cis:accountNumber>
<customerReference/>
<shipmentDate>{$this->shipmentDate}</shipmentDate>
<costCentre/>
<ShipmentItem>
<weightInKG>{$this->weight}</weightInKG>
<lengthInCM>{$this->length}</lengthInCM>
<widthInCM>{$this->width}</widthInCM>
<heightInCM>{$this->height}</heightInCM>
</ShipmentItem>
<Service>
</Service>
<Notification>
<recipientEmailAddress/>
</Notification>
</ShipmentDetails>
<Shipper>
<Name>
<cis:name1>{$senderName}</cis:name1>
</Name>
<Address>
<cis:streetName>{$senderStreetName}</cis:streetName>
<cis:streetNumber>{$senderStreetNo}</cis:streetNumber>
<cis:addressAddition/>
<cis:dispatchingInformation/>
<cis:zip>{$senderZip}</cis:zip>
<cis:city>{$senderCity}</cis:city>
<cis:province/>
<cis:Origin>
<cis:countryISOCode>{$senderCountry}</cis:countryISOCode>
<cis:state/>
</cis:Origin>
</Address>
<Communication>
<cis:phone/>
<cis:email>{$senderEmail}</cis:email>
<cis:contactPerson/>
</Communication>
</Shipper>
<Receiver>
<cis:name1>{$this->name1}</cis:name1>
<Address>
<cis:name2>{$this->name2}</cis:name2>
<cis:name3>{$this->name3}</cis:name3>
<cis:streetName>{$this->street}</cis:streetName>
<cis:streetNumber>{$this->streetNo}</cis:streetNumber>
<cis:addressAddition/>
<cis:dispatchingInformation/>
<cis:zip>{$this->zip}</cis:zip>
<cis:city>{$this->city}</cis:city>
<cis:province/>
<cis:Origin>
<cis:countryISOCode>{$this->country}</cis:countryISOCode>
<cis:state/>
</cis:Origin>
</Address>
<Communication>
<cis:phone/>
<cis:email>{$this->email}</cis:email>
<cis:contactPerson/>
</Communication>
</Receiver>
</Shipment>
<PrintOnlyIfCodeable active="{$printOnlyIfCodeableActive}"/>
</ShipmentOrder>
<labelResponseType>B64</labelResponseType>
</ns:CreateShipmentOrderRequest>
</soapenv:Body>
</soapenv:Envelope>
XML;
return $payload;
}
}
@@ -0,0 +1,52 @@
<?php
namespace Xentral\Modules\Dhl\Request;
/**
* Class GetManifestRequest
*
* @package Xentral\Modules\Dhl\Request
*/
class GetManifestRequest
{
private $manifestDate;
public function __construct(
$manifestDate
) {
$this->manifestDate = $manifestDate;
}
/**
* @param string $username
* @param string $password
*
* @return string
*/
public function toXml($username, $password)
{
$payload = <<<XML
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://dhl.de/webservices/businesscustomershipping/3.0"
xmlns:cis="http://dhl.de/webservice/cisbase">
<soapenv:Header>
<cis:Authentification>
<cis:user>{$username}</cis:user>
<cis:signature>{$password}</cis:signature>
</cis:Authentification>
</soapenv:Header>
<soapenv:Body>
<ns:Version>
<majorRelease>3</majorRelease>
<minorRelease>0</minorRelease>
</ns:Version>
<manifestDate>$this->manifestDate</manifestDate>
</soapenv:Body>
</soapenv:Envelope>
XML;
return $payload;
}
}
@@ -0,0 +1,54 @@
<?php
namespace Xentral\Modules\Dhl\Request;
/**
* Class CreateShipmentRequest
*
* @package Xentral\Modules\Dhl\Request
*/
class GetVersionRequest
{
private $major;
private $minor;
public function __construct(
$major,
$minor
) {
$this->major = $major;
$this->minor = $minor;
}
/**
* @param string $username
* @param string $password
*
* @return string
*/
public function toXml($username, $password)
{
$payload = <<<XML
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://dhl.de/webservices/businesscustomershipping/3.0"
xmlns:cis="http://dhl.de/webservice/cisbase">
<soapenv:Header>
<cis:Authentification>
<cis:user>{$username}</cis:user>
<cis:signature>{$password}</cis:signature>
</cis:Authentification>
</soapenv:Header>
<soapenv:Body>
<ns:Version>
<majorRelease>{$this->major}</majorRelease>
<minorRelease>{$this->minor}</minorRelease>
</ns:Version>
</soapenv:Body>
</soapenv:Envelope>
XML;
return $payload;
}
}
@@ -0,0 +1,78 @@
<?php
namespace Xentral\Modules\Dhl\Response;
use Xentral\Modules\Dhl\Exception\DhlBaseException;
use Xentral\Modules\Dhl\Exception\InvalidRequestDataException;
/**
* Class BaseResponse
*
* @package Xentral\Modules\Dhl\Response
*/
class BaseResponse
{
/**
* @param string $responseXml
*
* @return \SimpleXMLElement
*/
public static function createXmlElement($responseXml){
$xmlElement = new \SimpleXMLElement($responseXml);
$xmlElement->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xmlElement->registerXPathNamespace('bcs', 'http://dhl.de/webservices/businesscustomershipping/3.0');
$faultString = $xmlElement->xpath('/SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/faultstring');
if (!empty($faultString)) {
$faultString = (string)$faultString[0];
if (!empty($faultString)) {
throw new DhlBaseException($faultString);
}
}
$faultString = $xmlElement->xpath('/soap:Envelope/soap:Body/soap:Fault/faultstring');
if (!empty($faultString)) {
$faultString = (string)$faultString[0];
if (!empty($faultString)) {
throw new DhlBaseException($faultString);
}
}
$statusCode = $xmlElement->xpath('/soap:Envelope/soap:Body/bcs:CreateShipmentOrderResponse/Status/statusCode');
$statusCode = (int)$statusCode[0];
if ($statusCode != 0) {
$errorMessages = array_merge(
$xmlElement->xpath(
'/soap:Envelope/soap:Body/bcs:CreateShipmentOrderResponse/Status/statusText'
),
$xmlElement->xpath(
'/soap:Envelope/soap:Body/bcs:CreateShipmentOrderResponse/CreationState/LabelData/Status/statusMessage'
)
);
$errorMsg = implode(' ', array_map(function ($error){
return (string) $error;
}, $errorMessages));
throw DhlBaseException::fromDhlStatusCode($statusCode, $errorMsg);
}
$statusCode = $xmlElement->xpath('/soap:Envelope/soap:Body/bcs:CreateShipmentOrderResponse/CreationState/LabelData/Status/statusCode');
$statusCode = (int)$statusCode[0];
if ($statusCode != 0) {
$errorMessages = $xmlElement->xpath(
'/soap:Envelope/soap:Body/bcs:CreateShipmentOrderResponse/CreationState/LabelData/Status/statusMessage'
);
$errorMsg = implode(' ', array_map(function ($error){
return (string) $error;
}, $errorMessages));
throw new InvalidRequestDataException($errorMsg);
}
return $xmlElement;
}
}
@@ -0,0 +1,107 @@
<?php
namespace Xentral\Modules\Dhl\Response;
use Xentral\Modules\Dhl\Exception\DhlBaseException;
use Xentral\Modules\Dhl\Exception\InvalidRequestDataException;
/**
* Class CreateShipmentResponse
*
* @package Xentral\Modules\Dhl\Response
*/
class CreateShipmentResponse extends BaseResponse
{
/** @var string */
private $label;
/** @var string */
private $shipmentNumer;
/** @var string */
private $exportDocument;
/**
* CreateShipmentResponse constructor.
*
* @param string $label
* @param string $shipmentNumber
*/
public function __construct($label, $shipmentNumber)
{
$this->label = $label;
$this->shipmentNumer = $shipmentNumber;
}
/**
* @param string $exportDocument
*/
public function setExportDocument($exportDocument)
{
$this->exportDocument = $exportDocument;
}
/**
* @param string $responseXml
*
* @return CreateShipmentResponse
*/
public static function fromResponseXml($responseXml)
{
$xmlElement = parent::createXmlElement($responseXml);
$label = $xmlElement->xpath(
'/soap:Envelope/soap:Body/bcs:CreateShipmentOrderResponse/CreationState/LabelData/labelData'
);
$shipmentNumber = $xmlElement->xpath(
'/soap:Envelope/soap:Body/bcs:CreateShipmentOrderResponse/CreationState/shipmentNumber'
);
$exportDoc = $xmlElement->xpath(
'/soap:Envelope/soap:Body/bcs:CreateShipmentOrderResponse/CreationState/LabelData/exportLabelData'
);
$response = new CreateShipmentResponse(
base64_decode((string)$label[0]),
(string)$shipmentNumber[0]
);
if (!empty($exportDoc)) {
$response->setExportDocument(base64_decode((string)$exportDoc[0]));
}
return $response;
}
/**
* @return string
*/
public function getShipmentNumber()
{
return $this->shipmentNumer;
}
/**
* @return bool
*/
public function containsExportDocuments()
{
return !empty($this->exportDocument);
}
/**
* @return string downloaded pdf as string
*/
public function getExportPaperAsPdf()
{
return $this->exportDocument;
}
/**
* @return string downloaded pdf as string
*/
public function getLabelAsPdf()
{
return $this->label;
}
}
@@ -0,0 +1,35 @@
<?php
namespace Xentral\Modules\Dhl\Response;
use phpDocumentor\Reflection\DocBlock\Tags\Param;
use Xentral\Modules\Dhl\Exception\DhlBaseException;
use Xentral\Modules\Dhl\Exception\InvalidRequestDataException;
/**
* Class GetManifestResponse
*
* @package Xentral\Modules\Dhl\Response
*/
class GetManifestResponse extends BaseResponse
{
/**
* GetVersionResponse constructor.
*
*/
public function __construct()
{
}
/**
* @param string $responseXml
*
* @return GetManifestResponse
*/
public static function fromResponseXml($responseXml)
{
$xmlElement = parent::createXmlElement($responseXml);
return new GetManifestResponse();
}
}
@@ -0,0 +1,34 @@
<?php
namespace Xentral\Modules\Dhl\Response;
use Xentral\Modules\Dhl\Exception\DhlBaseException;
use Xentral\Modules\Dhl\Exception\InvalidRequestDataException;
/**
* Class CreateShipmentResponse
*
* @package Xentral\Modules\Dhl\Response
*/
class GetVersionResponse extends BaseResponse
{
/**
* GetVersionResponse constructor.
*
*/
public function __construct()
{
}
/**
* @param string $responseXml
*
* @return GetVersionResponse
*/
public static function fromResponseXml($responseXml)
{
$xmlElement = parent::createXmlElement($responseXml);
return new GetVersionResponse();
}
}