示例#1
0
 /**
  * Test validation in the setters
  */
 public function testFaultyProperties()
 {
     $address = new Address();
     try {
         $address->setBox(str_repeat('a', 9));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 8.', $e->getMessage());
     }
     try {
         $address->setCountryCode(str_repeat('a', 3));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 2.', $e->getMessage());
     }
     try {
         $address->setLocality(str_repeat('a', 41));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 40.', $e->getMessage());
     }
     try {
         $address->setNumber(str_repeat('a', 9));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 8.', $e->getMessage());
     }
     try {
         $address->setPostalCode(str_repeat('a', 41));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 40.', $e->getMessage());
     }
     try {
         $address->setStreetName(str_repeat('a', 41));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 40.', $e->getMessage());
     }
 }
示例#2
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return Address
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $address = new Address();
     if (isset($xml->streetName) && $xml->streetName != '') {
         $address->setStreetName((string) $xml->streetName);
     }
     if (isset($xml->number) && $xml->number != '') {
         $address->setNumber((string) $xml->number);
     }
     if (isset($xml->box) && $xml->box != '') {
         $address->setBox((string) $xml->box);
     }
     if (isset($xml->postalCode) && $xml->postalCode != '') {
         $address->setPostalCode((string) $xml->postalCode);
     }
     if (isset($xml->locality) && $xml->locality != '') {
         $address->setLocality((string) $xml->locality);
     }
     if (isset($xml->countryCode) && $xml->countryCode != '') {
         $address->setCountryCode((string) $xml->countryCode);
     }
     return $address;
 }
示例#3
0
文件: index.php 项目: BenCavens/bpost
$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', '*****@*****.**');
//$option = new Messaging('infoNextDay', 'NL', '*****@*****.**');
//$option = new Messaging('infoReminder', 'NL', '*****@*****.**');
//$option = new Messaging('keepMeInformed', 'NL', '*****@*****.**');
//$option = new CashOnDelivery(
//    1251,
//    'BE19210023508812',
//    'GEBABEBB'
示例#4
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;
 }