Example #1
0
 /**
  * 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);
 }
Example #2
0
 /**
  * Test validation in the setters
  */
 public function testFaultyProperties()
 {
     $customsInfo = new CustomsInfo();
     try {
         $customsInfo->setContentDescription(str_repeat('a', 51));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 50.', $e->getMessage());
     }
     try {
         $customsInfo->setParcelReturnInstructions(str_repeat('a', 10));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals(sprintf('Invalid value, possible values are: %1$s.', implode(', ', CustomsInfo::getPossibleParcelReturnInstructionValues())), $e->getMessage());
     }
     try {
         $customsInfo->setShipmentType(str_repeat('a', 10));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals(sprintf('Invalid value, possible values are: %1$s.', implode(', ', CustomsInfo::getPossibleShipmentTypeValues())), $e->getMessage());
     }
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return International
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $international = new International();
     if (isset($xml->international->product) && $xml->international->product != '') {
         $international->setProduct((string) $xml->international->product);
     }
     if (isset($xml->international->options)) {
         foreach ($xml->international->options as $optionData) {
             $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common');
             if (in_array($optionData->getName(), array('infoDistributed'))) {
                 $option = Messaging::createFromXML($optionData);
             } else {
                 $className = '\\TijsVerkoyen\\Bpost\\Bpost\\Order\\Box\\Option\\' . ucfirst($optionData->getName());
                 if (!method_exists($className, 'createFromXML')) {
                     throw new Exception('Not Implemented');
                 }
                 $option = call_user_func(array($className, 'createFromXML'), $optionData);
             }
             $international->addOption($option);
         }
     }
     if (isset($xml->international->parcelWeight) && $xml->international->parcelWeight != '') {
         $international->setParcelWeight((int) $xml->international->parcelWeight);
     }
     if (isset($xml->international->receiver)) {
         $receiverData = $xml->international->receiver->children('http://schema.post.be/shm/deepintegration/v3/common');
         $international->setReceiver(Receiver::createFromXML($receiverData));
     }
     if (isset($xml->international->customsInfo)) {
         $international->setCustomsInfo(CustomsInfo::createFromXML($xml->international->customsInfo));
     }
     return $international;
 }
Example #5
0
$atBpost->setReceiverName('Tijs Verkoyen');
$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);