_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([ 'errorCode' => $serviceResponse->getCode(), 'errorText' => $this->getServiceName() . ': ' . $serviceResponse->getMessage(), ]); } } catch (App_Service_Shipping_FedEx_Exception $e) { $this->_response->setIsSuccess(false)->setData([ 'errorCode' => $e->getCode(), 'errorText' => $e->getMessage(), ] ); } } else { $this->_response->setIsSuccess(false)->setData([ 'errorCode' => self::ERROR_VALIDATE_REQUIRED_PARAMS, 'errorText' => implode('
', $errors), ]); } } return $this->_response; } protected function _prepareRateRequest() { $packageLineItems = $this->_getPackageLineItems(); $this->_rateRequest = [ 'WebAuthenticationDetail' => [ 'UserCredential' => [ 'Key' => $this->getConfig()->userCredentialKey, 'Password' => $this->getConfig()->userCredentialPassword, ], ], 'ClientDetail' => [ 'AccountNumber' => $this->getConfig()->shippingAccountNumber, 'MeterNumber' => $this->getConfig()->meterNumber, ], 'Version' => $this->getConfig()->versionInfo->toArray(), 'RequestedShipment' => [ 'DropoffType' => $this->getConfig()->dropoffType, 'ShipTimestamp' => date('c'), 'Shipper' => [ 'Contact' => [ 'PersonName' => $this->getOption('shipperPersonName'), 'CompanyName' => $this->getOption('shipperCompanyName'), 'PhoneNumber' => $this->getOption('shipperPhoneNumber'), ], 'Address' => [ 'StreetLines' => $this->getOption('shipperStreetLines'), 'City' => $this->getOption('shipperCity'), 'StateOrProvinceCode' => $this->getOption('shipperState'), 'PostalCode' => $this->getOption('shipperPostalCode'), 'CountryCode' => $this->getOption('shipperCountry'), ], ], 'Recipient' => [ 'Contact' => [ 'PersonName' => $this->getOption('shipToStreetLines'), 'CompanyName' => $this->getOption('shipToCompanyName'), 'PhoneNumber' => $this->getOption('shipToPhoneNumber'), ], 'Address' => [ 'PostalCode' => $this->getOption('shipToPostalCode'), 'CountryCode' => $this->getOption('shipToCountry'), 'StateOrProvinceCode' => $this->getOption('shipToState'), 'Residential' => ($this->getOption('addressType') == self::ADDRESS_TYPE_RESIDENTIAL), ], ], 'ShippingChargesPayment' => [ 'PaymentType' => $this->getConfig()->payorType, 'Payor' => [ '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'] = [ 'Amount' => $totalInsuredValueAmount, 'Currency' => $this->getConfig()->totalInsuredValueCurrency, ]; } return $this; } protected function _getPackageLineItems() { $packageItems = []; foreach ($this->_getPackagesInformation() as $key => $packageInformation) { $packageItems[] = [ 'SequenceNumber' => $key + 1, 'GroupPackageCount' => 1, 'Weight' => [ '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, ['trace' => $trace]); $client->__setLocation($this->_serviceLocation); return $client; } /** * Create rate soap client * * @return SoapClient */ protected function _createRateSoapClient() { return $this->_createSoapClient($this->_rateServiceWsdl); } }