/**
  * Invoke request and return response
  */
 private function invoke(array $converted, $dataHandle = null, $contentMd5 = null)
 {
     $parameters = $converted[CONVERTED_PARAMETERS_KEY];
     $actionName = $parameters["Action"];
     $response = array();
     $responseBody = null;
     $statusCode = 200;
     /* Submit the request and read response body */
     try {
         // Ensure the endpoint URL is set.
         if (empty($this->config['ServiceURL'])) {
             throw new MarketplaceWebService_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);
         $converted[CONVERTED_PARAMETERS_KEY] = $parameters;
         $shouldRetry = false;
         $retries = 0;
         do {
             try {
                 $response = $this->performRequest($actionName, $converted, $dataHandle, $contentMd5);
                 $httpStatus = $response['Status'];
                 switch ($httpStatus) {
                     case 200:
                         $shouldRetry = false;
                         break;
                     case 500:
                     case 503:
                         require_once dirname(__FILE__) . '/Model/ErrorResponse.php';
                         $errorResponse = MarketplaceWebService_Model_ErrorResponse::fromXML($response['ResponseBody']);
                         // We will not retry throttling errors since this would just add to the throttling problem.
                         $shouldRetry = $errorResponse->getError()->getCode() === 'RequestThrottled' ? false : true;
                         if ($shouldRetry && $retries <= $this->config['MaxErrorRetry']) {
                             $this->pauseOnRetry(++$retries);
                         } else {
                             throw $this->reportAnyErrors($response['ResponseBody'], $response['Status'], $response['ResponseHeaderMetadata']);
                         }
                         break;
                     default:
                         $shouldRetry = false;
                         throw $this->reportAnyErrors($response['ResponseBody'], $response['Status'], $response['ResponseHeaderMetadata']);
                         break;
                 }
                 /* Rethrow on deserializer error */
             } catch (Exception $e) {
                 require_once dirname(__FILE__) . '/Exception.php';
                 throw new MarketplaceWebService_Exception(array('Exception' => $e, 'Message' => $e->getMessage()));
             }
         } while ($shouldRetry);
     } catch (MarketplaceWebService_Exception $se) {
         throw $se;
     } catch (Exception $t) {
         throw new MarketplaceWebService_Exception(array('Exception' => $t, 'Message' => $t->getMessage()));
     }
     return array('ResponseBody' => $response['ResponseBody'], 'ResponseHeaderMetadata' => $response['ResponseHeaderMetadata']);
 }
 /**
  * Invoke request and return response
  */
 private function invoke(array $converted, $dataHandle = null, $contentMd5 = null)
 {
     $parameters = $converted[CONVERTED_PARAMETERS_KEY];
     $actionName = $parameters["Action"];
     $response = array();
     $responseBody = null;
     $statusCode = 200;
     /* Submit the request and read response body */
     try {
         // Ensure the endpoint URL is set.
         if (empty($this->config['ServiceURL'])) {
             throw new MarketplaceWebService_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);
         $converted[CONVERTED_PARAMETERS_KEY] = $parameters;
         // log to db - before request
         $this->dblogger->updateLog(array('callname' => $actionName, 'request' => maybe_serialize($converted), 'parameters' => maybe_serialize($parameters), 'account_id' => $this->account_id, 'market_id' => $this->market_id, 'success' => 'pending'));
         $shouldRetry = false;
         $retries = 0;
         do {
             try {
                 $response = $this->performRequest($actionName, $converted, $dataHandle, $contentMd5);
                 $httpStatus = $response['Status'];
                 // log to db - after request
                 $this->dblogger->updateLog(array('response' => maybe_serialize($response), 'http_code' => $response['Status'], 'success' => 'HTTP OK'));
                 switch ($httpStatus) {
                     case 200:
                         $shouldRetry = false;
                         break;
                     case 500:
                     case 503:
                         require_once 'MarketplaceWebService/Model/ErrorResponse.php';
                         $errorResponse = MarketplaceWebService_Model_ErrorResponse::fromXML($response['ResponseBody']);
                         // We will not retry throttling errors since this would just add to the throttling problem.
                         $shouldRetry = $errorResponse->getError()->getCode() === 'RequestThrottled' ? false : true;
                         if ($shouldRetry && $retries <= $this->config['MaxErrorRetry']) {
                             $this->pauseOnRetry(++$retries);
                         } else {
                             throw $this->reportAnyErrors($response['ResponseBody'], $response['Status'], null, $response['ResponseHeaderMetadata']);
                         }
                         break;
                     default:
                         $shouldRetry = false;
                         throw $this->reportAnyErrors($response['ResponseBody'], $response['Status'], null, $response['ResponseHeaderMetadata']);
                         break;
                 }
                 /* Rethrow on deserializer error */
             } catch (Exception $e) {
                 require_once 'MarketplaceWebService/Exception.php';
                 // log to db - error
                 $success = 'Error';
                 $this->dblogger->updateLog(array('result' => $e->getMessage(), 'success' => $success));
                 wpla_show_message($actionName . ' request failed with error: ' . $e->getMessage(), 'error');
                 throw new MarketplaceWebService_Exception(array('Exception' => $e, 'Message' => $e->getMessage()));
             }
         } while ($shouldRetry);
     } catch (MarketplaceWebService_Exception $se) {
         throw $se;
     } catch (Exception $t) {
         throw new MarketplaceWebService_Exception(array('Exception' => $t, 'Message' => $t->getMessage()));
     }
     // log to db - parsed request
     // $success = 'Success';
     // $this->dblogger->updateLog( array(
     //     'result'    => json_encode( $response['ResponseBody'] ),
     //     'success'   => $success
     // ));
     return array('ResponseBody' => $response['ResponseBody'], 'ResponseHeaderMetadata' => $response['ResponseHeaderMetadata']);
 }