Ejemplo n.º 1
0
 public function track($trackingNumber)
 {
     if (!isset($trackingNumber)) {
         return false;
     }
     //The WSDL is not included with the sample code.
     //Please include and reference in $path_to_wsdl variable.
     $path_to_wsdl = __DIR__ . DIRECTORY_SEPARATOR . 'TrackService_v9.wsdl';
     ini_set("soap.wsdl_cache_enabled", "0");
     $client = new \SoapClient($path_to_wsdl, array('trace' => 1));
     // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $this->authKey, 'Password' => $this->authPassword));
     $request['ClientDetail'] = array('AccountNumber' => $this->authAccountNumber, 'MeterNumber' => $this->authMeterNumber);
     $request['TransactionDetail'] = array('CustomerTransactionId' => '*** Track Request using PHP ***');
     $request['Version'] = array('ServiceId' => 'trck', 'Major' => '9', 'Intermediate' => '1', 'Minor' => '0');
     $request['SelectionDetails'] = array('PackageIdentifier' => array('Type' => 'TRACKING_NUMBER_OR_DOORTAG', 'Value' => $trackingNumber));
     try {
         if ($this->setEndpoint('changeEndpoint')) {
             $newLocation = $client->__setLocation(setEndpoint('endpoint'));
         }
         $response = $client->track($request);
         $this->responseToArray($response);
         return $response;
     } catch (SoapFault $exception) {
         $this->printFault($exception, $client);
     }
 }
Ejemplo n.º 2
0
 function quote($data, $config)
 {
     if ($config["test_mode"] == 'true') {
         $wsdl = PATH_THIRD . "brilliant_retail/core/shipping/assets/fedex/wsdl/RateService_v13_test.wsdl";
     } else {
         $wsdl = PATH_THIRD . "brilliant_retail/core/shipping/assets/fedex/wsdl/RateService_v13.wsdl";
     }
     $client = new SoapClient($wsdl, array('trace' => 1));
     // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
     // Need at least 1 for the weight
     if ($data["weight"] < 1) {
         $data["weight"] = 1;
     }
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $config["fedex_key"], 'Password' => $config["fedex_password"]));
     $request['ClientDetail'] = array('AccountNumber' => $config["fedex_account"], 'MeterNumber' => $config["fedex_meter"]);
     $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v13 using BrilliantRetail ***');
     $request['Version'] = array('ServiceId' => 'crs', 'Major' => '13', 'Intermediate' => '0', 'Minor' => '0');
     $request['ReturnTransitAndCommit'] = true;
     $request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP';
     $request['RequestedShipment']['ShipTimestamp'] = date('c');
     $request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING';
     $request['RequestedShipment']['TotalInsuredValue'] = array('Ammount' => $data["total"], 'Currency' => 'USD');
     // Shipper Info
     $request['RequestedShipment']['Shipper'] = array('Contact' => array('PersonName' => '', 'CompanyName' => '', 'PhoneNumber' => ''), 'Address' => array('StreetLines' => array(''), 'City' => '', 'StateOrProvinceCode' => $config["from_state"], 'PostalCode' => $config["from_zip"], 'CountryCode' => $config["from_country"]));
     // Recipient Info
     $request['RequestedShipment']['Recipient'] = array('Contact' => array('PersonName' => '', 'CompanyName' => '', 'PhoneNumber' => ''), 'Address' => array('StreetLines' => array(), 'City' => '', 'StateOrProvinceCode' => substr($data["to_state"], 0, 2), 'PostalCode' => $data["to_zip"], 'CountryCode' => $data["to_country"], 'Residential' => true));
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     $request['RequestedShipment']['PackageCount'] = '1';
     $request['RequestedShipment']['RequestedPackageLineItems'] = $packageLineItem = array('SequenceNumber' => 1, 'GroupPackageCount' => 1, 'Weight' => array('Value' => $data["weight"], 'Units' => strtoupper($config["weight_unit"])), 'Dimensions' => array('Length' => (int) $config["size_length"], 'Width' => (int) $config["size_width"], 'Height' => (int) $config["size_height"], 'Units' => 'IN'));
     $code = unserialize($config["code"]);
     $this->rates = array();
     foreach ($code as $c) {
         $request['RequestedShipment']['ServiceType'] = $c;
         try {
             if (setEndpoint('changeEndpoint')) {
                 $newLocation = $client->__setLocation(setEndpoint('endpoint'));
             }
             $response = $client->getRates($request);
             if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
                 $rateReply = $response->RateReplyDetails;
                 $this->rates[$c] = array('code' => $c, 'rate' => number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2), 'label' => ucwords(strtolower(str_replace("_", " ", $rateReply->ServiceType))));
             }
         } catch (SoapFault $exception) {
             printFault($exception, $client);
         }
     }
     if (count($this->rates) > 1) {
         usort($this->rates, array($this, '_rate_sort'));
     }
     return $this->rates;
 }
Ejemplo n.º 3
0
	'Minor' => '0'
);
$request['SelectionDetails'] = array(
	'PackageIdentifier' => array(
		
		'Type' => 'CUSTOMER_REFERENCE',
		'Value' => getProperty('customerreference') // Replace with a valid customer reference
	),
	'ShipmentAccountNumber' => getProperty('trackaccount') // Replace with account used for shipment
);



try {
	if(setEndpoint('changeEndpoint')){
		$newLocation = $client->__setLocation(setEndpoint('endpoint'));
	}
	
	$response = $client ->track($request);

    if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR'){
		if($response->HighestSeverity != 'SUCCESS'){
			echo '<table border="1">';
			echo '<tr><th>Track Reply</th><th>&nbsp;</th></tr>';
			trackDetails($response->Notifications, '');
			echo '</table>';
		}else{
	    	if ($response->CompletedTrackDetails->HighestSeverity != 'SUCCESS'){
				echo '<table border="1">';
			    echo '<tr><th>Shipment Level Tracking Details</th><th>&nbsp;</th></tr>';
			    trackDetails($response->CompletedTrackDetails, '');
Ejemplo n.º 4
0
 private function _processRequest($address, $products)
 {
     require_once DIR_EXT . 'default_fedex/core/lib/fedex_func.php';
     if ($this->config->get('default_fedex_test')) {
         $path_to_wsdl = DIR_EXT . 'default_fedex/core/lib/RateService_v9_test.wsdl';
     } else {
         $path_to_wsdl = DIR_EXT . 'default_fedex/core/lib/RateService_v9.wsdl';
     }
     $client = new SoapClient($path_to_wsdl, array('trace' => 1));
     // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
     //Fedex Key
     $fedex_key = $this->config->get('default_fedex_key');
     //Fedex Password
     $fedex_password = $this->config->get('default_fedex_password');
     //Fedex Meter Id
     $fedex_meter_id = $this->config->get('default_fedex_meter');
     //Fedex Account
     $fedex_account = $this->config->get('default_fedex_account');
     //Quote Type Residential or commercial
     $fedex_quote = $this->config->get('default_fedex_quote_type');
     if ($fedex_quote == 'residential') {
         $fedex_residential = true;
     } else {
         $fedex_residential = false;
     }
     $fedex_addr = $this->config->get('default_fedex_address');
     $fedex_city = $this->config->get('default_fedex_city');
     $fedex_state = $this->config->get('default_fedex_state');
     $fedex_zip = $this->config->get('default_fedex_zip');
     $fedex_country = $this->config->get('default_fedex_country');
     $fedex_add_chrg = $this->config->get('default_fedex_add_chrg');
     if (strlen($fedex_state) > 2) {
         $this->messages->saveError('Fedex US error!', 'Fedex US Shipping Extension won\'t work because state code length must be 2 letters. Please check settings form on #admin#rt=extension/extensions/edit&extension=default_fedex');
     }
     if (strlen($fedex_country) != 2) {
         $this->messages->saveError('Fedex US error!', 'Fedex US Shipping Extension won\'t work because country code length must be 2 letters. Please check settings form on #admin#rt=extension/extensions/edit&extension=default_fedex');
     }
     //Recepient Info
     $shipping_address = $address;
     $ground_quote = 0;
     $first_overnight_quote = 0;
     $priority_overnight_quote = 0;
     $standard_overnight_quote = 0;
     $two_day_quote = 0;
     $express_saver_quote = 0;
     //Products info
     if ($products) {
         foreach ($products as $result) {
             $request = array();
             $product_weight = $this->weight->convert($result['weight'], $this->config->get('config_weight_class'), 'lb');
             $product_weight = $product_weight < 0.1 ? 0.1 : $product_weight;
             $product_length = $this->length->convert($result['length'], $this->config->get('config_length_class'), 'in');
             $product_width = $this->length->convert($result['width'], $this->config->get('config_length_class'), 'in');
             $product_height = $this->length->convert($result['height'], $this->config->get('config_length_class'), 'in');
             $product_quantity = $result['quantity'];
             $product_total = $result['total'];
             //BUILD REQUEST START
             $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $fedex_key, 'Password' => $fedex_password));
             $request['ClientDetail'] = array('AccountNumber' => $fedex_account, 'MeterNumber' => $fedex_meter_id);
             $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v9 using PHP ***');
             $request['Version'] = array('ServiceId' => 'crs', 'Major' => '9', 'Intermediate' => '0', 'Minor' => '0');
             $request['ReturnTransitAndCommit'] = true;
             $request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP';
             // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
             $request['RequestedShipment']['ShipTimestamp'] = date('c');
             //$request['RequestedShipment']['ServiceType'] = 'GROUND_HOME_DELIVERY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
             $request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING';
             // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
             $request['RequestedShipment']['TotalInsuredValue'] = array('Ammount' => $product_total, 'Currency' => 'USD');
             $request['RequestedShipment']['Shipper'] = array('Address' => array('StreetLines' => array($fedex_addr), 'City' => $fedex_city, 'StateOrProvinceCode' => $fedex_state, 'PostalCode' => $fedex_zip, 'CountryCode' => $fedex_country));
             $request['RequestedShipment']['Recipient'] = array('Address' => array('StreetLines' => array($shipping_address['address_1'], $shipping_address['address_2']), 'City' => $shipping_address['city'], 'StateOrProvinceCode' => $shipping_address['zone_code'], 'PostalCode' => $shipping_address['postcode'], 'CountryCode' => $shipping_address['iso_code_2'], 'Residential' => $fedex_residential));
             $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => $fedex_account, 'CountryCode' => 'US'));
             $request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
             $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
             $request['RequestedShipment']['PackageCount'] = $product_quantity;
             $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
             //  Or PACKAGE_SUMMARY
             for ($q = 0; $q < $product_quantity; $q++) {
                 $request['RequestedShipment']['RequestedPackageLineItems'] = array('Weight' => array('Value' => $product_weight, 'Units' => 'LB'), 'Dimensions' => array('Length' => $product_length, 'Width' => $product_width, 'Height' => $product_height, 'Units' => 'IN'));
             }
             try {
                 if (setEndpoint('changeEndpoint')) {
                     $newLocation = $client->__setLocation(setEndpoint('endpoint'));
                 }
                 $response = $client->getRates($request);
                 if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
                     if (count($response->RateReplyDetails) > 1) {
                         foreach ($response->RateReplyDetails as $rateReply) {
                             if ($rateReply->ServiceType == 'FEDEX_GROUND' || $rateReply->ServiceType == 'GROUND_HOME_DELIVERY') {
                                 $ground_quote = $ground_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                             } else {
                                 if ($rateReply->ServiceType == 'FIRST_OVERNIGHT') {
                                     $first_overnight_quote = $first_overnight_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                                 } else {
                                     if ($rateReply->ServiceType == 'PRIORITY_OVERNIGHT') {
                                         $priority_overnight_quote = $priority_overnight_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                                     } else {
                                         if ($rateReply->ServiceType == 'STANDARD_OVERNIGHT') {
                                             $standard_overnight_quote = $standard_overnight_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                                         } else {
                                             if ($rateReply->ServiceType == 'FEDEX_2_DAY') {
                                                 $two_day_quote = $two_day_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                                             } else {
                                                 if ($rateReply->ServiceType == 'FEDEX_EXPRESS_SAVER') {
                                                     $express_saver_quote = $express_saver_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         $rateReply = $response->RateReplyDetails;
                         if ($rateReply->ServiceType == 'FEDEX_GROUND' || $rateReply->ServiceType == 'GROUND_HOME_DELIVERY') {
                             $ground_quote = $ground_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                         } else {
                             if ($rateReply->ServiceType == 'FIRST_OVERNIGHT') {
                                 $first_overnight_quote = $first_overnight_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                             } else {
                                 if ($rateReply->ServiceType == 'PRIORITY_OVERNIGHT') {
                                     $priority_overnight_quote = $priority_overnight_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                                 } else {
                                     if ($rateReply->ServiceType == 'STANDARD_OVERNIGHT') {
                                         $standard_overnight_quote = $standard_overnight_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                                     } else {
                                         if ($rateReply->ServiceType == 'FEDEX_2_DAY') {
                                             $two_day_quote = $two_day_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                                         } else {
                                             if ($rateReply->ServiceType == 'FEDEX_EXPRESS_SAVER') {
                                                 $express_saver_quote = $express_saver_quote + $product_quantity * number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     $error_msg = $this->getNotifications($response->Notifications);
                 }
             } catch (SoapFault $exception) {
                 $error_text = 'Fault' . "<br>\n";
                 $error_text .= "Code:" . $exception->faultcode . "\n";
                 $error_text .= "String:" . $exception->faultstring . "\n";
                 $error_text .= $client;
                 $this->message->saveError('fedex extension soap error', $error_text);
                 $this->log->write($error_text);
             }
         }
     }
     if ($first_overnight_quote > 0 && $this->config->get('default_fedex_default_fedex_us_01') > 0) {
         $first_overnight_quote = $first_overnight_quote + $fedex_add_chrg;
         $quote_data['FEDEX_FIRST_OVERNIGHT'] = array('id' => 'default_fedex.' . 'FEDEX_FIRST_OVERNIGHT', 'title' => 'Fedex First Overnight', 'cost' => $this->currency->convert($first_overnight_quote, 'USD', $this->currency->getCode()), 'tax_class_id' => 0, 'text' => $this->currency->format($this->currency->convert($first_overnight_quote, 'USD', $this->currency->getCode())));
     }
     if ($priority_overnight_quote > 0 && $this->config->get('default_fedex_default_fedex_us_02') > 0) {
         $priority_overnight_quote = $priority_overnight_quote + $fedex_add_chrg;
         $quote_data['FEDEX_PRIORITY_OVERNIGHT'] = array('id' => 'default_fedex.' . 'FEDEX_PRIORITY_OVERNIGHT', 'title' => 'Fedex Priority Overnight', 'cost' => $this->currency->convert($priority_overnight_quote, 'USD', $this->currency->getCode()), 'tax_class_id' => 0, 'text' => $this->currency->format($this->currency->convert($priority_overnight_quote, 'USD', $this->currency->getCode())));
     }
     if ($standard_overnight_quote > 0 && $this->config->get('default_fedex_default_fedex_us_03') > 0) {
         $standard_overnight_quote = $standard_overnight_quote + $fedex_add_chrg;
         $quote_data['FEDEX_STANDARD_OVERNIGHT'] = array('id' => 'default_fedex.' . 'FEDEX_STANDARD_OVERNIGHT', 'title' => 'Fedex Standard Overnight', 'cost' => $this->currency->convert($standard_overnight_quote, 'USD', $this->currency->getCode()), 'tax_class_id' => 0, 'text' => $this->currency->format($this->currency->convert($standard_overnight_quote, 'USD', $this->currency->getCode())));
     }
     if ($two_day_quote > 0 && $this->config->get('default_fedex_default_fedex_us_04') > 0) {
         $two_day_quote = $two_day_quote + $fedex_add_chrg;
         $quote_data['FEDEX_2_DAY'] = array('id' => 'default_fedex.' . 'FEDEX_2_DAY', 'title' => 'Fedex 2 Day', 'cost' => $this->currency->convert($two_day_quote, 'USD', $this->currency->getCode()), 'tax_class_id' => 0, 'text' => $this->currency->format($this->currency->convert($two_day_quote, 'USD', $this->currency->getCode())));
     }
     if ($express_saver_quote > 0 && $this->config->get('default_fedex_default_fedex_us_05') > 0) {
         $express_saver_quote = $express_saver_quote + $fedex_add_chrg;
         $quote_data['FEDEX_EXPRESS_SAVER'] = array('id' => 'default_fedex.' . 'FEDEX_EXPRESS_SAVER', 'title' => 'Fedex Express Saver', 'cost' => $this->currency->convert($express_saver_quote, 'USD', $this->currency->getCode()), 'tax_class_id' => 0, 'text' => $this->currency->format($this->currency->convert($express_saver_quote, 'USD', $this->currency->getCode())));
     }
     if ($ground_quote > 0 && $this->config->get('default_fedex_default_fedex_us_06') > 0) {
         $ground_quote = $ground_quote + $fedex_add_chrg;
         $quote_data['FEDEX_GROUND'] = array('id' => 'default_fedex.' . 'FEDEX_GROUND', 'title' => 'Fedex Ground', 'cost' => $this->currency->convert($ground_quote, 'USD', $this->currency->getCode()), 'tax_class_id' => 0, 'text' => $this->currency->format($this->currency->convert($ground_quote, 'USD', $this->currency->getCode())));
     }
     return array('quote_data' => $quote_data, 'error_msg' => $error_msg);
 }
 private function _processRequest($address)
 {
     require_once DIR_EXT . 'default_fedex/core/lib/fedex_func.php';
     if ($this->config->get('default_fedex_test')) {
         $path_to_wsdl = DIR_EXT . 'default_fedex/core/lib/RateService_v9_test.wsdl';
     } else {
         $path_to_wsdl = DIR_EXT . 'default_fedex/core/lib/RateService_v9.wsdl';
     }
     $client = new SoapClient($path_to_wsdl, array('trace' => 1));
     // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
     //Fedex Key
     $fedex_key = $this->config->get('default_fedex_key');
     //Fedex Password
     $fedex_password = $this->config->get('default_fedex_password');
     //Fedex Meter Id
     $fedex_meter_id = $this->config->get('default_fedex_meter');
     //Fedex Account
     $fedex_account = $this->config->get('default_fedex_account');
     //Quote Type Residential or commercial
     $fedex_quote = $this->config->get('default_fedex_quote_type');
     if ($fedex_quote == 'residential') {
         $fedex_residential = true;
     } else {
         $fedex_residential = false;
     }
     $fedex_addr = $this->config->get('default_fedex_address');
     $fedex_city = $this->config->get('default_fedex_city');
     $fedex_state = $this->config->get('default_fedex_state');
     $fedex_zip = $this->config->get('default_fedex_zip');
     $fedex_country = $this->config->get('default_fedex_country');
     $fedex_add_chrg = $this->config->get('default_fedex_add_chrg');
     //Recepient Info
     $shipping_address = $address;
     $request = array();
     $product_weight = 1.0;
     $product_length = 1.0;
     $product_width = 1.0;
     $product_height = 1.0;
     $product_quantity = 1;
     $product_total = 1.0;
     //BUILD REQUEST START
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $fedex_key, 'Password' => $fedex_password));
     $request['ClientDetail'] = array('AccountNumber' => $fedex_account, 'MeterNumber' => $fedex_meter_id);
     $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v9 using PHP ***');
     $request['Version'] = array('ServiceId' => 'crs', 'Major' => '9', 'Intermediate' => '0', 'Minor' => '0');
     $request['ReturnTransitAndCommit'] = true;
     $request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP';
     // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
     $request['RequestedShipment']['ShipTimestamp'] = date('c');
     //$request['RequestedShipment']['ServiceType'] = 'GROUND_HOME_DELIVERY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
     $request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING';
     // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
     $request['RequestedShipment']['TotalInsuredValue'] = array('Ammount' => $product_total, 'Currency' => 'USD');
     $request['RequestedShipment']['Shipper'] = array('Address' => array('StreetLines' => array($fedex_addr), 'City' => $fedex_city, 'StateOrProvinceCode' => $fedex_state, 'PostalCode' => $fedex_zip, 'CountryCode' => $fedex_country));
     $request['RequestedShipment']['Recipient'] = array('Address' => array('StreetLines' => array($shipping_address['address_1'], $shipping_address['address_2']), 'City' => $shipping_address['city'], 'StateOrProvinceCode' => $shipping_address['zone_code'], 'PostalCode' => $shipping_address['postcode'], 'CountryCode' => $shipping_address['iso_code_2'], 'Residential' => $fedex_residential));
     $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => $fedex_account, 'CountryCode' => 'US'));
     $request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     $request['RequestedShipment']['PackageCount'] = $product_quantity;
     $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
     //  Or PACKAGE_SUMMARY
     for ($q = 0; $q < $product_quantity; $q++) {
         $request['RequestedShipment']['RequestedPackageLineItems'] = array('Weight' => array('Value' => $product_weight, 'Units' => 'LB'), 'Dimensions' => array('Length' => $product_length, 'Width' => $product_width, 'Height' => $product_height, 'Units' => 'IN'));
     }
     $error_msg = '';
     try {
         if (setEndpoint('changeEndpoint')) {
             $newLocation = $client->__setLocation(setEndpoint('endpoint'));
         }
         $response = $client->getRates($request);
         if ($response->HighestSeverity == 'FAILURE' || $response->HighestSeverity == 'ERROR') {
             $error_msg = $this->_get_notifications($response->Notifications);
         }
     } catch (SoapFault $exception) {
         $error_text = 'Fault' . "<br>\n";
         $error_text .= "Code:" . $exception->faultcode . "\n";
         $error_text .= "String:" . $exception->faultstring . "\n";
         $error_text .= $client;
         $this->message->saveError('fedex extension soap error', $error_text);
         $this->log->write($error_text);
     }
     return array('error' => $error_msg);
 }
 function get_live_rates($option_value = "ALL")
 {
     // manually set the weight at 1lb as a minimum
     $this->EE =& get_instance();
     $this->EE->load->library('cartthrob_shipping_plugins');
     $this->core->cart->set_custom_data("shipping_error", "");
     if ($this->plugin_settings('mode') == "dev") {
         $wsdl_path = PATH_THIRD . "cartthrob/third_party/lib/fedex/wsdl/RateService_v9_dev_version.wsdl";
     } else {
         $wsdl_path = PATH_THIRD . "cartthrob/third_party/lib/fedex/wsdl/RateService_v9.wsdl";
     }
     $client = new SoapClient($wsdl_path, array('trace' => 1));
     // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
     $shipping = array('error_message' => NULL, 'price' => array(), 'option_value' => array(), 'option_name' => array());
     if (!$this->plugin_settings('access_key') || !$this->plugin_settings('account_number') || !$this->plugin_settings('password') || !$this->plugin_settings('meter_number')) {
         $shipping['error_message'] = $this->EE->lang->line('shipping_settings_not_configured');
         $this->core->cart->set_custom_data("shipping_error", $shipping['error_message']);
         $this->core->cart->save();
         return $shipping;
     }
     /******************************************* ASSEMBLE REQUEST & SEND *********************************/
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $this->plugin_settings('access_key'), 'Password' => $this->plugin_settings('password')));
     $request['ClientDetail'] = array('AccountNumber' => $this->plugin_settings('account_number'), 'MeterNumber' => $this->plugin_settings('meter_number'));
     $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Available Services Request v9 using PHP ***');
     $request['Version'] = array('ServiceId' => 'crs', 'Major' => '9', 'Intermediate' => '0', 'Minor' => '0');
     $request['ReturnTransitAndCommit'] = true;
     $request['RequestedShipment']['DropoffType'] = $this->plugin_settings('rate_chart');
     // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
     $request['RequestedShipment']['ShipTimestamp'] = date('c');
     $orig_state = $this->plugin_settings('origination_state') ? $this->plugin_settings('origination_state') : $this->EE->cartthrob_shipping_plugins->customer_location_defaults('state');
     //@TODO add state
     $orig_zip = $this->plugin_settings('origination_zip') ? $this->plugin_settings('origination_zip') : $this->EE->cartthrob_shipping_plugins->customer_location_defaults("zip");
     // @TODO add zip
     $orig_country_code = $this->plugin_settings('orig_country_code') ? $this->plugin_settings('orig_country_code') : $this->EE->cartthrob_shipping_plugins->customer_location_defaults("country_code");
     //@TODO add country
     $orig_res_com = $this->plugin_settings('origination_res_com') == "RES" ? 1 : 0;
     $destination_res_com = $this->plugin_settings('destination_res_com') == "RES" ? 1 : 0;
     $request['RequestedShipment']['TotalInsuredValue'] = array('Amount' => $this->plugin_settings('insurance_default'), 'Currency' => $this->plugin_settings('insurance_currency'));
     $request['RequestedShipment']['Shipper'] = array('Address' => array('StreetLines' => array($this->plugin_settings('origination_address'), $this->plugin_settings('origination_address2')), 'City' => $this->plugin_settings('origination_city'), 'StateOrProvinceCode' => $orig_state, 'PostalCode' => $orig_zip, 'CountryCode' => $this->EE->cartthrob_shipping_plugins->alpha2_country_code($orig_country_code), 'Residential' => $orig_res_com));
     if ($option_value == "SMART_POST") {
         $request['RequestedShipment']['SmartPostDetail'] = array('Indicia' => $this->plugin_settings('sp_indicia'), 'AncillaryEndorsement' => $this->plugin_settings('sp_ancillary_services'), 'HubId' => $this->plugin_settings('hubid'), 'CustomerManifestId' => date("md0B"));
     }
     $request['RequestedShipment']['Recipient'] = array('Address' => array('StreetLines' => array($this->EE->cartthrob_shipping_plugins->customer_location_defaults("address"), $this->EE->cartthrob_shipping_plugins->customer_location_defaults('address2')), 'City' => $this->EE->cartthrob_shipping_plugins->customer_location_defaults("city", NULL), 'StateOrProvinceCode' => $this->EE->cartthrob_shipping_plugins->customer_location_defaults("state", NULL), 'PostalCode' => $this->EE->cartthrob_shipping_plugins->customer_location_defaults("zip", NULL), 'CountryCode' => $this->EE->cartthrob_shipping_plugins->alpha2_country_code($this->EE->cartthrob_shipping_plugins->customer_location_defaults("country_code")), 'Residential' => $destination_res_com));
     $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => $this->plugin_settings('account_number'), 'CountryCode' => $this->EE->cartthrob_shipping_plugins->alpha2_country_code($orig_country_code)));
     $request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     $request['RequestedShipment']['PackageCount'] = $this->core->cart->count_all();
     $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
     //  Or PACKAGE_SUMMARY
     $count = 0;
     foreach ($this->core->cart->items() as $key => $item) {
         $request['RequestedShipment']['RequestedPackageLineItems'][$count] = array('Weight' => array('Value' => ($item->weight() > 0 ? $item->weight() : 1) * $item->quantity(), 'Units' => $this->plugin_settings('weight_code')), 'Dimensions' => array('Length' => $item->item_options('length') ? $item->item_options('length') : $this->plugin_settings('def_length'), 'Width' => $item->item_options('width') ? $item->item_options('width') : $this->plugin_settings('def_width'), 'Height' => $item->item_options('height') ? $item->item_options('height') : $this->plugin_settings('def_height'), 'Units' => $this->plugin_settings('length_code')));
         $count++;
     }
     try {
         if (setEndpoint('changeEndpoint')) {
             $newLocation = $client->__setLocation(setEndpoint('endpoint'));
         }
         $response = $client->getRates($request);
         if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR' && !empty($response->RateReplyDetails)) {
             foreach ($response->RateReplyDetails as $rateReply) {
                 // if only ONE rate is returned.... then $rateReply is not an array, and we need to go up to the $response
                 if (is_string($rateReply)) {
                     if (isset($response->RateReplyDetails->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount)) {
                         $shipping['error_message'] = NULL;
                         $shipping['price'][] = number_format($response->RateReplyDetails->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                         $shipping['option_value'][] = $response->RateReplyDetails->ServiceType;
                         $shipping['option_name'][] = $this->shipping_methods($response->RateReplyDetails->ServiceType);
                     }
                     // breaking, because any additional iteration will continue to return the result above.
                     break;
                 } else {
                     if (isset($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount)) {
                         $shipping['error_message'] = NULL;
                         $shipping['price'][] = number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",");
                         $shipping['option_value'][] = $rateReply->ServiceType;
                         $shipping['option_name'][] = $this->shipping_methods($rateReply->ServiceType);
                     }
                 }
             }
         } else {
             $shipping = array('error_message' => $this->build_errors($response->Notifications), 'price' => array(), 'option_value' => array(), 'option_name' => array());
         }
     } catch (SoapFault $exception) {
         $shipping = array('error_message' => $exception->faultcode . " " . $exception->faultstring . " " . $this->build_faults($exception), 'price' => array(), 'option_value' => array(), 'option_name' => array());
     }
     // CHECKING THE PRESELECTED OPTIONS THAT ARE AVAILABLE
     $available_shipping = array();
     foreach ($shipping['option_value'] as $key => $value) {
         // REMOVE THE ONES THAT ARE NOT OPTIONS
         if ($this->plugin_settings($value) != "n") {
             $available_shipping['price'][$key] = $shipping['price'][$key];
             $available_shipping['option_value'][$key] = $shipping['option_value'][$key];
             $available_shipping['option_name'][$key] = $shipping['option_name'][$key];
         }
     }
     if ($shipping['error_message']) {
         $available_shipping['error_message'] = $shipping['error_message'];
         $this->core->cart->set_custom_data("shipping_error", $shipping['error_message']);
     }
     // update cart shipping hash
     $this->cart_hash($available_shipping);
     // if there's no errors, but we removed all of the shipping options, it's because none of the values were configured on the backend. We need to warn.
     if (empty($available_shipping['error_message']) && empty($available_shipping['price']) && !empty($available_shipping)) {
         $available_shipping['error_message'] = "Shipping options compatible with your location: (" . $shipping_address . " " . $shipping_address2 . " " . $shipping_city . " " . ($shipping_state ? "," . $shipping_state : "") . " " . $shipping_zip . " " . $dest_country_code . ") have not been configured in the cart settings. Please contact the webmaster";
         if ($dest_country_code != $orig_country_code) {
             $available_shipping['error_message'] .= " International shipping options may need to be added. ";
         }
         $this->core->cart->set_custom_data("shipping_error", $available_shipping['error_message']);
     }
     $this->core->cart->save();
     return $available_shipping;
 }
Ejemplo n.º 7
0
 public function getRates($items)
 {
     global $order;
     require_once BASE . 'external/fedex-php/fedex-common.php';
     //require_once('fedex-common.php');
     //The WSDL is not included with the sample code.
     //Please include and reference in $path_to_wsdl variable.
     $path_to_wsdl = BASE . 'external/fedex-php/RateService_v9.wsdl';
     ini_set("soap.wsdl_cache_enabled", "0");
     $client = new SoapClient($path_to_wsdl, array('trace' => 1));
     // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $this->configdata['fedex_key'], 'Password' => $this->configdata['fedex_password']));
     $request['ClientDetail'] = array('AccountNumber' => $this->configdata['fedex_account_number'], 'MeterNumber' => $this->configdata['fedex_meter_number']);
     //$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Available Services Request v9 using PHP ***');
     $request['TransactionDetail'] = array('CustomerTransactionId' => md5("Probody " . date('c')));
     $request['Version'] = array('ServiceId' => 'crs', 'Major' => '9', 'Intermediate' => '0', 'Minor' => '0');
     $request['ReturnTransitAndCommit'] = true;
     $request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP';
     // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
     $request['RequestedShipment']['ShipTimestamp'] = date('c');
     // Service Type and Packaging Type are not passed in the request
     $this->configdata['shipfrom']['StreetLines'][] = $this->configdata['shipfrom']['address1'];
     if (!empty($this->configdata['shipfrom']['address2'])) {
         $this->configdata['shipfrom']['StreetLines'][] = $this->configdata['shipfrom']['address2'];
     }
     if (!empty($this->configdata['shipfrom']['address3'])) {
         $this->configdata['shipfrom']['StreetLines'][] = $this->configdata['shipfrom']['address3'];
     }
     unset($this->configdata['shipfrom']['address1']);
     unset($this->configdata['shipfrom']['address2']);
     unset($this->configdata['shipfrom']['address3']);
     unset($this->configdata['shipfrom']['state']);
     unset($this->configdata['shipfrom']['country']);
     //eDebug($this->configdata['shipfrom'],true);
     $request['RequestedShipment']['Shipper'] = array('Address' => $this->configdata['shipfrom']);
     // get the current shippingmethod and format the address for ups
     $currentmethod = $order->getCurrentShippingMethod();
     $request['RequestedShipment']['Recipient'] = array('Address' => $this->formatAddress($currentmethod));
     $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => $this->configdata['fedex_account_number'], 'CountryCode' => $this->configdata['shipfrom']['CountryCode']));
     $request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
     // set the standard box sizes.
     $box_width = empty($this->configdata['default_width']) ? 0 : $this->configdata['default_width'];
     $box_height = empty($this->configdata['default_height']) ? 0 : $this->configdata['default_height'];
     $box_length = empty($this->configdata['default_length']) ? 0 : $this->configdata['default_length'];
     $box_volume = $box_height * $box_width * $box_length;
     // set some starting/default values
     $weight = 0;
     $volume = 0;
     $count = 0;
     $package_items = array();
     // loop each product in this shipment and create the packages
     foreach ($items->orderitem as $item) {
         for ($i = 0; $i < $item->quantity; $i++) {
             if (empty($item->product->no_shipping) && $item->product->requiresShipping == true) {
                 $lbs = empty($item->product->weight) ? $this->configdata['default_max_weight'] : $item->product->weight;
                 $width = empty($item->product->width) ? $this->configdata['default_width'] : $item->product->width;
                 $height = empty($item->product->height) ? $this->configdata['default_height'] : $item->product->height;
                 $length = empty($item->product->length) ? $item->product->width : $item->product->length;
                 $length = empty($length) ? $this->configdata['default_length'] : $length;
                 $package_items[$count]->volume = $width * $length * $height;
                 $package_items[$count]->weight = $lbs;
                 $package_items[$count]->w = $width;
                 $package_items[$count]->h = $height;
                 $package_items[$count]->l = $length;
                 $package_items[$count]->name = $item->product->title;
                 $count += 1;
             }
         }
     }
     //eDebug($package_items);
     // sort the items by volume
     $package_items = expSorter::sort(array('array' => $package_items, 'sortby' => 'volume', 'order' => 'DESC'));
     // loop over all the items and try to put them into packages in a semi-intelligent manner
     // we have sorted the list of items from biggest to smallest.  Items with a volume larger than
     // our standard box will generate a package with the dimensions set to the size of the item.
     // otherwise we just keep stuffing items in the current package until we can't find anymore that will
     // fit.  Once that happens we close that package and start a new one...repeating until we are out of items
     $space_left = $box_volume;
     //eDebug($space_left);
     $total_weight = 0;
     $box_count = 0;
     $fedexItemArray = array();
     while (!empty($package_items)) {
         $no_more_room = false;
         $used = array();
         foreach ($package_items as $idx => $pi) {
             /*if ($pi->volume > $box_volume) {
             #                    echo $pi->name."is too big for standard box <br>";
             #                    eDebug('created OVERSIZED package with weight of '.$pi->weight);
             #                    eDebug('dimensions: height: '.$pi->h." width: ".$pi->w." length: ".$pi->l);
             #                    echo "<hr>";
                                 $weight = $pi->weight > 1 ? $pi->weight : 1;
                                 $upsRate->package(array('description'=>'shipment','weight'=>$weight,'code'=>'02','length'=>$pi->l,'width'=>$pi->w,'height'=>$pi->h));
                                 $used[] = $idx;
                                 $no_more_room = false;
                             } elseif($pi->volume <= $space_left) {*/
             if ($pi->volume >= $space_left) {
                 $no_more_room = true;
                 break;
             }
             $space_left = $space_left - $pi->volume;
             $total_weight += $pi->weight;
             #                    echo "Adding ".$pi->name."<br>";
             #                    echo "Space left in current box: ".$space_left."<br>";
             $used[] = $idx;
             //}
         }
         // remove the used items from the array so they wont be there on the next go around.
         foreach ($used as $idx) {
             unset($package_items[$idx]);
         }
         // if there is no more room left on the current package or we are out of items then
         // add the package to the shippment.
         if ($no_more_room || empty($package_items) && $total_weight > 0) {
             $box_count++;
             $total_weight = $total_weight > 1 ? $total_weight : 1;
             #                eDebug('created standard sized package with weight of '.$total_weight);
             #                echo "<hr>";
             //$upsRate->package(array('description'=>'shipment','weight'=>$total_weight,'code'=>'02','length'=>$box_length,'width'=>$box_width,'height'=>$box_height));
             $fedexItemArray[] = array('Weight' => array('Value' => $total_weight, 'Units' => 'LB'), 'Dimensions' => array('Length' => $box_length, 'Width' => $box_width, 'Height' => $box_height, 'Units' => 'IN'));
             $space_left = $box_volume;
             $total_weight = 0;
         }
     }
     //eDebug($fedexItemArray,true);
     //eDebug($box_count . " boxes in this shipment.");
     $request['RequestedShipment']['PackageCount'] = "{$box_count}";
     $request['RequestedShipment']['RequestedPackageLineItems'] = $fedexItemArray;
     //eDebug($request['RequestedShipment']['PackageCount']);
     //eDebug($request['RequestedShipment']['RequestedPackageLineItems'],true);
     /*array(
       '0' => array(
               'Weight' => 
                       array(
                           'Value' => 2.0,
                           'Units' => 'LB'),
                           'Dimensions' => 
                                   array(
                                       'Length' => 10,
                                       'Width' => 10,
                                       'Height' => 3,
                                       'Units' => 'IN')),
       '1' => array(
               'Weight' => 
                       array(
                           'Value' => 5.0,
                           'Units' => 'LB'),
                           'Dimensions' => 
                                   array(
                                       'Length' => 20,
                                       'Width' => 20,
                                       'Height' => 10,
                                       'Units' => 'IN')
                                       )
                                   );
                                                                                               
                                                                                                                             */
     try {
         if (setEndpoint('changeEndpoint')) {
             $newLocation = $client->__setLocation(setEndpoint('endpoint'));
         }
         $response = $client->getRates($request);
         //eDebug($response,true);
         if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
             //echo 'Rates for following service type(s) were returned.'. Newline. Newline;
             //echo '<table border="1">';
             //echo '<tr><td>Service Type</td><td>Amount</td><td>Delivery Date</td>';
             $rates = array();
             //array(
             //"03"=>array("id"=>"03", "title"=>"UPS Ground", "cost"=>5.00),
             //"02"=>array("id"=>"02", "title"=>"UPS Second Day Air", "cost"=>10.00),
             //"01"=>array("id"=>"01", "title"=>"UPS Next Day Air", "cost"=>20.00)
             //);
             /*eDebug($this->configdata['shipping_methods'],true);
               eDebug($response -> RateReplyDetails,true);*/
             foreach ($response->RateReplyDetails as $rateReply) {
                 if (in_array($rateReply->ServiceType, $this->configdata['shipping_methods'])) {
                     $rates[$rateReply->ServiceType] = array("id" => $rateReply->ServiceType, "title" => $this->shippingmethods[$rateReply->ServiceType], "cost" => number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ","));
                 }
                 /* $amount = '<td>$' . number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount,2,".",",") . '</td>';
                    if(array_key_exists('DeliveryTimestamp',$rateReply)){
                        $deliveryDate= '<td>' . $rateReply->DeliveryTimestamp . '</td>';
                    }else{
                        $deliveryDate= '<td>' . $rateReply->TransitTime . '</td>';
                    }
                    echo $serviceType . $amount. $deliveryDate;
                    echo '</tr>';*/
             }
             //eDebug($rates,true);
             return array_reverse($rates);
         } else {
             printError($client, $response);
         }
         writeToLog($client);
         // Write to log file
     } catch (SoapFault $exception) {
         printFault($exception, $client);
     }
 }