Example #1
0
 /**
  * Do shipment request to carrier web service, obtain Print Shipping Labels and process errors in response
  *
  * @param Varien_Object $request
  * @return Varien_Object
  */
 protected function _doShipmentRequest(Varien_Object $request)
 {
     $this->_prepareShipmentRequest($request);
     $result = new Varien_Object();
     $xmlRequest = $this->_formShipmentRequest($request);
     $xmlResponse = $this->_getCachedQuotes($xmlRequest);
     if ($xmlResponse === null) {
         $url = $this->getConfigData('url');
         if (!$url) {
             $url = $this->_defaultUrls['ShipConfirm'];
         }
         $debugData = array('request' => $xmlRequest);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (bool) $this->getConfigFlag('mode_xml'));
         $xmlResponse = curl_exec($ch);
         if ($xmlResponse === false) {
             throw new Exception(curl_error($ch));
         } else {
             $debugData['result'] = $xmlResponse;
             $this->_setCachedQuotes($xmlRequest, $xmlResponse);
         }
     }
     try {
         $response = new SimpleXMLElement($xmlResponse);
     } catch (Exception $e) {
         $debugData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
         $result->setErrors($e->getMessage());
     }
     if (isset($response->Response->Error) && in_array($response->Response->Error->ErrorSeverity, array('Hard', 'Transient'))) {
         $result->setErrors((string) $response->Response->Error->ErrorDescription);
     }
     $this->_debug($debugData);
     if ($result->hasErrors() || empty($response)) {
         return $result;
     } else {
         return $this->_sendShipmentAcceptRequest($response);
     }
 }