Example #1
0
 public function testMockRates()
 {
     $rateAdapter = new Rate(['prod' => false, 'key' => 'XXX', 'password' => 'XXX', 'accountNumber' => 'XXX', 'meterNumber' => 'XXX', 'dropOffType' => 'BUSINESS_SERVICE_CENTER', 'shipment' => $this->shipment, 'approvedCodes' => $this->approvedCodes, 'requestAdapter' => new StubFedex()]);
     $rates = $rateAdapter->getRates();
     $ground = new Quote('fedex', 'GROUND_HOME_DELIVERY', 'Ground Home Delivery', 1655);
     $ground->setTransitTime('THREE_DAYS');
     $express = new Quote('fedex', 'FEDEX_EXPRESS_SAVER', 'Fedex Express Saver', 2989);
     $express->setDeliveryEstimate(new DateTime('2014-09-30T20:00:00'));
     $secondDay = new Quote('fedex', 'FEDEX_2_DAY', 'Fedex 2 Day', 4072);
     $secondDay->setDeliveryEstimate(new DateTime('2014-09-29T20:00:00'));
     $overnight = new Quote('fedex', 'STANDARD_OVERNIGHT', 'Standard Overnight', 7834);
     $overnight->setDeliveryEstimate(new DateTime('2014-09-26T20:00:00'));
     $expected = [$ground, $express, $secondDay, $overnight];
     $this->assertEquals($expected, $rates);
 }
Example #2
0
 public function testDisplayOptions()
 {
     $rates = [];
     $usps = new USPS\Rate($this->getUSPSOptions());
     $rates['usps'] = $usps->getRates();
     $ups = new UPS\Rate($this->getUPSOptions());
     $rates['ups'] = $ups->getRates();
     $fedex = new Fedex\Rate($this->getFedexOptions());
     $rates['fedex'] = $fedex->getRates();
     $ship = Ship::factory($this->shipping_options);
     $rates = $ship->getDisplayRates($rates);
     $post = new Quote('usps', '4', 'Parcel Post', 1001);
     $fedexTwoDay = new Quote('fedex', 'FEDEX_2_DAY', 'Fedex 2 Day', 4072);
     $fedexTwoDay->setDeliveryEstimate(new DateTime('2014-09-29T20:00:00'));
     $overnight = new Quote('fedex', 'STANDARD_OVERNIGHT', 'Standard Overnight', 7834);
     $overnight->setDeliveryEstimate(new DateTime('2014-09-26T20:00:00'));
     $expected = ['Standard Shipping' => [$post], 'Two-Day Shipping' => [$fedexTwoDay], 'One-Day Shipping' => [$overnight]];
     $this->assertEquals($expected, $rates);
 }
Example #3
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 #4
0
 public function testCreate()
 {
     $quote = new Quote();
     $quote->setCode('-code-');
     $quote->setName('Test Name');
     $quote->setCost(500);
     $quote->setTransitTime('-transit-time-');
     $quote->setDeliveryEstimate(new DateTime());
     $quote->setCarrier('-carrier-');
     $this->assertEquals('-code-', $quote->getCode());
     $this->assertEquals('Test Name', $quote->getName());
     $this->assertEquals(500, $quote->getCost());
     $this->assertEquals('-transit-time-', $quote->getTransitTime());
     $this->assertTrue($quote->getDeliveryEstimate() instanceof DateTime);
     $this->assertEquals('-carrier-', $quote->getCarrier());
 }
Example #5
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 #6
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;
 }