示例#1
0
    public function getAllRates()
    {
        $return = new ShippingRateSet();
        $country = isset($this->countries[$this->destCountry]) ? $this->countries[$this->destCountry] : $this->countries['CA'];
        $xml = '<?xml version="1.0" ?>
		<eparcel>
			<language>en</language>
			<ratesAndServicesRequest>
				<merchantCPCID> ' . $this->getConfigValue('merchantID') . ' </merchantCPCID>
				<fromPostalCode> ' . htmlspecialchars($this->sourceZip) . ' </fromPostalCode>
				<turnAroundTime>24</turnAroundTime>
				<lineItems>
					<item>
						<quantity> 1 </quantity>
						<weight> ' . $this->weight . ' </weight>
						<length> 1 </length>
						<width> 1 </width>
						<height> 1 </height>
						<description> LiveCart shipment </description>
						<readyToShip />
					</item>
				</lineItems>
				<provOrState> ' . htmlspecialchars($this->destState) . ' </provOrState>
				<country> ' . htmlspecialchars($this->destCountry) . ' </country>
				<postalCode> ' . htmlspecialchars($this->destZip) . ' </postalCode>
			</ratesAndServicesRequest>
		</eparcel>';
        $result = $this->httpPost('sellonline.canadapost.ca', '/', 'XMLRequest=' . urlencode($xml));
        $xml = simplexml_load_string($result);
        if ($xml) {
            if (isset($xml->ratesAndServicesResponse->product)) {
                foreach ($xml->ratesAndServicesResponse->product as $rate) {
                    $r = new ShippingRateResult();
                    $r->setServiceName($rate->name . ' (' . $rate->deliveryDate . ')');
                    $r->setCost((string) $rate->rate, 'CAD');
                    $r->setClassName(get_class($this));
                    $r->setProviderName($this->getProviderName());
                    $r->setRawResponse($result);
                    $return->add($r);
                }
            } else {
                $return = new ShippingRateError(isset($xml->error->statusMessage) ? $xml->error->statusMessage : '');
            }
        }
        $return->setRawResponse($result);
        return $return;
    }
示例#2
0
 public function getRates()
 {
     include_once dirname(__FILE__) . '/../library/usps/usps.php';
     // Priority mail only supports flat-rate or unspecified containers
     if ('Priority' == $this->service && strpos(strtolower($this->container), 'flat') === false) {
         $this->container = '';
     }
     $usps = new USPSHandler();
     $usps->setServer($this->getConfigValue('server', 'http://production.shippingapis.com/ShippingAPI.dll'));
     $usps->setUserName($this->getConfigValue('userId'));
     $usps->setOrigZip($this->sourceZip);
     $usps->setDestZip($this->destZip);
     $country = isset($this->countries[$this->destCountry]) ? $this->countries[$this->destCountry] : 'USA';
     $usps->setCountry($country);
     // get weight in pounds/ounces
     $weight = $this->weight * 1000;
     $pounds = floor($weight / 453.59237);
     $ounces = ceil($weight % 453.59237 / 28.3495231);
     $usps->setWeight($pounds, $ounces);
     $usps->setMachinable($this->getConfigValue('isMachinable') ? 'TRUE' : 'FALSE');
     $usps->setService($this->service);
     $usps->setSize($this->getConfigValue('size', 'Regular'));
     if (!empty($this->container)) {
         $usps->setContainer($this->container);
     }
     $price = $usps->getPrice();
     // success
     if (isset($price->list)) {
         $result = new ShippingRateSet();
         foreach ($price->list as $rate) {
             $r = new ShippingRateResult();
             $type = $rate->svcdescription;
             $type = str_replace(array('&lt', ';sup', '&gt;', '&amp;', 'amp;', 'reg;', ';/sup', 'trade;'), '', $type);
             $type = str_replace('**', '', $type);
             $r->setServiceName(isset($rate->mailservice) ? $rate->mailservice : $type . ' (' . $rate->svccommitments . ')');
             $r->setCost($rate->rate, 'USD');
             $r->setClassName(get_class($this));
             $r->setProviderName($this->getProviderName());
             $result->add($r);
         }
     } else {
         $errorMsg = isset($price->error) ? $price->error->description : '';
         $result = new ShippingRateError($errorMsg);
     }
     $result->setRawResponse($price);
     return $result;
 }
示例#3
0
 private function getRatesByType(Fedex $fedex, $type)
 {
     $fedex->setCarrierCode($type);
     $enabledServices = $this->getConfigValue('enabledServices', null);
     $price = $fedex->getPrice();
     if (isset($price['FDXRATEAVAILABLESERVICESREPLY'][0]['ENTRY'])) {
         $rates = $price['FDXRATEAVAILABLESERVICESREPLY'][0]['ENTRY'];
         $result = new ShippingRateSet();
         foreach ($rates as $price) {
             $r = new ShippingRateResult();
             $code = $price['SERVICE'][0]['VALUE'];
             if (!is_array($enabledServices) || isset($enabledServices[$code])) {
                 $name = self::$names[$code];
                 if (isset($price['DELIVERYDATE'][0]['VALUE'])) {
                     $date = $price['DELIVERYDATE'][0]['VALUE'];
                     $name = $name . ' (' . $date . ')';
                 }
                 $r->setServiceName($name);
                 $cost = $price['ESTIMATEDCHARGES'][0]['DISCOUNTEDCHARGES'][0]['NETCHARGE'][0]['VALUE'];
                 $currency = isset($price['ESTIMATEDCHARGES'][0]['CURRENCYCODE'][0]['VALUE']) ? $price['ESTIMATEDCHARGES'][0]['CURRENCYCODE'][0]['VALUE'] : 'USD';
                 $r->setCost($cost, $currency);
                 $r->setClassName(get_class($this));
                 $r->setProviderName($this->getProviderName());
                 $result->add($r);
             }
         }
     } else {
         $price = $price['FDXRATEAVAILABLESERVICESREPLY'][0];
         $msg = isset($price['ERROR']) ? $price['ERROR'] : (isset($price['SOFTERROR']) ? $price['SOFTERROR'][0]['MESSAGE'] : '');
         $result = new ShippingRateError($msg);
     }
     $result->setRawResponse($price);
     return $result;
 }