Пример #1
0
 /**
  * Creates and sends a request for the given shipment. This handles checking for
  * errors in the response back from UPS.
  *
  * @param RateRequest $rateRequest
  *
  * @throws Exception
  *
  * @return RateRequest
  */
 private function sendRequest(RateRequest $rateRequest)
 {
     $request = $this->createRequest($rateRequest);
     //$response = $this->request($this->createAccess(), $request, $this->compileEndpointUrl(self::ENDPOINT));
     $this->response = $this->getRequest()->request($this->createAccess(), $request, $this->compileEndpointUrl(self::ENDPOINT));
     $response = $this->response->getResponse();
     if (null === $response) {
         throw new Exception('Failure (0): Unknown error', 0);
     }
     if ($response->Response->ResponseStatusCode == 0) {
         throw new Exception("Failure ({$response->Response->Error->ErrorSeverity}): {$response->Response->Error->ErrorDescription}", (int) $response->Response->Error->ErrorCode);
     } else {
         return $this->formatResponse($response);
     }
 }
Пример #2
0
 /**
  * Get package tracking information.
  *
  * @param string $trackingNumber The package's tracking number.
  * @param string $requestOption Optional processing. For Mail Innovations the only valid options are Last Activity and All activity.
  *
  * @throws Exception
  *
  * @return stdClass
  */
 public function track($trackingNumber, $requestOption = 'activity')
 {
     $this->trackingNumber = $trackingNumber;
     $this->requestOption = $requestOption;
     $access = $this->createAccess();
     $request = $this->createRequest();
     $this->response = $this->getRequest()->request($access, $request, $this->compileEndpointUrl(self::ENDPOINT));
     $response = $this->response->getResponse();
     if (null === $response) {
         throw new Exception('Failure (0): Unknown error', 0);
     }
     if ($response instanceof SimpleXMLElement && $response->Response->ResponseStatusCode == 0) {
         throw new Exception("Failure ({$response->Response->Error->ErrorSeverity}): {$response->Response->Error->ErrorDescription}", (int) $response->Response->Error->ErrorCode);
     } else {
         return $this->formatResponse($response);
     }
 }
Пример #3
0
 /**
  * Get address suggestions from UPS
  *
  * @param $address
  * @param int $requestOption
  * @param int $maxSuggestion
  * @return stdClass
  * @throws Exception
  */
 public function validate($address, $requestOption = self::REQUEST_OPTION_ADDRESS_VALIDATION, $maxSuggestion = 15)
 {
     if ($maxSuggestion > 50) {
         throw new \Exception('Maximum of 50 suggestions allowed');
     }
     if (!in_array($requestOption, range(1, 3))) {
         throw new \Exception('Invalid request option supplied');
     }
     $this->address = $address;
     $this->requestOption = $requestOption;
     $this->maxSuggestion = $maxSuggestion;
     $access = $this->createAccess();
     $request = $this->createRequest();
     $this->response = $this->getRequest()->request($access, $request, $this->compileEndpointUrl(self::ENDPOINT));
     $response = $this->response->getResponse();
     if (null === $response) {
         throw new Exception("Failure (0): Unknown error", 0);
     }
     if ($response instanceof SimpleXMLElement && $response->Response->ResponseStatusCode == 0) {
         throw new Exception("Failure ({$response->Response->Error->ErrorSeverity}): {$response->Response->Error->ErrorDescription}", (int) $response->Response->Error->ErrorCode);
     } else {
         return $this->formatResponse($response);
     }
 }
Пример #4
0
 /**
  * Get a QuantumView subscription
  *
  * @param string $name Name of subscription requested by user.
  * @param string $beginDateTime Beginning date time for the retrieval criteria of the subscriptions. Format: Y-m-d H:i:s or Unix timestamp.
  * @param string $endDateTime Ending date time for the retrieval criteria of the subscriptions. Format: Y-m-d H:i:s or Unix timestamp.
  * @param string $fileName File name of specific subscription requested by user.
  * @param string $bookmark Bookmarks the file for next retrieval.
  * @return ArrayObject
  * @throws Exception
  */
 public function getSubscription($name = null, $beginDateTime = null, $endDateTime = null, $fileName = null, $bookmark = null)
 {
     // Format date times
     if (null !== $beginDateTime) {
         $beginDateTime = $this->formatDateTime($beginDateTime);
     }
     if (null !== $endDateTime) {
         $endDateTime = $this->formatDateTime($endDateTime);
     }
     // If user provided a begin date time but no end date time, we assume the end date time is now
     if (null !== $beginDateTime && null === $endDateTime) {
         $endDateTime = $this->formatDateTime(time());
     }
     $this->name = $name;
     $this->beginDateTime = $beginDateTime;
     $this->endDateTime = $endDateTime;
     $this->fileName = $fileName;
     $this->bookmark = $bookmark;
     // Create request
     $access = $this->createAccess();
     $request = $this->createRequest();
     $this->response = $this->getRequest()->request($access, $request, $this->compileEndpointUrl(self::ENDPOINT));
     $response = $this->response->getResponse();
     if (null === $response) {
         throw new Exception("Failure (0): Unknown error", 0);
     }
     if ($response->Response->ResponseStatusCode == 0) {
         throw new Exception("Failure ({$response->Response->Error->ErrorSeverity}): {$response->Response->Error->ErrorDescription}", (int) $response->Response->Error->ErrorCode);
     } else {
         if (isset($response->Bookmark)) {
             $this->setBookmark((string) $response->Bookmark);
         } else {
             $this->setBookmark(null);
         }
         return $this->formatResponse($response);
     }
 }