Exemple #1
0
 /**
  * Create the Rate request.
  *
  * @param RateRequest $rateRequest The request details. Refer to the UPS documentation for available structure
  *
  * @return string
  */
 private function createRequest(RateRequest $rateRequest)
 {
     $shipment = $rateRequest->getShipment();
     $document = $xml = new DOMDocument();
     $xml->formatOutput = true;
     /** @var DOMElement $trackRequest */
     $trackRequest = $xml->appendChild($xml->createElement('RatingServiceSelectionRequest'));
     $trackRequest->setAttribute('xml:lang', 'en-US');
     $request = $trackRequest->appendChild($xml->createElement('Request'));
     $node = $xml->importNode($this->createTransactionNode(), true);
     $request->appendChild($node);
     $request->appendChild($xml->createElement('RequestAction', 'Rate'));
     $request->appendChild($xml->createElement('RequestOption', $this->requestOption));
     $trackRequest->appendChild($rateRequest->getPickupType()->toNode($document));
     $shipmentNode = $trackRequest->appendChild($xml->createElement('Shipment'));
     // Support specifying an individual service
     $service = $shipment->getService();
     if (isset($service)) {
         $shipmentNode->appendChild($service->toNode($document));
     }
     $shipper = $shipment->getShipper();
     if (isset($shipper)) {
         $shipmentNode->appendChild($shipper->toNode($document));
     }
     $shipFrom = $shipment->getShipFrom();
     if (isset($shipFrom)) {
         $shipmentNode->appendChild($shipFrom->toNode($document));
     }
     $shipTo = $shipment->getShipTo();
     if (isset($shipTo)) {
         $shipmentNode->appendChild($shipTo->toNode($document));
     }
     $alternateDeliveryAddress = $shipment->getAlternateDeliveryAddress();
     if (isset($alternateDeliveryAddress)) {
         $shipmentNode->appendChild($alternateDeliveryAddress->toNode($document));
     }
     $rateInformation = $shipment->getRateInformation();
     if ($rateInformation !== null) {
         $shipmentNode->appendChild($rateInformation->toNode($document));
     }
     $shipmentIndicationType = $shipment->getShipmentIndicationType();
     if (isset($shipmentIndicationType)) {
         $shipmentNode->appendChild($shipmentIndicationType->toNode($document));
     }
     foreach ($shipment->getPackages() as $package) {
         $shipmentNode->appendChild($package->toNode($document));
     }
     $shipmentServiceOptions = $shipment->getShipmentServiceOptions();
     if (isset($shipmentServiceOptions)) {
         $shipmentNode->appendChild($shipmentServiceOptions->toNode($xml));
     }
     return $xml->saveXML();
 }
Exemple #2
0
 /**
  * @expectedException \Exception
  */
 public function testGetRateInvalidShipment()
 {
     $request = new RateRequest();
     $shipment = new Shipment();
     $shipment->Shipper = new \stdClass();
     $shipment->Shipper->Name = 'Test Shipper';
     $shipment->Shipper->ShipperNumber = '12345';
     $shipment->Shipper->Address = new \stdClass();
     $shipment->Shipper->Address->AddressLine1 = '123 Some St.';
     $shipment->Shipper->Address->City = 'Test';
     $shipment->Shipper->Address->PostalCode = '12345';
     $shipment->Shipper->Address->StateProvinceCode = 'WA';
     $shipment->ShipTo = new \stdClass();
     $shipment->ShipTo->CompanyName = 'Test ShipTo';
     $shipment->ShipTo->Address = new \stdClass();
     $shipment->ShipTo->Address->AddressLine1 = '1234 Some St.';
     $shipment->ShipTo->Address->City = 'Other City';
     $shipment->ShipTo->Address->PostalCode = '12345';
     $shipment->ShipTo->Address->StateProvinceCode = 'WA';
     $shipment->Service = new \stdClass();
     $shipment->Service->Code = '03';
     $package = new \stdClass();
     $package->PackagingType = new \stdClass();
     $package->PackagingType->Code = '02';
     $package->PackageWeight = new \stdClass();
     $package->PackageWeight->Weight = '10';
     $shipment->Package = array($package);
     $request->setShipment($shipment);
     // should throw exception cause invalid zip code
     throw new \Exception();
     // fixme
     //$this->rate->getRate($shipment);
 }