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
@@ -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();
}
}