コード例 #1
0
ファイル: BoxTest.php プロジェクト: BenCavens/bpost
 /**
  * Tests Box->toXML
  */
 public function testNationalToXML()
 {
     $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'), 'nationalBox' => array('atHome' => array('product' => 'bpack 24h Pro', 'weight' => 2000, '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('nationalBox');
     $atHome = $expectedDocument->createElement('atHome');
     $nationalBox->appendChild($atHome);
     $atHome->appendChild($expectedDocument->createElement('product', $data['nationalBox']['atHome']['product']));
     $atHome->appendChild($expectedDocument->createElement('weight', $data['nationalBox']['atHome']['weight']));
     $receiver = $expectedDocument->createElement('receiver');
     $atHome->appendChild($receiver);
     foreach ($data['nationalBox']['atHome']['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['nationalBox']['atHome']['receiver']['address']['streetName'], $data['nationalBox']['atHome']['receiver']['address']['number'], null, $data['nationalBox']['atHome']['receiver']['address']['postalCode'], $data['nationalBox']['atHome']['receiver']['address']['locality'], $data['nationalBox']['atHome']['receiver']['address']['countryCode']);
     $receiver = new Receiver();
     $receiver->setAddress($address);
     $receiver->setName($data['nationalBox']['atHome']['receiver']['name']);
     $receiver->setCompany($data['nationalBox']['atHome']['receiver']['company']);
     $receiver->setPhoneNumber($data['nationalBox']['atHome']['receiver']['phoneNumber']);
     $receiver->setEmailAddress($data['nationalBox']['atHome']['receiver']['emailAddress']);
     $atHome = new AtHome();
     $atHome->setProduct($data['nationalBox']['atHome']['product']);
     $atHome->setWeight($data['nationalBox']['atHome']['weight']);
     $atHome->setReceiver($receiver);
     $box = new Box();
     $box->setSender($sender);
     $box->setNationalBox($atHome);
     $box->setRemark($data['remark']);
     $actualDocument->appendChild($box->toXML($actualDocument, null));
     $this->assertEquals($expectedDocument, $actualDocument);
 }
コード例 #2
0
ファイル: AtHomeTest.php プロジェクト: BenCavens/bpost
 /**
  * Test validation in the setters
  */
 public function testFaultyProperties()
 {
     $atHome = new AtHome();
     try {
         $atHome->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(', ', AtHome::getPossibleProductValues())), $e->getMessage());
     }
 }
コード例 #3
0
ファイル: index.php プロジェクト: BenCavens/bpost
$receiver->setEmailAddress('*****@*****.**');
// options
$option = new Messaging('infoDistributed', 'NL', '*****@*****.**');
//$option = new Messaging('infoNextDay', 'NL', '*****@*****.**');
//$option = new Messaging('infoReminder', 'NL', '*****@*****.**');
//$option = new Messaging('keepMeInformed', 'NL', '*****@*****.**');
//$option = new CashOnDelivery(
//    1251,
//    'BE19210023508812',
//    'GEBABEBB'
//);
//$option = new Signature();
//$option = new Insurance('additionalInsurance', 3);
//$option = new AutomaticSecondPresentation();
// @Home
$atHome = new AtHome();
$atHome->setProduct('bpack 24h Pro');
$atHome->setWeight(2000);
$atHome->setReceiver($receiver);
$atHome->addOption($option);
$box->setNationalBox($atHome);
// @Bpost
$pugoAddress = new PugoAddress('Turnhoutsebaan', '468', null, '2110', 'Wijnegem', 'BE');
$atBpost = new AtBpost();
$atBpost->setWeight(2000);
$atBpost->setPugoId('207500');
$atBpost->setPugoName('WIJNEGEM');
$atBpost->setPugoAddress($pugoAddress);
$atBpost->setReceiverName('Tijs Verkoyen');
$atBpost->setReceiverCompany('Sumo Coders');
//$box->setNationalBox($atBpost);
コード例 #4
0
ファイル: AtHome.php プロジェクト: tijsverkoyen/bpost
 /**
  * @param  \SimpleXMLElement $xml
  * @return AtHome
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $atHome = new AtHome();
     if (isset($xml->atHome->product) && $xml->atHome->product != '') {
         $atHome->setProduct((string) $xml->atHome->product);
     }
     if (isset($xml->atHome->options) and !empty($xml->atHome->options)) {
         foreach ($xml->atHome->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);
             }
             $atHome->addOption($option);
         }
     }
     if (isset($xml->atHome->weight) && $xml->atHome->weight != '') {
         $atHome->setWeight((int) $xml->atHome->weight);
     }
     if (isset($xml->atHome->openingHours) && $xml->atHome->openingHours != '') {
         throw new Exception('Not Implemented');
         $atHome->setProduct((string) $xml->atHome->openingHours);
     }
     if (isset($xml->atHome->desiredDeliveryPlace) && $xml->atHome->desiredDeliveryPlace != '') {
         $atHome->setDesiredDeliveryPlace((string) $xml->atHome->desiredDeliveryPlace);
     }
     if (isset($xml->atHome->receiver)) {
         $atHome->setReceiver(Receiver::createFromXML($xml->atHome->receiver->children('http://schema.post.be/shm/deepintegration/v3/common')));
     }
     return $atHome;
 }
コード例 #5
0
ファイル: BpostTest.php プロジェクト: BenCavens/bpost
 /**
  * @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;
 }