'Europe First International Priority', 'FEDEX_1_DAY_FREIGHT' => 'Fedex 1 Day Freight', 'FEDEX_2_DAY' => 'Fedex 2 Day', 'FEDEX_2_DAY_AM' => 'Fedex 2 Day AM', 'FEDEX_2_DAY_FREIGHT' => 'Fedex 2 Day Freight', 'FEDEX_3_DAY_FREIGHT' => 'Fedex 3 Day Freight', 'FEDEX_EXPRESS_SAVER' => 'Fedex Express Saver', 'FEDEX_FIRST_FREIGHT' => 'Fedex First Freight', 'FEDEX_FREIGHT_ECONOMY' => 'Fedex Freight Economy', 'FEDEX_FREIGHT_PRIORITY' => 'Fedex Freight Priority', 'FEDEX_GROUND' => 'Fedex Ground', 'FIRST_OVERNIGHT' => 'First Overnight', 'GROUND_HOME_DELIVERY' => 'Ground Home Delivery', 'INTERNATIONAL_ECONOMY' => 'International Economy', 'INTERNATIONAL_ECONOMY_FREIGHT' => 'International Economy Freight', 'INTERNATIONAL_FIRST' => 'International First', 'INTERNATIONAL_PRIORITY' => 'International Priority', 'INTERNATIONAL_PRIORITY_FREIGHT' => 'International Priority Freight', 'PRIORITY_OVERNIGHT' => 'Priority Overnight', 'SMART_POST' => 'Smart Post', 'STANDARD_OVERNIGHT' => 'Standard Overnight', ]; public function __construct($options = []) { parent::__construct($options); $this->key = Arr::get($options, 'key'); $this->password = Arr::get($options, 'password'); $this->accountNumber = Arr::get($options, 'accountNumber'); $this->meterNumber = Arr::get($options, 'meterNumber'); $this->approvedCodes = Arr::get($options, 'approvedCodes'); $this->dropOffType = Arr::get($options, 'dropOffType'); $this->setRequestAdapter(Arr::get($options, 'requestAdapter', new RateRequest\Post())); } protected function prepare() { $date = time(); $day_name = date('l', $date); if ($day_name == 'Saturday') { $date += 172800; } elseif ($day_name == 'Sunday') { $date += 86400; } // http://www.fedex.com/templates/components/apps/wpor/secure/downloads/pdf/Aug13/PropDevGuide.pdf // http://www.fedex.com/us/developer/product/WebServices/MyWebHelp_August2010/Content/ // Proprietary_Developer_Guide/Rate_Services_conditionalized.htm $packages = ''; $sequence_number = 0; foreach ($this->shipment->getPackages() as $package) { $sequence_number++; $packages .= '' . '' . $sequence_number . '' . '1' . '' . 'LB' . '' . $package->getWeight() . '' . '' . '' . '' . $package->getLength() . '' . '' . $package->getWidth() . '' . '' . $package->getHeight() . '' . 'IN' . '' . ''; } $this->data = '' . '' . '' . '' . '' . '' . '' . $this->key . '' . '' . $this->password . '' . '' . '' . '' . '' . $this->accountNumber . '' . '' . $this->meterNumber . '' . '' . '' . 'crs' . '13' . '0' . '0' . '' . 'true' . '' . '' . date('c') . '' . '' . $this->dropOffType . '' . 'YOUR_PACKAGING' . '' . '
' . '' . $this->shipment->getFromPostalCode() . '' . '' . $this->shipment->getFromCountryCode() . '' . ( $this->shipment->getFromIsResidential() ? '1' : '' ) . '
' . '
' . '' . '
' . '' . $this->shipment->getToPostalCode() . '' . '' . $this->shipment->getToCountryCode() . '' . ( $this->shipment->getToIsResidential() ? '1' : '' ) . '
' . '
' . 'LIST' . '' . $this->shipment->packageCount() . '' . $packages . '
' . '
' . '
' . '
'; return $this; } protected function execute() { if ($this->isProduction) { $url = $this->urlProd; } else { $url = $this->urlDev; } $this->response = $this->rateRequest->execute($url, $this->data); return $this; } protected function process() { try { $dom = new DOMDocument('1.0', 'UTF-8'); $dom->loadXml($this->response); $rate_reply = $dom->getElementsByTagName('RateReplyDetails'); if (empty($rate_reply->length)) { throw new Exception('Unable to get FedEx Rates.'); } } catch (Exception $e) { // StatsD::increment('error.shipping.get_fedex_rate'); // Kohana::$log->add(Log::ERROR, $e)->write(); throw $e; } foreach ($rate_reply as $rate) { $code = $rate->getElementsByTagName('ServiceType')->item(0)->nodeValue; if (! empty($this->approvedCodes) && ! in_array($code, $this->approvedCodes)) { continue; } $name = Arr::get($this->shippingCodes, $code); $delivery_ts = @$rate->getElementsByTagName('DeliveryTimestamp')->item(0)->nodeValue; $transit_time = @$rate->getElementsByTagName('TransitTime')->item(0)->nodeValue; $cost = $rate ->getElementsByTagName('RatedShipmentDetails')->item(0) ->getElementsByTagName('ShipmentRateDetail')->item(0) ->getElementsByTagName('TotalNetCharge')->item(0) ->getElementsByTagName('Amount')->item(0)->nodeValue; $quote = new Quote; $quote ->setCarrier('fedex') ->setCode($code) ->setName($name) ->setCost((int) ($cost * 100)) ->setTransitTime($transit_time); if ($delivery_ts) { $quote->setDeliveryEstimate(new DateTime($delivery_ts)); } $this->rates[] = $quote; } return $this; } }