_serviceLocation = ($this->getConfig()->testMode) ? $this->getConfig()->locationTest : $this->getConfig()->location; $this->_rateServiceWsdl = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, get_class($this)) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'RateService_v13.wsdl'; return $this; } public function getRate() { return $this->_getServiceResponse(); } protected function _getServiceResponse() { if (null == $this->_response->getData()) { if (true === ($errors = $this->_validateRequiredRateFields())) { try { $this->_prepareRateRequest(); if (!($serviceResponse = $this->_callService()) instanceof Qs_Exception) { $this->_response->prepareServiceResponse($serviceResponse); } else { $this->_response->setIsSuccess(false)->setData(array( 'errorCode' => $serviceResponse->getCode(), 'errorText' => $this->getServiceName() . ': ' . $serviceResponse->getMessage() )); } } catch (App_Service_Shipping_FedEx_Exception $e) { $this->_response->setIsSuccess(false)->setData(array( 'errorCode' => $e->getCode(), 'errorText' => $e->getMessage() ) ); } } else { $this->_response->setIsSuccess(false)->setData(array( 'errorCode' => self::ERROR_VALIDATE_REQUIRED_PARAMS, 'errorText' => implode('
', $errors) )); } } return $this->_response; } protected function _prepareRateRequest() { $packageLineItems = $this->_getPackageLineItems(); $this->_rateRequest = array( 'WebAuthenticationDetail' => array( 'UserCredential' => array( 'Key' => $this->getConfig()->userCredentialKey, 'Password' => $this->getConfig()->userCredentialPassword ) ), 'ClientDetail' => array( 'AccountNumber' => $this->getConfig()->shippingAccountNumber, 'MeterNumber' => $this->getConfig()->meterNumber ), 'Version' => $this->getConfig()->versionInfo->toArray(), 'RequestedShipment' => array( 'DropoffType' => $this->getConfig()->dropoffType, 'ShipTimestamp' => date('c'), 'Shipper' => array( 'Contact' => array( 'PersonName' => $this->getOption('shipperPersonName'), 'CompanyName' => $this->getOption('shipperCompanyName'), 'PhoneNumber' => $this->getOption('shipperPhoneNumber'), ), 'Address' => array( 'StreetLines' => $this->getOption('shipperStreetLines'), 'City' => $this->getOption('shipperCity'), 'StateOrProvinceCode' => $this->getOption('shipperState'), 'PostalCode' => $this->getOption('shipperPostalCode'), 'CountryCode' => $this->getOption('shipperCountry') ) ), 'Recipient' => array( 'Contact' => array( 'PersonName' => $this->getOption('shipToStreetLines'), 'CompanyName' => $this->getOption('shipToCompanyName'), 'PhoneNumber' => $this->getOption('shipToPhoneNumber'), ), 'Address' => array( 'PostalCode' => $this->getOption('shipToPostalCode'), 'CountryCode' => $this->getOption('shipToCountry'), 'StateOrProvinceCode' => $this->getOption('shipToState'), 'Residential' => ($this->getOption('addressType') == self::ADDRESS_TYPE_RESIDENTIAL) ) ), 'ShippingChargesPayment' => array( 'PaymentType' => $this->getConfig()->payorType, 'Payor' => array( 'AccountNumber' => $this->getConfig()->billingAccountNumber, 'CountryCode' => $this->getOption('shipperCountry') ) ), 'RateRequestTypes' => $this->getConfig()->rateRequestTypes, 'PackageCount' => sizeof($packageLineItems), 'PackageDetail' => $this->getConfig()->packageDetail, 'PackagingType' => $this->getConfig()->packagingType, 'ServiceType' => $this->getOption('serviceCode'), 'RequestedPackageLineItems' => $packageLineItems ) ); if (false !== ($totalInsuredValueAmount = $this->getOption('totalInsuredValueAmount'))) { $this->_rateRequest['RequestedShipment']['TotalInsuredValue'] = array( 'Amount' => $totalInsuredValueAmount, 'Currency' => $this->getConfig()->totalInsuredValueCurrency, ); } return $this; } protected function _getPackageLineItems() { $packageItems = array(); foreach ($this->_getPackagesInformation() as $key => $packageInformation) { $packageItems[] = array( 'SequenceNumber' => $key + 1, 'GroupPackageCount' => 1, 'Weight' => array( 'Value' => $this->_prepareWeight($packageInformation['weight']), 'Units' => $this->getConfig()->weightUnits ) ); } return $packageItems; } protected function _callService() { try { ini_set("soap.wsdl_cache_enabled", "0"); /** @var App_Service_Shipping_FedEx_SoapClient $client */ $client = $this->_createRateSoapClient(); try { $response = $client->getRates($this->_rateRequest); } catch (Qs_Exception $e) { return $e; } } catch (App_Service_Shipping_FedEx_Exception $e) { return $e; } return $response; } /** * Create soap client with selected wsdl * * @param string $wsdl * @param bool|int $trace * @return SoapClient */ protected function _createSoapClient($wsdl, $trace = false) { $client = new SoapClient($wsdl, array('trace' => $trace)); $client->__setLocation($this->_serviceLocation); return $client; } /** * Create rate soap client * * @return SoapClient */ protected function _createRateSoapClient() { return $this->_createSoapClient($this->_rateServiceWsdl); } }