/** * Retrieve member information * * @param string $id * @param boolean $as_xml [optional] * @return Customer / mixed */ public function getMember($id, $as_xml = false) { $xml = $this->doCall('/customer/' . $id); if ($as_xml) { return $xml; } return Customer::createFromXML($xml); }
/** * Tests Customer->toXML */ public function testCreateFromXML() { $data = array('UserID' => '5f1f1b07-a8c4-4d4c-bd5b-cdace6cb7c84', 'FirstName' => 'Bruno', 'LastName' => 'Vandenabeele', 'Street' => 'Oplintersesteenweg', 'Number' => '629', 'CompanyName' => 'Bpost', 'Country' => 'BE', 'DateOfBirth' => '1974-07-02', 'DeliveryCode' => '344337728', 'Email' => '*****@*****.**', 'MobilePrefix' => '0032', 'MobileNumber' => '475813445', 'Postalcode' => '3300', 'PreferredLanguage' => 'nl-BE', 'ReceivePromotions' => true, 'actived' => true, 'Title' => 'Mr', 'Town' => 'Tienen', 'PackStations' => array(array('OrderNumber' => 1, 'PackStationId' => 14472))); $document = self::createDomDocument(); $customerElement = $document->createElement('Customer'); foreach ($data as $key => $value) { if ($key == 'PackStations') { continue; } $customerElement->appendChild($document->createElement($key, $value)); } $customerPackStation = $document->createElement('CustomerPackStation'); $customerPackStation->appendChild($document->createElement('OrderNumber', 1)); $customerPackStation->appendChild($document->createElement('PackstationID', 14472)); $packStations = $document->createElement('PackStations'); $packStations->appendChild($customerPackStation); $customerElement->appendChild($packStations); $document->appendChild($customerElement); $customer = Customer::createFromXML(simplexml_load_string($document->saveXML())); $this->assertEquals($data['UserID'], $customer->getUserID()); $this->assertEquals($data['FirstName'], $customer->getFirstName()); $this->assertEquals($data['LastName'], $customer->getLastName()); $this->assertEquals($data['Street'], $customer->getStreet()); $this->assertEquals($data['Number'], $customer->getNumber()); $this->assertEquals($data['CompanyName'], $customer->getCompanyName()); $this->assertEquals(new \DateTime($data['DateOfBirth']), $customer->getDateOfBirth()); $this->assertEquals($data['DeliveryCode'], $customer->getDeliveryCode()); $this->assertEquals($data['Email'], $customer->getEmail()); $this->assertEquals($data['MobilePrefix'], $customer->getMobilePrefix()); $this->assertEquals($data['MobileNumber'], $customer->getMobileNumber()); $this->assertEquals($data['Postalcode'], $customer->getPostalCode()); $this->assertEquals($data['PreferredLanguage'], $customer->getPreferredLanguage()); $this->assertEquals($data['ReceivePromotions'], $customer->getReceivePromotions()); $this->assertEquals($data['actived'], $customer->getActivated()); $this->assertEquals($data['Title'] . '.', $customer->getTitle()); $this->assertEquals($data['Town'], $customer->getTown()); $packStations = $customer->getPackStations(); $this->assertEquals($data['PackStations'][0]['OrderNumber'], $packStations[0]->getOrderNumber()); $this->assertEquals($data['PackStations'][0]['PackStationId'], $packStations[0]->getPackStationId()); try { $xml = simplexml_load_string('<Customer> </Customer>'); $customer = Customer::createFromXML($xml); } catch (\Exception $e) { $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e); $this->assertEquals('No UserId found.', $e->getMessage()); } }
/** * Retrieve member information * * @param string $id * @return Customer */ public function getMember($id) { $xml = $this->doCall('/customer/' . $id); return Customer::createFromXML($xml); }