Exemplo n.º 1
0
 public function testCreateRequest()
 {
     $tit = new Ups\TimeInTransit();
     $tit->setRequest($request = new RequestMock());
     $data = new \Ups\Entity\TimeInTransitRequest();
     // Addresses
     $from = new \Ups\Entity\AddressArtifactFormat();
     $from->setPoliticalDivision3('Amsterdam');
     $from->setPostcodePrimaryLow('1000AA');
     $from->setCountryCode('NL');
     $data->setTransitFrom($from);
     $to = new \Ups\Entity\AddressArtifactFormat();
     $to->setPoliticalDivision3('Amsterdam');
     $to->setPostcodePrimaryLow('1000AA');
     $to->setCountryCode('NL');
     $data->setTransitTo($to);
     // Weight
     $shipmentWeight = new \Ups\Entity\ShipmentWeight();
     $shipmentWeight->setWeight(5.0);
     $unit = new \Ups\Entity\UnitOfMeasurement();
     $unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS);
     $shipmentWeight->setUnitOfMeasurement($unit);
     $data->setShipmentWeight($shipmentWeight);
     // Packages
     $data->setTotalPackagesInShipment(2);
     // InvoiceLines
     $invoiceLineTotal = new \Ups\Entity\InvoiceLineTotal();
     $invoiceLineTotal->setMonetaryValue(100.0);
     $invoiceLineTotal->setCurrencyCode('EUR');
     $data->setInvoiceLineTotal($invoiceLineTotal);
     // Pickup date
     $data->setPickupDate(new \DateTime('2015-05-23'));
     try {
         // Get data
         $times = $tit->getTimeInTransit($data);
     } catch (Exception $e) {
     }
     $this->assertEquals($request->getRequestXml(), $request->getExpectedRequestXml('/TimeInTransit/Request1.xml'));
     // Try now with documentsOnlyIndicator
     $data->setDocumentsOnlyIndicator();
     try {
         // Get data
         $times = $tit->getTimeInTransit($data);
     } catch (Exception $e) {
     }
     $this->assertEquals($request->getRequestXml(), $request->getExpectedRequestXml('/TimeInTransit/Request2.xml'));
 }
Exemplo n.º 2
0
 /**
  * Create the TimeInTransit request.
  *
  * @param TimeInTransitRequest $timeInTransitRequest The request details. Refer to the UPS documentation for available structure
  *
  * @return string
  */
 private function createRequest(TimeInTransitRequest $timeInTransitRequest)
 {
     $xml = new DOMDocument();
     $xml->formatOutput = true;
     $trackRequest = $xml->appendChild($xml->createElement('TimeInTransitRequest'));
     $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', 'TimeInTransit'));
     $transitFromNode = $trackRequest->appendChild($xml->createElement('TransitFrom'));
     $address = $timeInTransitRequest->getTransitFrom();
     if (isset($address)) {
         $transitFromNode->appendChild($address->toNode($xml));
     }
     $transitToNode = $trackRequest->appendChild($xml->createElement('TransitTo'));
     $address = $timeInTransitRequest->getTransitTo();
     if (isset($address)) {
         $transitToNode->appendChild($address->toNode($xml));
     }
     $weight = $timeInTransitRequest->getShipmentWeight();
     if (isset($weight)) {
         $trackRequest->appendChild($weight->toNode($xml));
     }
     $packages = $timeInTransitRequest->getTotalPackagesInShipment();
     if (isset($packages)) {
         $trackRequest->appendChild($xml->createElement('TotalPackagesInShipment', $packages));
     }
     $invoiceLineTotal = $timeInTransitRequest->getInvoiceLineTotal();
     if (isset($invoiceLineTotal)) {
         $trackRequest->appendChild($invoiceLineTotal->toNode($xml));
     }
     $pickupDate = $timeInTransitRequest->getPickupDate();
     if ($pickupDate) {
         $trackRequest->appendChild($xml->createElement('PickupDate', $pickupDate->format('Ymd')));
     }
     $indicator = $timeInTransitRequest->getDocumentsOnlyIndicator();
     if ($indicator) {
         $trackRequest->appendChild($xml->createElement('DocumentsOnlyIndicator'));
     }
     return $xml->saveXML();
 }