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 = "{$this->productTypeDescription}";
}
$contentsRoot = new \SimpleXMLElement('');
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 = <<
{$username}
{$password}
3
0
1
?
{$this->product}
{$accountNumber}
{$this->shipmentDate}
{$this->weight}
{$this->length}
{$this->width}
{$this->height}
{$senderName}
{$senderStreetName}
{$senderStreetNo}
{$senderZip}
{$senderCity}
{$senderCountry}
{$senderEmail}
{$this->name1}
{$this->name2}
{$this->name3}
{$this->street}
{$this->streetNo}
{$this->zip}
{$this->city}
{$this->country}
{$this->email}
{$this->productType}
{$productTypeDescriptionXml}
{$senderCity}
0
{$contentsXml}
B64
XML;
return $payload;
}
}