Example #1
0
 /**
  * Invoke request and return response
  */
 private function _invoke(array $parameters)
 {
     $actionName = $parameters["Action"];
     $response = array();
     $responseBody = null;
     $statusCode = 200;
     /* Submit the request and read response body */
     try {
         if (empty($this->_config['ServiceURL'])) {
             throw new OffAmazonPaymentsService_Exception(array('ErrorCode' => 'InvalidServiceURL', 'Message' => "Missing serviceUrl configuration value. You may obtain a list of valid MWS URLs by consulting the MWS Developer's Guide, or reviewing the sample code published along side this library."));
         }
         /* Add required request parameters */
         $parameters = $this->_addRequiredParameters($parameters);
         $shouldRetry = true;
         $retries = 0;
         do {
             try {
                 $response = $this->_httpPost($parameters);
                 if ($response['Status'] === 200) {
                     $shouldRetry = false;
                 } else {
                     if ($response['Status'] === 500 || $response['Status'] === 503) {
                         require_once 'OffAmazonPaymentsService/Model/ErrorResponse.php';
                         $errorResponse = OffAmazonPaymentsService_Model_ErrorResponse::fromXML($response['ResponseBody']);
                         $errors = $errorResponse->getError();
                         $shouldRetry = $errors[0]->getCode() === 'RequestThrottled' ? false : true;
                         if ($shouldRetry) {
                             $this->_pauseOnRetry(++$retries, $response['Status']);
                         } else {
                             throw $this->_reportAnyErrors($response['ResponseBody'], $response['Status'], $response['ResponseHeaderMetadata']);
                         }
                     } else {
                         throw $this->_reportAnyErrors($response['ResponseBody'], $response['Status'], $response['ResponseHeaderMetadata']);
                     }
                 }
                 /* Rethrow on deserializer error */
             } catch (Exception $e) {
                 require_once 'OffAmazonPaymentsService/Exception.php';
                 if ($e instanceof OffAmazonPaymentsService_Exception) {
                     throw $e;
                 } else {
                     require_once 'OffAmazonPaymentsService/Exception.php';
                     throw new OffAmazonPaymentsService_Exception(array('Exception' => $e, 'Message' => $e->getMessage()));
                 }
             }
         } while ($shouldRetry);
     } catch (OffAmazonPaymentsService_Exception $se) {
         throw $se;
     } catch (Exception $t) {
         throw new OffAmazonPaymentsService_Exception(array('Exception' => $t, 'Message' => $t->getMessage()));
     }
     return array('ResponseBody' => $response['ResponseBody'], 'ResponseHeaderMetadata' => $response['ResponseHeaderMetadata']);
 }
Example #2
0
 /**
  * Invoke request and return response
  */
 private function _invoke(array $parameters)
 {
     $actionName = $parameters["Action"];
     $response = array();
     $responseBody = null;
     $statusCode = 200;
     /* Submit the request and read response body */
     try {
         /* Add required request parameters */
         $parameters = $this->_addRequiredParameters($parameters);
         $shouldRetry = true;
         $retries = 0;
         do {
             try {
                 $response = $this->_httpPost($parameters);
                 if ($response['Status'] == 200) {
                     $shouldRetry = false;
                 } else {
                     if ($response['Status'] == 500 || $response['Status'] == 503) {
                         $errorResponse = OffAmazonPaymentsService_Model_ErrorResponse::fromXML($response['ResponseBody']);
                         $errors = $errorResponse->getError();
                         $shouldRetry = $errors[0]->getCode() === 'RequestThrottled' ? false : true;
                         if ($shouldRetry) {
                             $this->_pauseOnRetry(++$retries, $response['Status']);
                         } else {
                             throw $this->_reportAnyErrors($response['ResponseBody'], $response['Status'], $response['ResponseHeaderMetadata']);
                         }
                     } else {
                         throw $this->_reportAnyErrors($response['ResponseBody'], $response['Status'], $response['ResponseHeaderMetadata']);
                     }
                 }
                 /* Rethrow on deserializer error */
             } catch (Exception $e) {
                 if ($e instanceof OffAmazonPaymentsService_Exception) {
                     throw $e;
                 } else {
                     throw new OffAmazonPaymentsService_Exception(array('Exception' => $e, 'Message' => $e->getMessage()));
                 }
             }
         } while ($shouldRetry);
     } catch (OffAmazonPaymentsService_Exception $se) {
         throw $se;
     } catch (Exception $t) {
         throw new OffAmazonPaymentsService_Exception(array('Exception' => $t, 'Message' => $t->getMessage()));
     }
     return array('ResponseBody' => $response['ResponseBody'], 'ResponseHeaderMetadata' => $response['ResponseHeaderMetadata']);
 }