/** * @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; }
$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' // ); // GEO6 webservices // $geo6 = new Geo6(GEO6_PARTNER, GEO6_APP_ID); // $response = $geo6->getNearestServicePoint('Afrikalaan', '289', '9000', 'nl', 7, 100); // $response = $geo6->getServicePointDetails('220000', 'nl', '1'); // $response = $geo6->getServicePointPage('220000', 'nl', '1');
/** * 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()); } }
/** * @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; }