Example #1
0
 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;
 }
Example #2
0
 protected function process()
 {
     try {
         $dom = new DOMDocument('1.0', 'UTF-8');
         $dom->loadXml($this->response);
         $postage_list = @$dom->getElementsByTagName('Postage');
         if (empty($postage_list)) {
             throw new Exception('Unable to get USPS Rates.');
         }
     } catch (Exception $e) {
         throw $e;
     }
     /** @var Quote[] $rates */
     $rates = [];
     foreach ($postage_list as $postage) {
         $code = @$postage->getAttribute('CLASSID');
         $cost = @$postage->getElementsByTagName('Rate')->item(0)->nodeValue;
         $deliveryEstimate = @$postage->getElementsByTagName('CommitmentDate')->item(0)->nodeValue;
         $transitTime = @$postage->getElementsByTagName('CommitmentName')->item(0)->nodeValue;
         //$name = @$postage->getElementsByTagName('MailService')->item(0)->nodeValue;
         $name = Arr::get($this->shipping_codes['domestic'], $code);
         if (!empty($this->approvedCodes) && !in_array($code, $this->approvedCodes)) {
             continue;
         }
         if (array_key_exists($code, $rates)) {
             $cost = $rates[$code]->getCost() + $cost * 100;
         } else {
             $cost = $cost * 100;
         }
         $quote = new Quote();
         $quote->setCarrier('usps')->setCode($code)->setName(html_entity_decode($name))->setCost((int) $cost);
         if (!empty($deliveryEstimate)) {
             $deliveryEstimateDT = new \DateTime($deliveryEstimate);
             $transitTime = $deliveryEstimateDT->diff(new \DateTime(date('Y-m-d')));
             $quote->setTransitTime($transitTime->d);
             $quote->setDeliveryEstimate($deliveryEstimateDT);
         }
         $rates[$quote->getCode()] = $quote;
     }
     $this->rates = array_values($rates);
     return $this;
 }
Example #3
0
 public function __construct($options = [])
 {
     $this->rates = [];
     $this->isProduction = (bool) Arr::get($options, 'prod', false);
     $this->shipment = Arr::get($options, 'shipment');
 }
Example #4
0
 protected function process()
 {
     try {
         $dom = new DOMDocument('1.0', 'UTF-8');
         $dom->loadXml($this->response);
         $rate_list = $dom->getElementsByTagName('RatedShipment');
         if (empty($rate_list->length)) {
             throw new Exception('Unable to get UPS Rates.');
         }
     } catch (Exception $e) {
         echo $this->response;
         throw $e;
     }
     foreach ($rate_list as $rate) {
         $code = @$rate->getElementsByTagName('Service')->item(0)->getElementsByTagName('Code')->item(0)->nodeValue;
         $name = Arr::get($this->shippingCodes['US'], $code);
         $cost = @$rate->getElementsByTagName('TotalCharges')->item(0)->getElementsByTagName('MonetaryValue')->item(0)->nodeValue;
         if (!empty($this->approvedCodes) && !in_array($code, $this->approvedCodes)) {
             continue;
         }
         $quote = new Quote();
         $quote->setCarrier('ups')->setCode($code)->setName($name)->setCost($cost * 100);
         $this->rates[] = $quote;
     }
     return $this;
 }