setAddressType($addressType); \Qs_Options::setOptions($this, $options); } /** * Sets address type. * * @param string $addressType * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setAddressType($addressType) { if (!in_array($addressType, array(self::BILLING, self::SHIPPING))) { throw new \LinkPoint\Exception('Invalid address type: '.$addressType); } $this->_addressType = $addressType; return $this; } /** * Returns address type. * @return string */ public function getAddressType() { return $this->_addressType; } /** * Sets customer name. * * @param string $name * @return \LinkPoint\Address */ public function setName($name) { $this->_name = $name; return $this; } /** * Returns customer name. * @return string */ public function getName() { return $this->_name; } /** * Sets company name. Valid only for billing addresses. * * @param string $name * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setCompanyName($name) { $this->_companyName = $name; return $this; } /** * Returns company name. * @return string */ public function getCompanyName() { return $this->_companyName; } /** * Sets address. * * @param string $address1 * @param string $address2 * @return \LinkPoint\Address */ public function setAddress($address1, $address2 = null) { $this->setAddress1($address1); if (null !== $address2) { $this->setAddress2($address2); } return $this; } public function setAddress1($address) { $addr = explode(' ', $address); if (is_numeric($addr[0])) { $this->setAddressNumber($addr[0]); } $this->_address1 = $address; return $this; } public function setAddress2($address) { $this->_address2 = $address; return $this; } /** * Gets address parts. * * @param int $part * @return array|string * @throws \LinkPoint\Exception */ public function getAddress($part = null) { if ($part == 1) { return $this->_address1; } elseif ($part == 2) { return $this->_address2; } return array($this->_address1, $this->_address2); } /** * Sets the address building number. * * @param int $num * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setAddressNumber($num) { if (is_numeric($num)) { $this->_addressNumber = $num; } else { throw new \LinkPoint\Exception('Address bulding number must be a number'); } return $this; } /** * Gets the address building number. * * @return int */ public function getAddressNumber() { return $this->_addressNumber; } /** * Sets city name. * * @param string $city * @return \LinkPoint\Address */ public function setCity($city) { $this->_city = $city; return $this; } /** * Returns city name. * @return string */ public function getCity() { return $this->_city; } /** * Sets province. * * @param string $province * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setProvince($province) { $this->_province = $province; return $this; } /** * Gets province. * @return string */ public function getProvince() { return $this->_province; } public function setState($state) { $this->_province = $state; return $this; } public function getState() { return $this->_province; } /** * Sets postal code. * * @param string $postCode * @return \LinkPoint\Address */ public function setPostCode($postCode) { $this->_postCode = $postCode; return $this; } /** * Returns postal code. * @return string */ public function getPostCode() { return $this->_postCode; } public function setZip($zip) { $this->_postCode = $zip; return $this; } public function getZip() { return $this->_postCode; } /** * Sets country code. * * @param string $country * @return \LinkPoint\Address */ public function setCountry($country) { $this->_country = $country; return $this; } /** * Returns country code. * @return string */ public function getCountry() { return $this->_country; } /** * Sets phone number. * * @param string $phone * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setPhone($phone) { $this->_phone = $phone; return $this; } /** * Returns phone number. * @return string */ public function getPhone() { return $this->_phone; } /** * Sets fax number. Valid only for billing addresses. * * @param string $fax * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setFax($fax) { $this->_fax = $fax; return $this; } /** * Returns fax number. * @return string */ public function getFax() { return (string) preg_replace('/[^0-9]/', '', $this->_fax); } /** * Sets email address. * * @param string $email * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setEmail($email) { $this->_email = $email; return $this; } /** * Returns email address. * @return string */ public function getEmail() { return $this->_email; } /** * Sets the user ID. Valid only for billing addresses. * * @param string $userId * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setUserId($userId) { $this->_userId = $userId; return $this; } /** * Returns the user ID. * @return string */ public function getUserId() { return $this->_userId; } /** * Sets the transaction weight. Valid only for shipping addresses. * * @param float $weight * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setWeight($weight) { $this->_weight = $weight; } /** * Returns the weight. * @return float */ public function getWeight() { return $this->_weight; } /** * Sets the number of items going to this address. Valid only for shipping addresses. * * @param int $items * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setItemCount($items) { $this->_itemCount = $items; return $this; } /** * Returns the number of items going to this address. * @return integer */ public function getItemCount() { return $this->_itemCount; } /** * Sets the shipping carrier ID number. Valid only for shipping addresses. * * @param int $id * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setCarrier($id) { $this->_shippingCarrier = $id; return $this; } /** * Returns the ID of the shipping carrier going to this address. * @return integer */ public function getCarrier() { return $this->_shippingCarrier; } /** * Sets the order total before shipping charges. Valid only for shipping addresses. * * @param float $total * @return \LinkPoint\Address * @throws \LinkPoint\Exception */ public function setTotal($total = 0.00) { $this->_total = $total; return $this; } /** * Returns the order total before shipping charges going to this address. * @return integer */ public function getTotal() { return $this->_total; } /** * Convert the address object into an XML entity * that can be sent to the payment processor. */ public function __toString() { $doc = new \DOMDocument(); // root element $xml = $doc->createElement($this->getAddressType()); // name if ($this->getName()) { $xml->appendChild($doc->createElement('name', $this->getName())); } // address1 if ($this->getAddress(1)) { $xml->appendChild($doc->createElement('address1', $this->getAddress(1))); } // address2 if ($this->getAddress(2)) { $xml->appendChild($doc->createElement('address2', $this->getAddress(2))); } // addrnum if ($this->getAddressNumber()) { $xml->appendChild($doc->createElement('addrnum', $this->getAddressNumber())); } // city if ($this->getCity()) { $xml->appendChild($doc->createElement('city', $this->getCity())); } // state if ($this->getProvince()) { $xml->appendChild($doc->createElement('state', $this->getProvince())); } // zip if ($this->getPostCode()) { $xml->appendChild($doc->createElement('zip', $this->getPostCode())); } // phone if ($this->getPhone()) { $xml->appendChild($doc->createElement('phone', $this->getPhone())); } // fax if ($this->getFax()) { $xml->appendChild($doc->createElement('fax', $this->getFax())); } // email if ($this->getEmail()) { $xml->appendChild($doc->createElement('email', $this->getEmail())); } // userid if ($this->getUserId()) { $xml->appendChild($doc->createElement('userid', $this->getUserId())); } // weight if ($this->getWeight()) { $xml->appendChild($doc->createElement('weight', $this->getWeight())); } // items if ($this->getItemCount()) { $xml->appendChild($doc->createElement('items', $this->getItemCount())); } // carrier if ($this->getCarrier()) { $xml->appendChild($doc->createElement('carrier', $this->getCarrier())); } // carrier if ($this->getTotal()) { $xml->appendChild($doc->createElement('total', $this->getTotal())); } $doc->appendChild($xml); return $doc->saveHTML(); } }