Beispiel #1
0
 function queryFedEx($pkg, $user_choices, $num_packages)
 {
     // Fetch the book rates from FEDEX
     global $messageStack, $currencies;
     $arrRates = array();
     $strXML = $this->FormatFedExRateRequest($pkg, $num_packages);
     //echo 'FedEx Express XML Submit String:<br />' . htmlspecialchars($strXML) . '<br />';
     $SubmitXML = GetXMLString($strXML, $this->rate_url, "POST");
     // Check for XML request errors
     if ($SubmitXML['result'] == 'error') {
         $messageStack->add(SHIPPING_FEDEX_CURL_ERROR . $SubmitXML['message'], 'error');
         return false;
     }
     $ResponseXML = $SubmitXML['xmlString'];
     //echo '<br />XML Return String:<br />' . htmlspecialchars($ResponseXML) . '<br />';
     // Check for errors
     $XMLFail = GetNodeData($ResponseXML, 'Error:Code');
     if ($XMLFail) {
         // fetch the error code
         $XMLErrorDesc = GetNodeData($ResponseXML, 'Error:Message');
         $FEDEXQuote['result'] = 'error';
         $messageStack->add(SHIPPING_FEDEX_RATE_ERROR . $XMLFail . ' - ' . $XMLErrorDesc, 'error');
         return false;
     }
     // Fetch the FedEx Rates
     $XMLStart = 'Entry';
     $XMLIndexName = 'Service';
     // name of the index in array
     $TagsToFind = array('DeliveryDOW' => 'DeliveryDay', 'TransitDays' => 'TimeInTransit', 'ShipmentCost' => 'EstimatedCharges:DiscountedCharges:NetCharge', 'BookCharges' => 'EstimatedCharges:ListCharges:NetCharge');
     $fdxRates = GetNodeArray($ResponseXML, $XMLStart, $XMLIndexName, $TagsToFind);
     //echo 'FedEx rate array = '; print_r($fdxRates); echo '<br />';
     foreach ($this->FedExRateCodes as $key => $value) {
         if (isset($fdxRates[$key]) && in_array($value, $user_choices)) {
             if ($fdxRates[$key]['BookCharges'] != "") {
                 $arrRates[$this->code][$value]['book'] = $currencies->clean_value($fdxRates[$key]['BookCharges']);
             }
             if ($fdxRates[$key]['ShipmentCost'] != "") {
                 $arrRates[$this->code][$value]['cost'] = $currencies->clean_value($fdxRates[$key]['ShipmentCost']);
             }
             $arrRates[$this->code][$value]['note'] = '';
             if ($fdxRates[$key]['TransitDays'] != "") {
                 $arrRates[$this->code][$value]['note'] .= $fdxRates[$key]['TransitDays'] . ' Day(s) Transit. ';
             }
             if ($fdxRates[$key]['DeliveryDOW'] != "") {
                 $arrRates[$this->code][$value]['note'] .= 'Arrives ' . $fdxRates[$key]['DeliveryDOW'];
             }
             if (function_exists('fedex_shipping_rate_calc')) {
                 $arrRates[$this->code][$value]['quote'] = fedex_shipping_rate_calc($arrRates[$this->code][$value]['book'], $arrRates[$this->code][$value]['cost'], $value);
             } else {
                 if ($fdxRates[$key]['BookCharges'] != "") {
                     $arrRates[$this->code][$value]['quote'] = $fdxRates[$key]['BookCharges'];
                 }
             }
         }
     }
     return $arrRates;
 }
Beispiel #2
0
 function queryFedEx($client, $pkg, $user_choices, $num_packages, $ltl = false)
 {
     global $messageStack, $currencies;
     $arrRates = array();
     $request = $this->FormatFedExRateRequest($pkg, $num_packages, $ltl);
     //if ($ltl) { echo 'FedEx Express XML Submit String:<br />'; print_r($request); echo '<br />'; }
     try {
         $response = $client->getRates($request);
         //echo 'Request <pre>'  . htmlspecialchars($client->__getLastRequest()) . '</pre>';
         //echo 'Response <pre>' . htmlspecialchars($client->__getLastResponse()) . '</pre>';
         //if ($ltl) { echo 'rate response array = '; print_r($response->RateReplyDetails); echo '<br />'; }
         if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
             if ($response->HighestSeverity == 'NOTE' || $response->HighestSeverity == 'WARNING') {
                 $message .= ' (' . $response->Notifications->Code . ') ' . $response->Notifications->Message;
                 $messageStack->add('FedEx Note: ' . $message, 'caution');
             }
             if (is_object($response->RateReplyDetails)) {
                 $response->RateReplyDetails = array($response->RateReplyDetails);
             }
             if (is_array($response->RateReplyDetails)) {
                 foreach ($response->RateReplyDetails as $rateReply) {
                     $service = $this->FedExRateCodes[$rateReply->ServiceType];
                     //echo 'rateReply->ServiceType = '; print_r($rateReply->ServiceType); echo '<br>';
                     if ($service == '3Dam' && $pkg->pkg_weight > FEDEX_MAX_SMART_POST_WEIGHT) {
                         continue;
                     }
                     if (in_array($service, $user_choices)) {
                         $temp = array();
                         // ground and freight are not in an array so convert
                         if (is_array($rateReply->RatedShipmentDetails)) {
                             foreach ($rateReply->RatedShipmentDetails as $details) {
                                 $temp[] = $details;
                             }
                         } else {
                             $temp[] = $rateReply->RatedShipmentDetails;
                         }
                         foreach ($temp as $details) {
                             switch ($details->ShipmentRateDetail->RateType) {
                                 default:
                                 case 'PAYOR_ACCOUNT':
                                     $arrRates[$this->code][$service]['cost'] = $details->ShipmentRateDetail->TotalNetCharge->Amount;
                                     if (isset($rateReply->CommitDetails->CommitTimestamp)) {
                                         $arrRates[$this->code][$service]['note'] = 'Commit: ' . date("D M j g:i a", strtotime($rateReply->CommitDetails->CommitTimestamp));
                                     } elseif (isset($rateReply->CommitDetails->MaximumTransitTime)) {
                                         $arrRates[$this->code][$service]['note'] = ' Commit: ' . date("D M j g:i a", strtotime($this->calculateDelivery($rateReply->CommitDetails->MaximumTransitTime, $pkg->residential_address)));
                                     } elseif (isset($rateReply->CommitDetails->TransitTime)) {
                                         $arrRates[$this->code][$service]['note'] = ' Commit: ' . date("D M j g:i a", strtotime($this->calculateDelivery($rateReply->CommitDetails->TransitTime, $pkg->residential_address)));
                                     } else {
                                         $arrRates[$this->code][$service]['note'] = '';
                                     }
                                     // fall through as book and quote are the same for both types
                                 // fall through as book and quote are the same for both types
                                 case 'RATED_ACCOUNT':
                                     $surcharges = $details->ShipmentRateDetail->TotalSurcharges->Amount;
                                     $baserate = $details->ShipmentRateDetail->TotalBaseCharge->Amount;
                                     $arrRates[$this->code][$service]['book'] = $baserate + $surcharges;
                                     $arrRates[$this->code][$service]['quote'] = $arrRates[$this->code][$service]['book'];
                                     break;
                                 case 'PAYOR_MULTIWEIGHT':
                                     break;
                             }
                         }
                         if (function_exists('fedex_shipping_rate_calc')) {
                             $arrRates[$this->code][$service]['quote'] = fedex_shipping_rate_calc($arrRates[$this->code][$service]['book'], $arrRates[$this->code][$service]['cost'], $service);
                         }
                     }
                 }
             }
         } else {
             foreach ($response->Notifications as $notification) {
                 if (is_object($notification)) {
                     $message .= ' (' . $notification->Severity . ') ' . $notification->Message;
                 } else {
                     $message .= ' - ' . $notification;
                 }
             }
             $messageStack->add(SHIPPING_FEDEX_V7_RATE_ERROR . $message, 'error');
             return false;
         }
     } catch (SoapFault $exception) {
         //echo 'Request <pre>'  . htmlspecialchars($client->__getLastRequest()) . '</pre>';
         //echo 'Response <pre>' . htmlspecialchars($client->__getLastResponse()) . '</pre>';
         $message = " [soap fault] ({$exception->faultcode}) {$exception->faultstring}";
         $messageStack->add(SHIPPING_FEDEX_CURL_ERROR . $message, 'error');
         return false;
     }
     //if ($ltl) { echo 'arrRates array = '; print_r($arrRates); echo '<br /><br />'; }
     return $arrRates;
 }