Example #1
0
 /**
  * @return Order
  */
 protected function createAtHomeOrderObject()
 {
     // create order
     $orderId = time();
     $order = new Order($orderId);
     $order->setCostCenter('Cost Center');
     // add lines
     $line1 = new OrderLine('Beer', 1);
     $order->addLine($line1);
     $line2 = new OrderLine('Whisky', 100);
     $order->addLine($line2);
     // add box
     $address = new Address();
     $address->setStreetName('Afrikalaan');
     $address->setNumber('289');
     $address->setPostalCode('9000');
     $address->setLocality('Gent');
     $address->setCountryCode('BE');
     $sender = new Sender();
     $sender->setAddress($address);
     $sender->setName('Tijs Verkoyen');
     $sender->setCompany('Sumo Coders');
     $sender->setPhoneNumber('+32 9 395 02 51');
     $sender->setEmailAddress('*****@*****.**');
     $box = new Box();
     $box->setSender($sender);
     $box->setRemark('Remark');
     // add label
     $address = new Address();
     $address->setStreetName('Kerkstraat');
     $address->setNumber('108');
     $address->setPostalCode('9050');
     $address->setLocality('Gentbrugge');
     $address->setCountryCode('BE');
     $receiver = new Receiver();
     $receiver->setAddress($address);
     $receiver->setName('Tijs Verkoyen');
     $receiver->setCompany('Sumo Coders');
     $receiver->setPhoneNumber('+32 9 395 02 51');
     $receiver->setEmailAddress('*****@*****.**');
     // options
     $option = new Messaging('infoDistributed', 'NL', '*****@*****.**');
     // @Home
     $atHome = new AtHome();
     $atHome->setProduct('bpack 24h Pro');
     $atHome->setWeight(2000);
     $atHome->setReceiver($receiver);
     $atHome->addOption($option);
     $box->setNationalBox($atHome);
     $order->addBox($box);
     return $order;
 }
Example #2
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return Order
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     // @todo work with classmaps ...
     if (!isset($xml->reference)) {
         throw new Exception('No reference found.');
     }
     $order = new Order((string) $xml->reference);
     if (isset($xml->costCenter) && $xml->costCenter != '') {
         $order->setCostCenter((string) $xml->costCenter);
     }
     if (isset($xml->orderLine)) {
         foreach ($xml->orderLine as $orderLine) {
             $order->addLine(Line::createFromXML($orderLine));
         }
     }
     if (isset($xml->box)) {
         foreach ($xml->box as $box) {
             $order->addBox(Box::createFromXML($box));
         }
     }
     return $order;
 }
Example #3
0
 /**
  * Test validation in the setters
  */
 public function testFaultyProperties()
 {
     $box = new Box();
     try {
         $box->setStatus(str_repeat('a', 10));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid value, possible values are: ' . implode(', ', Box::getPossibleStatusValues()) . '.', $e->getMessage());
     }
 }
Example #4
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return Box
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $box = new Box();
     if (isset($xml->sender)) {
         $box->setSender(Sender::createFromXML($xml->sender->children('http://schema.post.be/shm/deepintegration/v3/common')));
     }
     if (isset($xml->nationalBox)) {
         $nationalBoxData = $xml->nationalBox->children('http://schema.post.be/shm/deepintegration/v3/national');
         // build classname based on the tag name
         $className = '\\TijsVerkoyen\\Bpost\\Bpost\\Order\\Box\\' . ucfirst($nationalBoxData->getName());
         if ($nationalBoxData->getName() == 'at24-7') {
             $className = '\\TijsVerkoyen\\Bpost\\Bpost\\Order\\Box\\At247';
         }
         if (!method_exists($className, 'createFromXML')) {
             throw new Exception('Not Implemented');
         }
         $nationalBox = call_user_func(array($className, 'createFromXML'), $nationalBoxData);
         $box->setNationalBox($nationalBox);
     }
     if (isset($xml->internationalBox)) {
         $internationalBoxData = $xml->internationalBox->children('http://schema.post.be/shm/deepintegration/v3/international');
         // build classname based on the tag name
         $className = '\\TijsVerkoyen\\Bpost\\Bpost\\Order\\Box\\' . ucfirst($internationalBoxData->getName());
         if (!method_exists($className, 'createFromXML')) {
             var_dump($className);
             throw new Exception('Not Implemented');
         }
         $internationalBox = call_user_func(array($className, 'createFromXML'), $internationalBoxData);
         $box->setInternationalBox($internationalBox);
     }
     if (isset($xml->remark) && $xml->remark != '') {
         $box->setRemark((string) $xml->remark);
     }
     if (isset($xml->status) && $xml->status != '') {
         $box->setStatus((string) $xml->status);
     }
     return $box;
 }
Example #5
0
 /**
  * Modify the status for an order.
  *
  * @param  string $reference The reference for an order
  * @param  string $status    The new status, allowed values are: OPEN, PENDING, CANCELLED, COMPLETED, ON-HOLD or PRINTED
  * @return bool
  */
 public function modifyOrderStatus($reference, $status)
 {
     $status = strtoupper($status);
     if (!in_array($status, Box::getPossibleStatusValues())) {
         throw new Exception(sprintf('Invalid value, possible values are: %1$s.', implode(', ', Box::getPossibleStatusValues())));
     }
     $url = '/orders/' . $reference;
     $document = new \DOMDocument('1.0', 'utf-8');
     $document->preserveWhiteSpace = false;
     $document->formatOutput = true;
     $orderUpdate = $document->createElement('orderUpdate');
     $orderUpdate->setAttribute('xmlns', 'http://schema.post.be/shm/deepintegration/v3/');
     $orderUpdate->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $orderUpdate->appendChild($document->createElement('status', $status));
     $document->appendChild($orderUpdate);
     $headers = array('Content-type: application/vnd.bpost.shm-orderUpdate-v3+XML');
     return $this->doCall($url, $document->saveXML(), $headers, 'POST', false) == '';
 }
Example #6
0
 /**
  * Tests Order->toXML
  */
 public function testToXML()
 {
     $data = array('accountId' => ACCOUNT_ID, 'reference' => 'reference ' . time(), 'costCenter' => 'costcenter ' . time(), 'orderLine' => array(array('text' => 'Beer ' . time(), 'nbOfItems' => rand(1, 10)), array('text' => 'Whisky ' . time(), 'nbOfItems' => rand(1, 10))), 'box' => array(array('sender' => array('name' => 'Tijs Verkoyen', 'company' => 'Sumo Coders', 'address' => array('streetName' => 'Afrikalaan', 'number' => '289', 'postalCode' => '9000', 'locality' => 'Gent', 'countryCode' => 'BE'), 'emailAddress' => '*****@*****.**', 'phoneNumber' => '+32 9 395 02 51'), 'nationalBox' => array('at24-7' => array('product' => 'bpack 24h Pro', 'weight' => 2000, 'parcelsDepotId' => '014472', 'parcelsDepotName' => 'WIJNEGEM', 'parcelsDepotAddress' => array('streetName' => 'Turnhoutsebaan', 'number' => '468', 'box' => 'A', 'postalCode' => '2110', 'locality' => 'Wijnegem', 'countryCode' => 'BE'), 'memberId' => '188565346', 'receiverName' => 'Tijs Verkoyen', 'receiverCompany' => 'Sumo Coders')), 'remark' => 'remark ' . time())));
     $expectedDocument = self::createDomDocument();
     $order = $expectedDocument->createElement('tns:order');
     $order->setAttribute('xmlns:common', 'http://schema.post.be/shm/deepintegration/v3/common');
     $order->setAttribute('xmlns:tns', 'http://schema.post.be/shm/deepintegration/v3/');
     $order->setAttribute('xmlns', 'http://schema.post.be/shm/deepintegration/v3/national');
     $order->setAttribute('xmlns:international', 'http://schema.post.be/shm/deepintegration/v3/international');
     $order->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $order->setAttribute('xsi:schemaLocation', 'http://schema.post.be/shm/deepintegration/v3/');
     $expectedDocument->appendChild($order);
     $order->appendChild($expectedDocument->createElement('tns:accountId', $data['accountId']));
     $order->appendChild($expectedDocument->createElement('tns:reference', $data['reference']));
     $order->appendChild($expectedDocument->createElement('tns:costCenter', $data['costCenter']));
     foreach ($data['orderLine'] as $row) {
         $line = $expectedDocument->createElement('tns:orderLine');
         $line->appendChild($expectedDocument->createElement('tns:text', $row['text']));
         $line->appendChild($expectedDocument->createElement('tns:nbOfItems', $row['nbOfItems']));
         $order->appendChild($line);
     }
     $box = $expectedDocument->createElement('tns:box');
     $order->appendChild($box);
     $sender = $expectedDocument->createElement('tns:sender');
     foreach ($data['box'][0]['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));
         }
     }
     $box->appendChild($sender);
     $nationalBox = $expectedDocument->createElement('tns:nationalBox');
     $at247 = $expectedDocument->createElement('at24-7');
     $nationalBox->appendChild($at247);
     $expectedDocument->appendChild($nationalBox);
     foreach ($data['box'][0]['nationalBox']['at24-7'] as $key => $value) {
         if ($key == 'parcelsDepotAddress') {
             $address = $expectedDocument->createElement($key);
             foreach ($value as $key2 => $value2) {
                 $key2 = 'common:' . $key2;
                 $address->appendChild($expectedDocument->createElement($key2, $value2));
             }
             $at247->appendChild($address);
         } else {
             $at247->appendChild($expectedDocument->createElement($key, $value));
         }
     }
     $box->appendChild($nationalBox);
     $box->appendChild($expectedDocument->createElement('tns:remark', $data['box'][0]['remark']));
     $actualDocument = self::createDomDocument();
     $address = new Address($data['box'][0]['sender']['address']['streetName'], $data['box'][0]['sender']['address']['number'], null, $data['box'][0]['sender']['address']['postalCode'], $data['box'][0]['sender']['address']['locality'], $data['box'][0]['sender']['address']['countryCode']);
     $sender = new Sender();
     $sender->setName($data['box'][0]['sender']['name']);
     $sender->setCompany($data['box'][0]['sender']['company']);
     $sender->setAddress($address);
     $sender->setEmailAddress($data['box'][0]['sender']['emailAddress']);
     $sender->setPhoneNumber($data['box'][0]['sender']['phoneNumber']);
     $parcelsDepotAddress = new ParcelsDepotAddress($data['box'][0]['nationalBox']['at24-7']['parcelsDepotAddress']['streetName'], $data['box'][0]['nationalBox']['at24-7']['parcelsDepotAddress']['number'], $data['box'][0]['nationalBox']['at24-7']['parcelsDepotAddress']['box'], $data['box'][0]['nationalBox']['at24-7']['parcelsDepotAddress']['postalCode'], $data['box'][0]['nationalBox']['at24-7']['parcelsDepotAddress']['locality'], $data['box'][0]['nationalBox']['at24-7']['parcelsDepotAddress']['countryCode']);
     $at247 = new At247();
     $at247->setProduct($data['box'][0]['nationalBox']['at24-7']['product']);
     $at247->setWeight($data['box'][0]['nationalBox']['at24-7']['weight']);
     $at247->setParcelsDepotId($data['box'][0]['nationalBox']['at24-7']['parcelsDepotId']);
     $at247->setParcelsDepotName($data['box'][0]['nationalBox']['at24-7']['parcelsDepotName']);
     $at247->setParcelsDepotAddress($parcelsDepotAddress);
     $at247->setMemberId($data['box'][0]['nationalBox']['at24-7']['memberId']);
     $at247->setReceiverName($data['box'][0]['nationalBox']['at24-7']['receiverName']);
     $at247->setReceiverCompany($data['box'][0]['nationalBox']['at24-7']['receiverCompany']);
     $box = new Box();
     $box->setSender($sender);
     $box->setNationalBox($at247);
     $box->setRemark($data['box'][0]['remark']);
     $order = new Order($data['reference']);
     $order->setCostCenter($data['costCenter']);
     $line1 = new Order\Line($data['orderLine'][0]['text'], $data['orderLine'][0]['nbOfItems']);
     $line2 = new Line($data['orderLine'][1]['text'], $data['orderLine'][1]['nbOfItems']);
     $order->addLine($line1);
     $order->addLine($line2);
     // I know, the line below is kinda bogus, but it will make sure all code is tested
     $order->setLines(array($line1, $line2));
     $order->addBox($box);
     // I know, the line below is kinda bogus, but it will make sure all code is tested
     $order->setBoxes(array($box));
     $actualDocument->appendChild($order->toXML($actualDocument, ACCOUNT_ID));
     $this->assertEquals($expectedDocument, $actualDocument);
     try {
         $xml = simplexml_load_string('<order>
             </order>');
         $order = Order::createFromXML($xml);
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('No reference found.', $e->getMessage());
     }
 }
Example #7
0
$line2 = new OrderLine('Whisky', 100);
$order->addLine($line2);
// add box
$address = new Address();
$address->setStreetName('Afrikalaan');
$address->setNumber('289');
$address->setPostalCode('9000');
$address->setLocality('Gent');
$address->setCountryCode('BE');
$sender = new Sender();
$sender->setAddress($address);
$sender->setName('Tijs Verkoyen');
$sender->setCompany('Sumo Coders');
$sender->setPhoneNumber('+32 9 395 02 51');
$sender->setEmailAddress('*****@*****.**');
$box = new Box();
$box->setSender($sender);
$box->setRemark('Remark');
// add label
$address = new Address();
$address->setStreetName('Kerkstraat');
$address->setNumber('108');
$address->setPostalCode('9050');
$address->setLocality('Gentbrugge');
$address->setCountryCode('BE');
$receiver = new Receiver();
$receiver->setAddress($address);
$receiver->setName('Tijs Verkoyen');
$receiver->setCompany('Sumo Coders');
$receiver->setPhoneNumber('+32 9 395 02 51');
$receiver->setEmailAddress('*****@*****.**');