/** * 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(); $service = $this->getCode('service_to_code', $request->getShippingMethod()); $recipientUSCountry = $this->_isUSCountry($request->getRecipientAddressCountryCode()); if ($recipientUSCountry && $service == 'Priority Express') { $requestXml = $this->_formUsExpressShipmentRequest($request); $api = 'ExpressMailLabel'; } else { if ($recipientUSCountry) { $requestXml = $this->_formUsSignatureConfirmationShipmentRequest($request, $service); if ($this->getConfigData('mode')) { $api = 'SignatureConfirmationV3'; } else { $api = 'SignatureConfirmationCertifyV3'; } } else { if ($service == 'First Class') { $requestXml = $this->_formIntlShipmentRequest($request); $api = 'FirstClassMailIntl'; } else { if ($service == 'Priority') { $requestXml = $this->_formIntlShipmentRequest($request); $api = 'PriorityMailIntl'; } else { $requestXml = $this->_formIntlShipmentRequest($request); $api = 'ExpressMailIntl'; } } } } $debugData = array('request' => $requestXml); $url = $this->getConfigData('gateway_secure_url'); if (!$url) { $url = $this->_defaultGatewayUrl; } $client = new Zend_Http_Client(); $client->setUri($url); $client->setConfig(array('maxredirects' => 0, 'timeout' => 30)); $client->setParameterGet('API', $api); $client->setParameterGet('XML', $requestXml); $response = $client->request()->getBody(); $response = simplexml_load_string($response); if ($response === false || $response->getName() == 'Error') { $debugData['result'] = array('error' => $response->Description, 'code' => $response->Number, 'xml' => $response->asXML()); $this->_debug($debugData); $result->setErrors($debugData['result']['error']); } else { if ($recipientUSCountry && $service == 'Priority Express') { $labelContent = base64_decode((string) $response->EMLabel); $trackingNumber = (string) $response->EMConfirmationNumber; } else { if ($recipientUSCountry) { $labelContent = base64_decode((string) $response->SignatureConfirmationLabel); $trackingNumber = (string) $response->SignatureConfirmationNumber; } else { $labelContent = base64_decode((string) $response->LabelImage); $trackingNumber = (string) $response->BarcodeNumber; } } $result->setShippingLabelContent($labelContent); $result->setTrackingNumber($trackingNumber); } $result->setGatewayResponse($response); $debugData['result'] = $response; $this->_debug($debugData); return $result; }
/** * 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(); $client = $this->_createShipSoapClient(); $requestClient = $this->_formShipmentRequest($request); $response = $client->processShipment($requestClient); if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') { $shippingLabelContent = $response->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image; $trackingNumber = $response->CompletedShipmentDetail->CompletedPackageDetails->TrackingIds->TrackingNumber; $result->setShippingLabelContent($shippingLabelContent); $result->setTrackingNumber($trackingNumber); $debugData = array('request' => $client->__getLastRequest(), 'result' => $client->__getLastResponse()); $this->_debug($debugData); } else { $debugData = array('request' => $client->__getLastRequest(), 'result' => array('error' => '', 'code' => '', 'xml' => $client->__getLastResponse())); if (is_array($response->Notifications)) { foreach ($response->Notifications as $notification) { $debugData['result']['code'] .= $notification->Code . '; '; $debugData['result']['error'] .= $notification->Message . '; '; } } else { $debugData['result']['code'] = $response->Notifications->Code . ' '; $debugData['result']['error'] = $response->Notifications->Message . ' '; } $this->_debug($debugData); $result->setErrors($debugData['result']['error']); } $result->setGatewayResponse($client->__getLastResponse()); return $result; }
/** * 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(); try { $client = $this->_createLabelSoapClient(); $requestShip = $this->_formShipmentRequest($request); $response = $client->GetPostageLabel($requestShip); $debugData['request_sent'] = $requestShip; //response includes string of PDF label - too big to log $debugString = "Status: " . $response->LabelRequestResponse->Status; if (isset($response->LabelRequestResponse->TrackingNumber)) { $debugString .= ' Tracking ID: ' . $response->LabelRequestResponse->TrackingNumber . ' Final Postage: ' . $response->LabelRequestResponse->FinalPostage; } $debugData['response'] = $debugString; } catch (Exception $e) { $debugData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode()); Mage::logException($e); $result->setErrors((string) 'an issue: ' . $e->getMessage()); } if (is_object($response)) { if ($response->LabelRequestResponse->Status != 0) { $result->setErrors((string) $response->LabelRequestResponse->ErrorMessage); $debugData['response'] = $response->LabelRequestResponse->ErrorMessage; } else { $result->setShippingLabelContent(base64_decode($response->LabelRequestResponse->Base64LabelImage)); $result->setTrackingNumber($response->LabelRequestResponse->TrackingNumber); $this->_recordCostToOrder($request->getOrderShipment()->getOrder(), $response->LabelRequestResponse->FinalPostage); } } $result->setGatewayResponse($client->__getLastResponse()); if ($this->_debug) { Mage::helper('wsalogger/log')->postInfo('endicia', 'Request XML', $client->__getLastRequest()); Mage::helper('wsalogger/log')->postInfo('endicia', 'Response', $debugData); } return $result; }