Beispiel #1
0
 /**
  * Tests Box->toXML
  */
 public function testInternationalToXML()
 {
     $data = array('sender' => 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'), 'internationalBox' => array('international' => array('product' => 'bpack World Express Pro', 'receiver' => array('name' => 'Tijs Verkoyen', 'company' => 'Sumo Coders', 'address' => array('streetName' => 'Kerkstraat', 'number' => '108', 'postalCode' => '9050', 'locality' => 'Gentbrugge', 'countryCode' => 'BE'), 'emailAddress' => '*****@*****.**', 'phoneNumber' => '+32 9 395 02 51'))), 'remark' => 'remark');
     $expectedDocument = self::createDomDocument();
     $box = $expectedDocument->createElement('box');
     $expectedDocument->appendChild($box);
     $sender = $expectedDocument->createElement('sender');
     foreach ($data['sender'] 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));
             }
             $sender->appendChild($address);
         } else {
             $sender->appendChild($expectedDocument->createElement($key, $value));
         }
     }
     $nationalBox = $expectedDocument->createElement('internationalBox');
     $atHome = $expectedDocument->createElement('international:international');
     $nationalBox->appendChild($atHome);
     $atHome->appendChild($expectedDocument->createElement('international:product', $data['internationalBox']['international']['product']));
     $receiver = $expectedDocument->createElement('international:receiver');
     $atHome->appendChild($receiver);
     foreach ($data['internationalBox']['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));
         }
     }
     $box->appendChild($sender);
     $box->appendChild($nationalBox);
     $box->appendChild($expectedDocument->createElement('remark', $data['remark']));
     $actualDocument = self::createDomDocument();
     $address = new Address($data['sender']['address']['streetName'], $data['sender']['address']['number'], $data['sender']['address']['box'], $data['sender']['address']['postalCode'], $data['sender']['address']['locality'], $data['sender']['address']['countryCode']);
     $sender = new Sender();
     $sender->setName($data['sender']['name']);
     $sender->setCompany($data['sender']['company']);
     $sender->setAddress($address);
     $sender->setEmailAddress($data['sender']['emailAddress']);
     $sender->setPhoneNumber($data['sender']['phoneNumber']);
     $address = new Address($data['internationalBox']['international']['receiver']['address']['streetName'], $data['internationalBox']['international']['receiver']['address']['number'], null, $data['internationalBox']['international']['receiver']['address']['postalCode'], $data['internationalBox']['international']['receiver']['address']['locality'], $data['internationalBox']['international']['receiver']['address']['countryCode']);
     $receiver = new Receiver();
     $receiver->setAddress($address);
     $receiver->setName($data['internationalBox']['international']['receiver']['name']);
     $receiver->setCompany($data['internationalBox']['international']['receiver']['company']);
     $receiver->setPhoneNumber($data['internationalBox']['international']['receiver']['phoneNumber']);
     $receiver->setEmailAddress($data['internationalBox']['international']['receiver']['emailAddress']);
     $international = new International();
     $international->setProduct($data['internationalBox']['international']['product']);
     $international->setReceiver($receiver);
     $box = new Box();
     $box->setSender($sender);
     $box->setInternationalBox($international);
     $box->setRemark($data['remark']);
     $actualDocument->appendChild($box->toXML($actualDocument, null));
     $this->assertEquals($expectedDocument, $actualDocument);
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * Test validation in the setters
  */
 public function testFaultyProperties()
 {
     $international = new International();
     try {
         $international->setProduct(str_repeat('a', 10));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals(sprintf('Invalid value, possible values are: %1$s.', implode(', ', International::getPossibleProductValues())), $e->getMessage());
     }
 }
Beispiel #4
0
$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');
    //    $response = $bpost->fetchOrder($orderId);
    //    $response = $bpost->createLabelForOrder('1398779096', 'A4');
    //    $response = $bpost->createLabelForBox('323212345659900357664050', 'A4');
    //    $response = $bpost->createLabelInBulkForOrders(
    //        array('1398779096', '1398862819'), 'A4'