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; }
$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> </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> </th></tr>'; trackDetails($response->CompletedTrackDetails, ''); echo '</table>'; }else{ echo '<table border="1">'; echo '<tr><th>Package Level Tracking Details</th><th> </th></tr>'; trackDetails($response->CompletedTrackDetails->TrackDetails, ''); echo '</table>'; } } printSuccess($client, $response); }else{ printError($client, $response); } writeToLog($client); // Write to log file } catch (SoapFault $exception) { printFault($exception, $client); } ?>
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); } }
function getFedexRate($from_zip, $to_zip, $weight) { // Colaesce Dev Account: $key = 'kEX6SaVxmKkWBrv4'; $account_number = '510087100'; $password = '******'; $meter_number = '7001787'; // $service_type = 'FEDEX_GROUND'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ... $packaging_type = 'YOUR_PACKAGING'; // valid values FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ... $drop_off_type = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ... $shipper = array('Address' => array('StreetLines' => array('2980 Highway 378'), 'City' => 'Conway', 'StateOrProvinceCode' => 'SC', 'PostalCode' => $from_zip, 'CountryCode' => 'US')); $recipient = array('Address' => array('StreetLines' => array(''), 'City' => '', 'StateOrProvinceCode' => '', 'PostalCode' => $to_zip, 'CountryCode' => 'US')); $requested_packages = array('0' => array('SequenceNumber' => '1', 'InsuredValue' => array('Amount' => 0, 'Currency' => 'USD'), 'ItemDescription' => 'Website Order', 'Weight' => array('Value' => $weight, 'Units' => 'LB'), 'Dimensions' => array('Length' => 0, 'Width' => 0, 'Height' => 0, 'Units' => 'IN'), 'CustomerReferences' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => 'Website Order'))); // Copyright 2008, FedEx Corporation. All rights reserved. // Version 4.0.0 require_once APP . '/vendors/fedex/fedex-common.php'; $newline = "<br />"; //The WSDL is not included with the sample code. //Please include and reference in $path_to_wsdl variable. $path_to_wsdl = APP . '/vendors/fedex/RateService_v4.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.phpfor more information $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $this->credentials['fedex']['key'], 'Password' => $this->credentials['fedex']['password'])); $request['ClientDetail'] = array('AccountNumber' => $this->credentials['fedex']['account_number'], 'MeterNumber' => $this->credentials['fedex']['meter_number']); $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v4 using PHP ***'); $request['Version'] = array('ServiceId' => 'crs', 'Major' => '4', 'Intermediate' => '0', 'Minor' => '0'); $request['RequestedShipment']['DropoffType'] = $drop_off_type; $request['RequestedShipment']['ShipTimestamp'] = date('c'); $request['RequestedShipment']['ServiceType'] = $service_type; $request['RequestedShipment']['PackagingType'] = $packaging_type; $request['RequestedShipment']['Shipper'] = $shipper; $request['RequestedShipment']['Recipient'] = $recipient; $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => $account_number, 'CountryCode' => 'US')); $request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT'; $request['RequestedShipment']['RateRequestTypes'] = 'LIST'; $request['RequestedShipment']['PackageCount'] = '1'; $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES'; $request['RequestedShipment']['RequestedPackages'] = $requested_packages; try { $response = $client->getRates($request); if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') { // print_r($response); exit(); return $response->RateReplyDetails->RatedShipmentDetails['0']->ShipmentRateDetail->TotalNetCharge->Amount; // printRequestResponse($client); } else { echo 'Error in processing transaction.' . $newline . $newline; foreach ($response->Notifications as $notification) { if (is_array($response->Notifications)) { echo $notification->Severity; echo ': '; echo $notification->Message . $newline; } else { echo $notification . $newline; } } } // writeToLog($client); // Write to log file } catch (SoapFault $exception) { printFault($exception, $client); } }