Example #1
0
 /**
  * Build the validate address request
  * @internal
  * @return string
  * @throws \SimpleUPS\Api\MissingParameterException
  */
 public function buildXml()
 {
     if ($this->getShipment()->getDestination() == null) {
         throw new MissingParameterException('Shipment destination is missing');
     }
     $dom = new \DomDocument('1.0');
     $dom->formatOutput = $this->getDebug();
     $dom->appendChild($ratingRequest = $dom->createElement('RatingServiceSelectionRequest'));
     $addressRequestLang = $dom->createAttribute('xml:lang');
     $addressRequestLang->value = parent::getXmlLang();
     $ratingRequest->appendChild($request = $dom->createElement('Request'));
     $request->appendChild($transactionReference = $dom->createElement('TransactionReference'));
     $transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext()));
     $request->appendChild($dom->createElement('RequestAction', 'Rate'));
     $request->appendChild($dom->createElement('RequestOption', 'Shop'));
     //@todo test with "Rate" as setting to determine difference
     $ratingRequest->appendChild($pickupType = $dom->createElement('PickupType'));
     $pickupType->appendChild($shipmentType = $dom->createElement('Code', $this->getPickupType()));
     if ($this->getRateType() != null) {
         $ratingRequest->appendChild($customerClassification = $dom->createElement('CustomerClassification'));
         $customerClassification->appendChild($dom->createElement('Code', $this->getRateType()));
     }
     // Shipment
     $shipment = $this->getShipment();
     $shipment->setShipper(UPS::getShipper());
     $ratingRequest->appendChild($shipment->toXml($dom));
     $xml = parent::buildAuthenticationXml() . $dom->saveXML();
     return $xml;
 }
Example #2
0
 /**
  * Build the validate address request
  * @return string
  * @throws \SimpleUPS\Api\MissingParameterException
  */
 public function buildXml()
 {
     if (serialize($this->getAddress()) == serialize(new Address())) {
         throw new MissingParameterException('Address requires a Country code, Postal code, and either a City or State\\Province code');
     }
     if ($this->getAddress()->getCountryCode() === null) {
         throw new MissingParameterException('Address requires a Country code');
     }
     if ($this->getAddress()->getPostalCode() === null) {
         throw new MissingParameterException('Address requires a Postal code');
     }
     $dom = new \DomDocument('1.0');
     $dom->formatOutput = $this->getDebug();
     $dom->appendChild($addressRequest = $dom->createElement('AddressValidationRequest'));
     $addressRequestLang = $dom->createAttribute('xml:lang');
     $addressRequestLang->value = parent::getXmlLang();
     $addressRequest->appendChild($request = $dom->createElement('Request'));
     $request->appendChild($transactionReference = $dom->createElement('TransactionReference'));
     $transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext()));
     $transactionReference->appendChild($dom->createElement('XpciVersion', $this->getXpciVersion()));
     $request->appendChild($dom->createElement('RequestAction', 'AV'));
     $addressRequest->appendChild($address = $dom->createElement('Address'));
     if ($this->getAddress()->getCity() != null) {
         $address->appendChild($dom->createElement('City', $this->getAddress()->getCity()));
     }
     if ($this->getAddress()->getStateProvinceCode() != null) {
         $address->appendChild($dom->createElement('StateProvinceCode', $this->getAddress()->getStateProvinceCode()));
     }
     if ($this->getAddress()->getPostalCode() != null) {
         $address->appendChild($dom->createElement('PostalCode', $this->getAddress()->getPostalCode()));
     }
     $address->appendChild($dom->createElement('CountryCode', $this->getAddress()->getCountryCode()));
     $xml = parent::buildAuthenticationXml() . $dom->saveXML();
     return $xml;
 }
Example #3
0
 /**
  * Build the validate address request
  * @return string
  * @throws \SimpleUPS\Api\MissingParameterException
  */
 public function buildXml()
 {
     if (serialize($this->getAddress()) == serialize(new Address())) {
         throw new MissingParameterException('Address requires a Country code and a City, a State\\Province code or a Postal code');
     }
     if ($this->getAddress()->getCountryCode() === null) {
         throw new MissingParameterException('Address requires a Country code');
     }
     $dom = new \DomDocument('1.0');
     $dom->formatOutput = $this->getDebug();
     $dom->appendChild($addressRequest = $dom->createElement('AddressValidationRequest'));
     $addressRequestLang = $dom->createAttribute('xml:lang');
     $addressRequestLang->value = parent::getXmlLang();
     $addressRequest->appendChild($request = $dom->createElement('Request'));
     $request->appendChild($transactionReference = $dom->createElement('TransactionReference'));
     $transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext()));
     $request->appendChild($dom->createElement('RequestAction', 'XAV'));
     $request->appendChild($dom->createElement('RequestOption', '3'));
     $addressRequest->appendChild($address = $dom->createElement('AddressKeyFormat'));
     $address->appendChild($dom->createElement('AddressLine', $this->getAddress()->getStreet()));
     if ($this->getAddress()->getAddressLine2()) {
         $address->appendChild($dom->createElement('AddressLine', $this->getAddress()->getAddressLine2()));
         if ($this->getAddress()->getAddressLine3()) {
             $address->appendChild($dom->createElement('AddressLine', $this->getAddress()->getAddressLine3()));
         }
     }
     if ($this->getAddress()->getCity() != null) {
         $address->appendChild($dom->createElement('PoliticalDivision2', $this->getAddress()->getCity()));
     }
     if ($this->getAddress()->getStateProvinceCode() != null) {
         $address->appendChild($dom->createElement('PoliticalDivision1', $this->getAddress()->getStateProvinceCode()));
     }
     if ($this->getAddress()->getPostalCode() != null) {
         $address->appendChild($dom->createElement('PostcodePrimaryLow', $this->getAddress()->getPostalCode()));
     }
     $address->appendChild($dom->createElement('CountryCode', $this->getAddress()->getCountryCode()));
     $xml = parent::buildAuthenticationXml() . $dom->saveXML();
     return $xml;
 }