/** * Tests Day->toXML */ public function testToXML() { $data = array('parcelValue' => '700', 'contentDescription' => 'BOOK', 'shipmentType' => 'DOCUMENTS', 'parcelReturnInstructions' => 'RTS', 'privateAddress' => false); $expectedDocument = self::createDomDocument(); $customsInfo = $expectedDocument->createElement('customsInfo'); foreach ($data as $key => $value) { if ($key == 'privateAddress') { $value = $value ? 'true' : 'false'; } $customsInfo->appendChild($expectedDocument->createElement($key, $value)); } $expectedDocument->appendChild($customsInfo); $actualDocument = self::createDomDocument(); $customsInfo = new CustomsInfo(); $customsInfo->setParcelValue($data['parcelValue']); $customsInfo->setContentDescription($data['contentDescription']); $customsInfo->setShipmentType($data['shipmentType']); $customsInfo->setParcelReturnInstructions($data['parcelReturnInstructions']); $customsInfo->setPrivateAddress($data['privateAddress']); $actualDocument->appendChild($customsInfo->toXML($actualDocument, null)); $this->assertEquals($expectedDocument, $actualDocument); $data = array('parcelValue' => '700', 'contentDescription' => 'BOOK', 'shipmentType' => 'DOCUMENTS', 'parcelReturnInstructions' => 'RTS', 'privateAddress' => true); $expectedDocument = self::createDomDocument(); $customsInfo = $expectedDocument->createElement('customsInfo'); foreach ($data as $key => $value) { if ($key == 'privateAddress') { $value = $value ? 'true' : 'false'; } $customsInfo->appendChild($expectedDocument->createElement($key, $value)); } $expectedDocument->appendChild($customsInfo); $actualDocument = self::createDomDocument(); $customsInfo = new CustomsInfo(); $customsInfo->setParcelValue($data['parcelValue']); $customsInfo->setContentDescription($data['contentDescription']); $customsInfo->setShipmentType($data['shipmentType']); $customsInfo->setParcelReturnInstructions($data['parcelReturnInstructions']); $customsInfo->setPrivateAddress($data['privateAddress']); $actualDocument->appendChild($customsInfo->toXML($actualDocument)); $this->assertEquals($expectedDocument, $actualDocument); }
/** * Tests International->toXML */ public function testToXML() { $data = array('international' => array('product' => 'bpack World Express Pro', 'options' => array(array('common:infoNextDay' => array('@attributes' => array('language' => 'NL'), 'common:emailAddress' => '*****@*****.**'))), 'receiver' => array('name' => 'Tijs Verkoyen', 'company' => 'Sumo Coders', 'address' => array('streetName' => 'Afrikalaan', 'number' => '289', 'box' => '3', 'postalCode' => '9000', 'locality' => 'Gent', 'countryCode' => 'BE'), 'emailAddress' => '*****@*****.**', 'phoneNumber' => '+32 9 395 02 51'), 'parcelWeight' => 2000, 'customsInfo' => array('parcelValue' => 700, 'contentDescription' => 'BOOK', 'shipmentType' => 'DOCUMENTS', 'parcelReturnInstructions' => 'RTS', 'privateAddress' => false))); $expectedDocument = self::createDomDocument(); $nationalBox = $expectedDocument->createElement('internationalBox'); $expectedDocument->appendChild($nationalBox); $international = $expectedDocument->createElement('international:international'); $nationalBox->appendChild($international); $international->appendChild($expectedDocument->createElement('international:product', $data['international']['product'])); $options = $expectedDocument->createElement('international:options'); foreach ($data['international']['options'] as $value) { foreach ($value as $key2 => $value2) { $element = $expectedDocument->createElement($key2); foreach ($value2 as $key3 => $value3) { if ($key3 == '@attributes') { foreach ($value3 as $key4 => $value4) { $element->setAttribute($key4, $value4); } } else { $element->appendChild($expectedDocument->createElement($key3, $value3)); } } $options->appendChild($element); } } $international->appendChild($options); $receiver = $expectedDocument->createElement('international:receiver'); $international->appendChild($receiver); foreach ($data['international']['receiver'] as $key => $value) { $key = 'common:' . $key; if ($key == 'common:address') { $address = $expectedDocument->createElement($key); foreach ($value as $key2 => $value2) { $key2 = 'common:' . $key2; $address->appendChild($expectedDocument->createElement($key2, $value2)); } $receiver->appendChild($address); } else { $receiver->appendChild($expectedDocument->createElement($key, $value)); } } $international->appendChild($expectedDocument->createElement('international:parcelWeight', $data['international']['parcelWeight'])); $customsInfo = $expectedDocument->createElement('international:customsInfo'); foreach ($data['international']['customsInfo'] as $key => $value) { if ($key == 'privateAddress') { $value = $value ? 'true' : 'false'; } $customsInfo->appendChild($expectedDocument->createElement('international:' . $key, $value)); } $international->appendChild($customsInfo); $actualDocument = self::createDomDocument(); $address = new Address($data['international']['receiver']['address']['streetName'], $data['international']['receiver']['address']['number'], $data['international']['receiver']['address']['box'], $data['international']['receiver']['address']['postalCode'], $data['international']['receiver']['address']['locality'], $data['international']['receiver']['address']['countryCode']); $receiver = new Receiver(); $receiver->setName($data['international']['receiver']['name']); $receiver->setCompany($data['international']['receiver']['company']); $receiver->setAddress($address); $receiver->setEmailAddress($data['international']['receiver']['emailAddress']); $receiver->setPhoneNumber($data['international']['receiver']['phoneNumber']); $customsInfo = new CustomsInfo(); $customsInfo->setParcelValue($data['international']['customsInfo']['parcelValue']); $customsInfo->setContentDescription($data['international']['customsInfo']['contentDescription']); $customsInfo->setShipmentType($data['international']['customsInfo']['shipmentType']); $customsInfo->setParcelReturnInstructions($data['international']['customsInfo']['parcelReturnInstructions']); $customsInfo->setPrivateAddress($data['international']['customsInfo']['privateAddress']); $messaging = new Messaging('infoNextDay', $data['international']['options'][0]['common:infoNextDay']['@attributes']['language'], $data['international']['options'][0]['common:infoNextDay']['common:emailAddress']); $international = new International(); $international->setProduct($data['international']['product']); $international->setReceiver($receiver); $international->setParcelWeight($data['international']['parcelWeight']); $international->setCustomsInfo($customsInfo); $international->addOption($messaging); // I know, the line below is kinda bogus, but it will make sure all code is tested $international->setOptions(array($messaging)); $actualDocument->appendChild($international->toXML($actualDocument)); $this->assertEquals($expectedDocument, $actualDocument); }
/** * @param \SimpleXMLElement $xml * @return CustomsInfo */ public static function createFromXML(\SimpleXMLElement $xml) { $customsInfo = new CustomsInfo(); if (isset($xml->parcelValue) && $xml->parcelValue != '') { $customsInfo->setParcelValue((int) $xml->parcelValue); } if (isset($xml->contentDescription) && $xml->contentDescription != '') { $customsInfo->setContentDescription((string) $xml->contentDescription); } if (isset($xml->shipmentType) && $xml->shipmentType != '') { $customsInfo->setShipmentType((string) $xml->shipmentType); } if (isset($xml->parcelReturnInstructions) && $xml->parcelReturnInstructions != '') { $customsInfo->setParcelReturnInstructions((string) $xml->parcelReturnInstructions); } if (isset($xml->privateAddress) && $xml->privateAddress != '') { $customsInfo->setPrivateAddress((string) $xml->privateAddress == 'true'); } return $customsInfo; }
$atBpost->setReceiverCompany('Sumo Coders'); //$box->setNationalBox($atBpost); // @24/7 $parcelsDepotAddress = new ParcelsDepotAddress('Turnhoutsebaan', '468', null, '2110', 'Wijnegem', 'BE'); $parcelsDepotAddress->setBox('A'); $at247 = new At247(); $at247->setParcelsDepotId('014472'); $at247->setParcelsDepotName('WIJNEGEM'); $at247->setParcelsDepotAddress($parcelsDepotAddress); $at247->setMemberId('188565346'); $at247->setReceiverName('Tijs Verkoyen'); $at247->setReceiverCompany('Sumo Coders'); //$box->setNationalBox($at247); // international $customsInfo = new CustomsInfo(); $customsInfo->setParcelValue(700); $customsInfo->setContentDescription('BOOK'); $customsInfo->setShipmentType('DOCUMENTS'); $customsInfo->setParcelReturnInstructions('RTS'); $customsInfo->setPrivateAddress(false); $international = new International(); $international->setProduct('bpack World Express Pro'); $international->setReceiver($receiver); $international->setParcelWeight(2000); $international->setCustomsInfo($customsInfo); //$box->setInternationalBox($international); $order->addBox($box); try { // Bpost webservices // $response = $bpost->createOrReplaceOrder($order); // $response = $bpost->modifyOrderStatus($orderId, 'OPEN');