Exemplo n.º 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);
 }
Exemplo n.º 2
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());
 }
Exemplo n.º 3
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;
 }