Exemplo n.º 1
0
 /**
  * @param null|object $attributes
  */
 public function __construct($attributes = null)
 {
     if (null !== $attributes) {
         if (isset($attributes->SingleLineAddress)) {
             $this->setSingleLineAddress($attributes->SingleLineAddress);
         }
     }
     parent::__construct($attributes);
 }
Exemplo n.º 2
0
 /**
  * @param null|object $attributes
  */
 public function __construct($attributes = null)
 {
     if (null !== $attributes) {
         if (isset($attributes->Country)) {
             $this->setCountryCode($attributes->Country);
         }
     }
     parent::__construct($attributes);
 }
Exemplo n.º 3
0
 /**
  * Create the XAV request.
  *
  * @return string
  */
 private function createRequest()
 {
     $xml = new DOMDocument();
     $xml->formatOutput = true;
     $avRequest = $xml->appendChild($xml->createElement('AddressValidationRequest'));
     $avRequest->setAttribute('xml:lang', 'en-US');
     $request = $avRequest->appendChild($xml->createElement('Request'));
     $node = $xml->importNode($this->createTransactionNode(), true);
     $request->appendChild($node);
     $request->appendChild($xml->createElement('RequestAction', 'XAV'));
     if (null !== $this->requestOption) {
         $request->appendChild($xml->createElement('RequestOption', $this->requestOption));
     }
     if (null !== $this->maxSuggestion) {
         $avRequest->appendChild($xml->createElement('MaximumListSize', $this->maxSuggestion));
     }
     if (null !== $this->address) {
         $addressNode = $avRequest->appendChild($xml->createElement('AddressKeyFormat'));
         if ($this->address->getAttentionName()) {
             $addressNode->appendChild($xml->createElement('ConsigneeName', $this->address->getAttentionName()));
         }
         if ($this->address->getBuildingName()) {
             $addressNode->appendChild($xml->createElement('BuildingName', $this->address->getBuildingName()));
         }
         if ($this->address->getAddressLine1()) {
             $addressNode->appendChild($xml->createElement('AddressLine', $this->address->getAddressLine1()));
         }
         if ($this->address->getAddressLine2()) {
             $addressNode->appendChild($xml->createElement('AddressLine', $this->address->getAddressLine2()));
         }
         if ($this->address->getAddressLine3()) {
             $addressNode->appendChild($xml->createElement('AddressLine', $this->address->getAddressLine3()));
         }
         if ($this->address->getStateProvinceCode()) {
             $addressNode->appendChild($xml->createElement('PoliticalDivision2', $this->address->getStateProvinceCode()));
         }
         if ($this->address->getCity()) {
             $addressNode->appendChild($xml->createElement('PoliticalDivision1', $this->address->getCity()));
         }
         if ($this->address->getCountryCode()) {
             $addressNode->appendChild($xml->createElement('CountryCode', $this->address->getCountryCode()));
         }
         if ($this->address->getPostalCode()) {
             $addressNode->appendChild($xml->createElement('PostcodePrimaryLow', $this->address->getPostalCode()));
         }
     }
     return $xml->saveXML();
 }
 public function testCreateRequest()
 {
     $xavRequest = new \Ups\AddressValidation();
     $xavRequest->setRequest($request = new RequestMock());
     $address = new \Ups\Entity\Address();
     $address->setAttentionName('Test Test');
     $address->setBuildingName('Building 1');
     $address->setAddressLine1('Times Square 1');
     $address->setAddressLine2('First Corner');
     $address->setAddressLine3('Second Corner');
     $address->setStateProvinceCode('NY');
     $address->setCity('New York');
     $address->setCountryCode('US');
     $address->setPostalCode('50000');
     try {
         // Get data
         $response = $xavRequest->validate($address);
     } catch (Exception $e) {
     }
     $this->assertEquals($request->getRequestXml(), $request->getExpectedRequestXml('/AddressValidation/Request1.xml'));
 }
Exemplo n.º 5
0
 /**
  * Build a UPS Cpmpatible Address Object from a Model
  * @param Contao\Model
  * @return stdClass
  */
 protected static function buildAddress(Model $objModel)
 {
     $Address = new Ups_Address();
     $arrSubdivision = explode('-', $objModel->subdivision);
     $Address->setAddressLine1($objModel->street_1);
     $Address->setAddressLine2($objModel->street_2);
     $Address->setAddressLine3($objModel->street_3);
     $Address->setCity($objModel->city);
     $Address->setStateProvinceCode(strtoupper($arrSubdivision[1]));
     $Address->setPostalCode($objModel->postal);
     $Address->setCountryCode(strtoupper($arrSubdivision[0]));
     return $Address;
 }