Basic DHL implementation, Refactor redundant code
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Bank
|
||||
{
|
||||
public string $accountOwner;
|
||||
public string $bankName;
|
||||
public string $iban;
|
||||
public string $note1;
|
||||
public string $note2;
|
||||
public ?string $bic;
|
||||
public ?string $accountreference;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Communication
|
||||
{
|
||||
public ?string $phone;
|
||||
public ?string $email;
|
||||
public ?string $contactPerson;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Contact
|
||||
{
|
||||
public ?Communication $Communication;
|
||||
public ?NativeAddress $Address;
|
||||
public ?Name $Name;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Country
|
||||
{
|
||||
public ?string $country;
|
||||
public string $countryISOCode;
|
||||
public ?string $state;
|
||||
|
||||
public static function Create(string $isoCode, ?string $state = null):Country {
|
||||
$obj = new Country();
|
||||
$obj->countryISOCode = $isoCode;
|
||||
$obj->state = $state;
|
||||
return $obj;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class CreateShipmentOrderRequest
|
||||
{
|
||||
public Version $Version;
|
||||
public ShipmentOrder $ShipmentOrder;
|
||||
public ?string $labelResponseType;
|
||||
public ?string $groupProfileName;
|
||||
public ?string $labelFormat;
|
||||
public ?string $labelFormatRetoure;
|
||||
public ?string $combinedPrinting;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class CreateShipmentOrderResponse
|
||||
{
|
||||
public Version $Version;
|
||||
public Statusinformation $Status;
|
||||
public ?CreationState $CreationState;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class CreationState
|
||||
{
|
||||
public string $sequenceNumber;
|
||||
public ?string $shipmentNumber;
|
||||
public ?string $returnShipmentNumber;
|
||||
public LabelData $LabelData;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Customer
|
||||
{
|
||||
public Name $Name;
|
||||
public ?string $vatID;
|
||||
public string $EKP;
|
||||
public NativeAddress $Address;
|
||||
public Contact $Contact;
|
||||
public ?Bank $Bank;
|
||||
public ?string $note;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class DeleteShipmentOrderRequest
|
||||
{
|
||||
public Version $Version;
|
||||
public string $shipmentNumber;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class DeleteShipmentOrderResponse
|
||||
{
|
||||
public Version $Version;
|
||||
public Statusinformation $Status;
|
||||
public ?DeletionState $DeletionState;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class DeletionState
|
||||
{
|
||||
public string $shipmentNumber;
|
||||
public Statusinformation $Status;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class DeliveryAddress
|
||||
{
|
||||
public ?NativeAddress $NativeAddress;
|
||||
public ?Postfiliale $PostOffice;
|
||||
public ?PackStation $PackStation;
|
||||
public ?string $streetNameCode;
|
||||
public ?string $streetNumberCode;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Dimension
|
||||
{
|
||||
public int $length;
|
||||
public int $width;
|
||||
public int $height;
|
||||
public ?string $unit;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class ExportDocPosition
|
||||
{
|
||||
public string $description;
|
||||
public string $countryCodeOrigin;
|
||||
public string $customsTariffNumber;
|
||||
public int $amount;
|
||||
public float $netWeightInKG;
|
||||
public float $customsValue;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class ExportDocument
|
||||
{
|
||||
const TYPE_PRESENT = 'PRESENT';
|
||||
const TYPE_DOCUMENT = 'DOCUMENT';
|
||||
const TYPE_COMMERCIAL_GOODS = 'COMMERCIAL_GOODS';
|
||||
const TYPE_COMMERCIAL_SAMPLE = 'COMMERCIAL_SAMPLE';
|
||||
const TYPE_RETURN_OF_GOODS= 'RETURN_OF_GOODS';
|
||||
const TYPE_OTHER = 'OTHER';
|
||||
|
||||
const TERMS_DDP = 'DDP';
|
||||
const TERMS_DXV = 'DXV';
|
||||
const TERMS_DAP = 'DAP';
|
||||
const TERMS_DDX = 'DDX';
|
||||
const TERMS_CPT = 'CPT';
|
||||
|
||||
public ?string $invoiceNumber;
|
||||
public string $exportType;
|
||||
public ?string $exportTypeDescription;
|
||||
public ?string $termsOfTrade;
|
||||
public string $placeOfCommital;
|
||||
public ?float $additionalFee;
|
||||
public ?string $customsCurrency;
|
||||
public ?string $permitNumber;
|
||||
public ?string $attestationNumber;
|
||||
public ?string $addresseesCustomsReference;
|
||||
public ?string $sendersCustomsReference;
|
||||
public ?bool $WithElectronicExportNtfctn;
|
||||
/** @var ExportDocPosition[] $ExportDocPosition */
|
||||
public array $ExportDocPosition;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class LabelData
|
||||
{
|
||||
public Statusinformation $Status;
|
||||
public ?string $shipmentNumber;
|
||||
public ?string $labelUrl;
|
||||
public ?string $labelData;
|
||||
public ?string $returnLabelUrl;
|
||||
public ?string $returnLabelData;
|
||||
public ?string $exportLabelUrl;
|
||||
public ?string $exportLabelData;
|
||||
public ?string $codLabelUrl;
|
||||
public ?string $codLabelData;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Name
|
||||
{
|
||||
public string $name1;
|
||||
public ?string $name2;
|
||||
public ?string $name3;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class NativeAddress
|
||||
{
|
||||
public string $streetName;
|
||||
public ?string $streetNumber;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public array $addressAddition;
|
||||
public ?string $dispatchingInformation;
|
||||
public string $zip;
|
||||
public string $city;
|
||||
public ?string $province;
|
||||
public ?Country $Origin;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class NativeAddressNew
|
||||
{
|
||||
public string $streetName;
|
||||
public ?string $streetNumber;
|
||||
public string $zip;
|
||||
public string $city;
|
||||
public ?Country $Origin;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class PackStation
|
||||
{
|
||||
public string $postNumber;
|
||||
public string $packstationNumber;
|
||||
public string $zip;
|
||||
public string $city;
|
||||
public ?string $province;
|
||||
public ?Country $Origin;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Postfiliale
|
||||
{
|
||||
public string $postfilialeNumber;
|
||||
public string $postNumber;
|
||||
public string $zip;
|
||||
public string $city;
|
||||
public ?Country $Origin;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Receiver
|
||||
{
|
||||
public string $name1;
|
||||
public ?NativeAddress $Address;
|
||||
public ?PackStation $Packstation;
|
||||
public ?Postfiliale $Postfiliale;
|
||||
public ?Communication $Communication;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Shipment
|
||||
{
|
||||
public ShipmentDetails $ShipmentDetails;
|
||||
public Shipper $Shipper;
|
||||
public string $ShipperReference;
|
||||
public Receiver $Receiver;
|
||||
public ?Shipper $ReturnReceiver;
|
||||
public ?ExportDocument $ExportDocument;
|
||||
public ?string $feederSystem;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->ShipmentDetails = new ShipmentDetails();
|
||||
$this->Shipper = new Shipper();
|
||||
$this->ShipperReference = '';
|
||||
$this->Receiver = new Receiver();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
class ShipmentDetails
|
||||
{
|
||||
public string $product;
|
||||
public string $accountNumber;
|
||||
public string $customerReference;
|
||||
private string $shipmentDate;
|
||||
public string $costCentre;
|
||||
public string $returnShipmentAccountNumber;
|
||||
public string $returnShipmentReference;
|
||||
public ShipmentItem $ShipmentItem;
|
||||
public ShipmentService $Service;
|
||||
public ShipmentNotification $Notification;
|
||||
public Bank $BankData;
|
||||
|
||||
public function SetShipmentDate(DateTimeImmutable $date): void {
|
||||
$this->shipmentDate = $date->format('Y-m-d');
|
||||
}
|
||||
|
||||
public function GetShipmentDate(): DateTimeImmutable {
|
||||
return DateTimeImmutable::createFromFormat('Y-m-d', $this->shipmentDate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class ShipmentItem
|
||||
{
|
||||
public float $weightInKG;
|
||||
public ?int $lengthInCM;
|
||||
public ?int $widthInCM;
|
||||
public ?int $heightInCM;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class ShipmentNotification
|
||||
{
|
||||
public string $recipientEmailAddress;
|
||||
public ?string $templateId;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class ShipmentOrder
|
||||
{
|
||||
public string $sequenceNumber;
|
||||
public Shipment $Shipment;
|
||||
public ?Serviceconfiguration $PrintOnlyIfCodeable;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class ShipmentService
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Shipper
|
||||
{
|
||||
public Name $Name;
|
||||
public NativeAddressNew $Address;
|
||||
public ?Communication $Communication;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->Name = new Name();
|
||||
$this->Address = new NativeAddressNew();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Status
|
||||
{
|
||||
public string $statuscode;
|
||||
public string $statusDescription;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class StatusElement
|
||||
{
|
||||
public string $statusElement;
|
||||
public string $statusMessage;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Statusinformation
|
||||
{
|
||||
public int $statusCode;
|
||||
public string $statusText;
|
||||
public array|string $statusMessage;
|
||||
public string $statusType;
|
||||
public StatusElement $errorMessage;
|
||||
public StatusElement $warningMessage;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl\Data;
|
||||
|
||||
class Version
|
||||
{
|
||||
public string $majorRelease;
|
||||
public string $minorRelease;
|
||||
public ?string $build;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\Dhl;
|
||||
|
||||
use SoapClient;
|
||||
use SoapHeader;
|
||||
use Xentral\Carrier\Dhl\Data\CreateShipmentOrderRequest;
|
||||
use Xentral\Carrier\Dhl\Data\CreateShipmentOrderResponse;
|
||||
use Xentral\Carrier\Dhl\Data\CreationState;
|
||||
use Xentral\Carrier\Dhl\Data\LabelData;
|
||||
use Xentral\Carrier\Dhl\Data\Shipment;
|
||||
use Xentral\Carrier\Dhl\Data\ShipmentOrder;
|
||||
use Xentral\Carrier\Dhl\Data\Statusinformation;
|
||||
use Xentral\Carrier\Dhl\Data\Version;
|
||||
|
||||
class DhlApi
|
||||
{
|
||||
private SoapClient $soapClient;
|
||||
|
||||
private const SANDBOX_URL = 'https://cig.dhl.de/services/sandbox/soap';
|
||||
private const PRODUCTION_URL = 'https://cig.dhl.de/services/production/soap';
|
||||
private const NAMESPACE_CIS = 'http://dhl.de/webservice/cisbase';
|
||||
|
||||
public function __construct(string $user, string $signature)
|
||||
{
|
||||
$this->soapClient = new SoapClient(__DIR__ . '/Wsdl/geschaeftskundenversand-api-3.4.0.wsdl', [
|
||||
'login' => 'ewsp',
|
||||
'password' => 'rZ*twrzJ5@wr&$',
|
||||
'location' => self::SANDBOX_URL,
|
||||
'trace' => 1,
|
||||
'connection_timeout' => 30,
|
||||
'classmap' => [
|
||||
'CreateShipmentOrderResponse' => CreateShipmentOrderResponse::class,
|
||||
'CreationState' => CreationState::class,
|
||||
'LabelData' => LabelData::class,
|
||||
'Statusinformation' => Statusinformation::class,
|
||||
'Version' => Version::class,
|
||||
]
|
||||
]);
|
||||
|
||||
$authHeader = new SoapHeader(self::NAMESPACE_CIS, 'Authentification', [
|
||||
'user' => $user,
|
||||
'signature' => $signature
|
||||
]);
|
||||
$this->soapClient->__setSoapHeaders($authHeader);
|
||||
}
|
||||
|
||||
public function CreateShipment(Shipment $shipment): CreateShipmentOrderResponse|string
|
||||
{
|
||||
$request = new CreateShipmentOrderRequest();
|
||||
$request->Version = $this->getVersion();
|
||||
$request->ShipmentOrder = new ShipmentOrder();
|
||||
$request->ShipmentOrder->Shipment = $shipment;
|
||||
$request->ShipmentOrder->sequenceNumber = '1';
|
||||
$request->labelResponseType = "B64";
|
||||
try {
|
||||
$response = $this->soapClient->createShipmentOrder($request);
|
||||
return $response;
|
||||
} catch (\SoapFault $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private function getVersion() {
|
||||
$version = new Version();
|
||||
$version->majorRelease = '3';
|
||||
$version->minorRelease = '4';
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\ShippingMethod\Model;
|
||||
|
||||
class CreateShipmentResult
|
||||
{
|
||||
public bool $Success = false;
|
||||
public array $Errors = [];
|
||||
public ?string $Label;
|
||||
public ?string $ExportDocuments;
|
||||
public ?string $TrackingNumber;
|
||||
public ?string $TrackingUrl;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\ShippingMethod\Model;
|
||||
|
||||
class CustomsInfo
|
||||
{
|
||||
const CUSTOMS_TYPE_GIFT = 0;
|
||||
const CUSTOMS_TYPE_DOCUMENTS = 1;
|
||||
const CUSTOMS_TYPE_GOODS = 2;
|
||||
const CUSTOMS_TYPE_SAMPLE = 3;
|
||||
const CUSTOMS_TYPE_RETURN = 4;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\ShippingMethod\Model;
|
||||
|
||||
class Product
|
||||
{
|
||||
const SERVICE_COD = 'cod';
|
||||
const SERVICE_PREMIUM = 'premium';
|
||||
|
||||
public string $Id;
|
||||
public string $Name;
|
||||
public float $LengthMin = 0;
|
||||
public float $LengthMax = 500;
|
||||
public float $WidthMin = 0;
|
||||
public float $WidthMax = 500;
|
||||
public float $HeightMin = 0;
|
||||
public float $HeightMax = 500;
|
||||
public float $WeightMin = 0;
|
||||
public float $WeightMax = 100;
|
||||
public array $AvailableServices = [];
|
||||
|
||||
public static function Create(string $id, string $name):Product {
|
||||
$obj = new Product();
|
||||
$obj->Id = $id;
|
||||
$obj->Name = $name;
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function WithLength(float $min, float $max): Product {
|
||||
$this->LengthMin = $min;
|
||||
$this->LengthMax = $max;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function WithWidth(float $min, float $max): Product {
|
||||
$this->WidthMin = $min;
|
||||
$this->WidthMax = $max;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function WithHeight(float $min, float $max): Product {
|
||||
$this->HeightMin = $min;
|
||||
$this->HeightMax = $max;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function WithWeight(float $min, float $max): Product {
|
||||
$this->WeightMin = $min;
|
||||
$this->WeightMax = $max;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function WithServices(array $services): Product {
|
||||
$this->AvailableServices = $services;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user