当前位置: 首页>>代码示例>>PHP>>正文


PHP SoapClient::getRates方法代码示例

本文整理汇总了PHP中SoapClient::getRates方法的典型用法代码示例。如果您正苦于以下问题:PHP SoapClient::getRates方法的具体用法?PHP SoapClient::getRates怎么用?PHP SoapClient::getRates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SoapClient的用法示例。


在下文中一共展示了SoapClient::getRates方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getRate

 public function getRate($PostalCode, $dest_zip, $dest_country_code, $service, $weight, $length = 0, $width = 0, $height = 0)
 {
     $setting = new Cart66Setting();
     $home_country = explode('~', Cart66Setting::getValue('home_country'));
     $countryCode = array_shift($home_country);
     $pickupCode = Cart66Setting::getValue('fedex_pickup_code') ? Cart66Setting::getValue('fedex_pickup_code') : "REGULAR_PICKUP";
     $residential = Cart66Setting::getValue('fedex_only_ship_commercial') ? "0" : "1";
     $locationType = Cart66Setting::getValue('fedex_location_type') == 'commercial' ? "0" : "1";
     if ($this->credentials != 1) {
         print 'Please set your credentials with the setCredentials function';
         die;
     }
     $path_to_wsdl = CART66_PATH . "/pro/models/RateService_v14.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->developerKey, 'Password' => $this->password));
     $request['ClientDetail'] = array('AccountNumber' => $this->accountNumber, 'MeterNumber' => $this->meterNumber);
     $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Available Services Request v14 using PHP ***');
     $request['Version'] = array('ServiceId' => 'crs', 'Major' => '14', 'Intermediate' => '0', 'Minor' => '0');
     $request['ReturnTransitAndCommit'] = true;
     $request['RequestedShipment']['DropoffType'] = $pickupCode;
     // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
     $request['RequestedShipment']['ShipTimestamp'] = date('c');
     // Service Type and Packaging Type are not passed in the request
     $request['RequestedShipment']['Shipper'] = array('Address' => array('PostalCode' => $this->fromZip, 'CountryCode' => $countryCode, 'Residential' => $locationType));
     $request['RequestedShipment']['Recipient'] = array('Address' => array('PostalCode' => $dest_zip, 'CountryCode' => $dest_country_code, 'Residential' => $residential));
     $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('ResponsibleParty' => array('AccountNumber' => $this->accountNumber, 'Contact' => null, 'Address' => array('CountryCode' => $countryCode))));
     $request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     $request['RequestedShipment']['PackageCount'] = $this->getPackageCount();
     $request['RequestedShipment']['RequestedPackageLineItems'] = $this->getRequestedPackageLineItems($weight);
     try {
         $client->__setLocation('https://gateway.fedex.com:443/web-services');
         $response = $client->getRates($request);
         if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
             $rate = array();
             if (is_array($response->RateReplyDetails)) {
                 foreach ($response->RateReplyDetails as $rateReply) {
                     $serviceType = $rateReply->ServiceType;
                     $amount = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
                     $rate[] = array('name' => $serviceType, 'rate' => $amount);
                 }
             } else {
                 $serviceType = $response->RateReplyDetails->ServiceType;
                 $amount = $response->RateReplyDetails->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
                 $rate[] = array('name' => $serviceType, 'rate' => $amount);
             }
         } else {
             $rate = false;
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Error: " . print_r($response->Notifications, true));
         }
     } catch (SoapFault $exception) {
         $this->printFault($exception, $client);
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] FedEx Error|| Code: " . $exception->faultcode . " Message: " . $exception->faultstring);
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Client Details: " . print_r($client, true));
         $rate = false;
     }
     return $rate;
 }
开发者ID:rbredow,项目名称:allyzabbacart,代码行数:60,代码来源:Cart66FedEx.php

示例2: _getQuotes

 protected function _getQuotes()
 {
     $r = $this->_request;
     $request = array('WebAuthenticationDetail' => array('UserCredential' => array('Key' => $r->key, 'Password' => $r->password)), 'ClientDetail' => array('AccountNumber' => $r->accountNumber, 'MeterNumber' => $r->meterNumber), 'Version' => array('ServiceId' => 'crs', 'Major' => '10', 'Intermediate' => '0', 'Minor' => '0'), 'RequestedShipment' => array('DropoffType' => $r->dropoffType, 'ShipTimestamp' => date('c'), 'PackagingType' => $r->packaging, 'TotalInsuredValue' => array('Ammount' => $r->value, 'Currency' => $r->currencyCode), 'Shipper' => array('Address' => array('PostalCode' => $r->originPostalCode, 'CountryCode' => $r->originCountryCode)), 'Recipient' => array('Address' => array('PostalCode' => $r->destPostalCode, 'CountryCode' => $r->destCountryCode, 'Residential' => (bool) $this->_config->residenceDelivery)), 'ShippingChargesPayment' => array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => $r->accountNumber, 'CountryCode' => $r->originCountryCode)), 'RateRequestTypes' => 'LIST', 'PackageCount' => '1', 'PackageDetail' => 'INDIVIDUAL_PACKAGES', 'RequestedPackageLineItems' => array(array('GroupPackageCount' => 1, 'Weight' => array('Value' => $r->weight, 'Units' => 'LB')))));
     $pathToWsdl = Axis::config('system/path') . "/app/code/Axis/ShippingFedex/etc/RateService_v10.wsdl";
     $client = new SoapClient($pathToWsdl);
     //        production : https://gateway.fedex.com:443/GatewayDC
     //        test       : https://wsbeta.fedex.com:443/web-services
     $client->__setLocation($this->_config->gateway);
     $response = $client->getRates($request);
     return $this->_parseResponse($response);
 }
开发者ID:baisoo,项目名称:axiscommerce,代码行数:12,代码来源:Standard.php

示例3: quote

 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;
 }
开发者ID:ebeauchamps,项目名称:brilliantretail,代码行数:51,代码来源:shipping.fedex.php

示例4: send

 /**
  * Send transaction
  *
  * @return void
  */
 public function send()
 {
     $this->request['RequestedShipment']['RequestedPackageLineItems'] = ['SequenceNumber' => 1, 'GroupPackageCount' => 1, 'Weight' => $this->weight];
     if (null !== $this->dimensions['Length'] && null !== $this->dimensions['Width'] && null !== $this->dimensions['Height']) {
         $this->request['RequestedShipment']['RequestedPackageLineItems']['Dimensions'] = $this->dimensions;
     }
     $this->response = $this->client->getRates($this->request);
     $this->responseCode = (int) $this->response->Notifications->Code;
     $this->responseMessage = (string) $this->response->Notifications->Message;
     if ($this->responseCode == 0) {
         foreach ($this->response->RateReplyDetails as $rate) {
             $this->rates[self::$services[(string) $rate->ServiceType]] = number_format((string) $rate->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2);
         }
         $this->rates = array_reverse($this->rates, true);
     }
 }
开发者ID:Nnadozieomeonu,项目名称:lacecart,代码行数:21,代码来源:Fedex.php

示例5: getRates

 function getRates(array $from, array $to, array $packages)
 {
     if (!class_exists('SoapClient')) {
         return array();
     }
     $wsdl = dirname(__FILE__) . '/FedEx_v8.wsdl';
     $args = array();
     $request = $this->getRequest($from, $to, $packages);
     try {
         $client = new SoapClient($wsdl, $args);
         $response = $client->getRates($request);
         $options = $response->RateReplyDetails;
         $out = $this->extractRates($options);
         return $out;
     } catch (SoapFault $e) {
         return array();
     }
 }
开发者ID:railfuture,项目名称:tiki-website,代码行数:18,代码来源:provider_fedex.php

示例6: send

 /**
  * Request shipping rates
  *
  * @return void
  */
 public function send()
 {
     $this->requestHeader['Version'] = ['ServiceId' => 'crs', 'Major' => '18', 'Intermediate' => '0', 'Minor' => '0'];
     $request['RequestedShipment'] = ['RateRequestTypes' => 'ACCOUNT', 'RateRequestTypes' => 'LIST', 'PackageCount' => count($this->packages), 'Shipper' => $this->shipFrom, 'Recipient' => $this->shipTo, 'RequestedPackageLineItems' => []];
     foreach ($this->packages as $package) {
         $request['RequestedShipment']['RequestedPackageLineItems'][] = $package->rateRequest();
     }
     $request = array_merge($this->requestHeader, $request);
     $this->client = new \SoapClient($this->wsdl['rates'], ['trace' => 1]);
     $this->response = $this->client->getRates($request);
     $this->responseCode = (int) $this->response->Notifications->Code;
     $this->responseMessage = (string) $this->response->Notifications->Message;
     $this->ratesExtended = [];
     if ($this->responseCode == 0) {
         foreach ($this->response->RateReplyDetails as $rate) {
             $serviceType = (string) $rate->ServiceType;
             $total = number_format((string) $rate->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2);
             $this->ratesExtended[$serviceType] = (object) ['shipper' => 'fedex', 'total' => $total, 'PackagingType' => (string) $rate->PackagingType, 'SignatureOption' => (string) $rate->SignatureOption, 'ActualRateType' => (string) $rate->ActualRateType, 'serviceType' => $serviceType, 'title' => self::$services[$serviceType]];
             $this->rates[self::$services[$serviceType]] = $total;
         }
         $this->rates = array_reverse($this->rates, true);
     }
 }
开发者ID:jfquestiaux,项目名称:fabrik,代码行数:28,代码来源:Fedex.php

示例7: date

 /** sends a SOAP request to a FedEx server. see what happens */
 function send_fedex_query($request)
 {
     if ($this->debug) {
         $log = "\n\n==\n" . get_class($this) . "::send_fedex_query()\n" . date('r');
         $log .= "\nIP: " . $_SERVER['REMOTE_ADDR'];
         error_log($log, 3, $this->debug_log);
     }
     $wsdl = dirname(__FILE__) . '/' . $this->_path_to_wsdl;
     if ($this->test_mode) {
         // testing version wsql hacked in, has a one-line difference
         $wsdl = preg_replace('/\\.wsdl$/', '-testing.wsdl', $wsdl);
     }
     $client = new SoapClient($wsdl, array('trace' => $this->debug));
     // http://us3.php.net/manual/en/ref.soap.php
     $quotes = array();
     try {
         $response = $client->getRates($request);
     } catch (SoapFault $e) {
         if ($this->debug) {
             $log = "\n\n==== EXCEPTION CAUGHT : SoapFault Exception ====\n";
             $log .= "====REQUEST====: \n" . $client->__getLastRequestHeaders() . "\n";
             $log .= $client->__getLastRequest() . "\n\n";
             $log .= "====RESPONSE===: \n" . $client->__getLastResponseHeaders() . "\n";
             $log .= $client->__getLastResponse() . "\n\n";
             error_log($log, 3, $this->debug_log);
         }
         return $this->raiseError($e->getMessage());
     }
     if ($this->debug) {
         $log = "\n====REQUEST==== \n" . $client->__getLastRequest() . "\n\n";
         error_log($log, 3, $this->debug_log);
         error_log("\nHighestSeverity: {$response->HighestSeverity}\n", 3, $this->debug_log);
         $log = "====RESPONSE===: \n" . serialize($response) . "\n\n";
         error_log($log, 3, $this->debug_log);
     }
     if ($response->HighestSeverity == 'SUCCESS') {
         foreach ($response->RateReplyDetails as $rateReply) {
             if (!is_object($rateReply) || !isset($rateReply->ServiceType)) {
                 continue;
             }
             $service = $rateReply->ServiceType;
             foreach ($rateReply->RatedShipmentDetails as $detail) {
                 $last_rate = null;
                 if (isset($detail->ShipmentRateDetail)) {
                     $rate = $detail->ShipmentRateDetail->TotalNetFedExCharge->Amount;
                     /* fedex returns multiple rate detail objects for each method, but they are always identical (maybe) */
                     if (!empty($last_rate) and $rate != $last_rate) {
                         $msg = "got different rates for the same shipping method {$service}";
                         trigger_error($msg, E_USER_WARNING);
                         if ($this->debug) {
                             error_log("{$msg}\n", 3, $this->debug_log);
                         }
                     }
                     $last_rate = $rate;
                 }
             }
             $quotes[$service] = $rate;
         }
         if (empty($quotes)) {
             $err = "No ship methods are available for this destination at this time. Please try again.";
             if ($this->debug) {
                 error_log("ERROR: {$err}\n", 3, $this->debug_log);
             }
             return $this->raiseError($err);
         }
         return $quotes;
     } else {
         if (is_object($response->Notifications)) {
             if ($response->Notifications->Code == 556) {
                 $err = "The Address or Postal/ZIP code was not valid.";
             } else {
                 $err = $response->Notifications->Severity . ': ' . $response->Notifications->Message . ' ';
             }
         } elseif (is_array($response->Notifications)) {
             foreach ($response->Notifications as $notification) {
                 $err .= $notification->Message . ' ';
             }
         }
         if ($this->debug) {
             error_log("Notification: {$err}\n", 3, $this->debug_log);
         }
         return $this->raiseError($err);
     }
 }
开发者ID:sbeam,项目名称:cshop,代码行数:85,代码来源:cmShipMethod_FedEx.class.php

示例8: quote


//.........这里部分代码省略.........
                     if ($shippingWeight <= 0) {
                         $shippingWeight = 0.1;
                     }
                     $new_shipping_weight += $shippingWeight;
                     $request['RequestedShipment']['RequestedPackageLineItems'][] = array('Weight' => array('Value' => $shippingWeight, 'Units' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_WEIGHT), 'GroupPackageCount' => 1);
                 }
             } else {
                 // note $values is an array
                 $new_shipping_num_boxes++;
                 if ($values['weight'] <= 0) {
                     $values['weight'] = 0.1;
                 }
                 $new_shipping_weight += $values['weight'];
                 $request['RequestedShipment']['RequestedPackageLineItems'][] = array('Weight' => array('Value' => $values['weight'], 'Units' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_WEIGHT), 'Dimensions' => array('Length' => $values['length'], 'Width' => $values['width'], 'Height' => $values['height'], 'Units' => $values['units']), 'GroupPackageCount' => 1);
             }
         }
         $shippingNumBoxes = $new_shipping_num_boxes;
         $shippingWeight = round($new_shipping_weight / $shippingNumBoxes, 2);
     } else {
         if ($shippingWeight == 0) {
             $shippingWeight = 0.1;
         }
         for ($i = 0; $i < $shippingNumBoxes; $i++) {
             $request['RequestedShipment']['RequestedPackageLineItems'][] = array('Weight' => array('Value' => $shippingWeight, 'Units' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_WEIGHT), 'GroupPackageCount' => 1);
         }
     }
     $request['RequestedShipment']['PackageCount'] = $shippingNumBoxes;
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_SATURDAY == 'true') {
         $request['RequestedShipment']['ServiceOptionType'] = 'SATURDAY_DELIVERY';
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_SIGNATURE_OPTION >= 0 && $totals >= MODULE_SHIPPING_FEDEX_WEB_SERVICES_SIGNATURE_OPTION) {
         $request['RequestedShipment']['SpecialServicesRequested'] = 'SIGNATURE_OPTION';
     }
     try {
         $response = $client->getRates($request);
         if (!empty($response) && ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR' && !empty($response->RateReplyDetails))) {
             if (is_object($response->RateReplyDetails)) {
                 $response->RateReplyDetails = get_object_vars($response->RateReplyDetails);
             }
             //echo '<pre>';
             //print_r($response->RateReplyDetails);
             //echo '</pre>';
             switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
                 case 0:
                     $show_box_weight = '';
                     break;
                 case 1:
                     $show_box_weight = ' (' . $shippingNumBoxes . ' ' . TEXT_SHIPPING_BOXES . ')';
                     break;
                 case 2:
                     $show_box_weight = ' (' . number_format($shippingWeight * $shippingNumBoxes, 2) . tra('lbs') . ')';
                     break;
                 default:
                     $show_box_weight = ' (' . $shippingNumBoxes . ' x ' . number_format($shippingWeight, 2) . tra('lbs') . ')';
                     break;
             }
             $this->quotes = array('id' => $this->code, 'module' => $this->title, 'info' => $this->info(), 'weight' => $show_box_weight);
             $methods = array();
             foreach ($response->RateReplyDetails as $rateReply) {
                 if (array_key_exists($rateReply->ServiceType, $this->types) && (empty($pShipHash['method']) || str_replace('_', '', $rateReply->ServiceType) == $pShipHash['method'])) {
                     $cost = NULL;
                     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_RATES == 'LIST') {
                         foreach ($rateReply->RatedShipmentDetails as $ShipmentRateDetail) {
                             if ($ShipmentRateDetail->ShipmentRateDetail->RateType == 'PAYOR_LIST_PACKAGE') {
                                 $cost = $ShipmentRateDetail->ShipmentRateDetail->TotalNetCharge->Amount;
                                 $cost = (double) round(preg_replace('/[^0-9.]/', '', $cost), 2);
                             }
                         }
                     } else {
                         $cost = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
                         $cost = (double) round(preg_replace('/[^0-9.]/', '', $cost), 2);
                     }
                     $methods[] = array('id' => str_replace('_', '', $rateReply->ServiceType), 'title' => ucwords(strtolower(str_replace('_', ' ', $rateReply->ServiceType))), 'cost' => $cost + (strpos($this->types[$rateReply->ServiceType]['handling_fee'], '%') ? $cost * (double) $this->types[$rateReply->ServiceType]['handling_fee'] / 100 : (double) $this->types[$rateReply->ServiceType]['handling_fee']), 'code' => $this->types[$rateReply->ServiceType]['code']);
                 }
             }
             $this->quotes['methods'] = $methods;
             if ($this->tax_class > 0) {
                 $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['countries_id'], $order->delivery['zone_id']);
             }
         } else {
             $message = '';
             if (is_array($response->Notifications)) {
                 foreach ($response->Notifications as $notification) {
                     $message .= tra($notification->Severity) . ': ' . tra($notification->Message);
                 }
             } elseif (is_object($response->Notifications)) {
                 $message .= tra($response->Notifications->Severity) . ': ' . tra($response->Notifications->Message);
             }
         }
     } catch (Exception $e) {
         $message = $e->getMessage();
     }
     if (!empty($message)) {
         $this->quotes = array('module' => $this->title, 'error' => $message);
     }
     if (!empty($this->icon)) {
         $this->quotes['icon'] = $this->icon;
     }
     return $this->quotes;
 }
开发者ID:bitweaver,项目名称:commerce,代码行数:101,代码来源:fedexwebservices.php

示例9: getFedexShippingCost

 public function getFedexShippingCost($wsParams)
 {
     // Check config
     if (!Configuration::get('FEDEX_CARRIER_API_KEY')) {
         return array('connect' => false, 'cost' => 0);
     }
     // Check if class Soap is available
     if (!extension_loaded('soap')) {
         return array('connect' => false, 'cost' => 0);
     }
     // Getting module directory
     $dir = dirname(__FILE__);
     if (preg_match('/classes/i', $dir)) {
         $dir .= '/../modules/fedexcarrier/';
     }
     // Enable Php Soap
     ini_set("soap.wsdl_cache_enabled", "0");
     $client = new SoapClient($dir . '/RateService_v10.wsdl', array('trace' => 1));
     // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
     // Country / State
     $shipper_country = Db::getInstance()->getRow('SELECT `iso_code` FROM `' . _DB_PREFIX_ . 'country` WHERE `id_country` = ' . (int) Configuration::get('FEDEX_CARRIER_COUNTRY'));
     $shipper_state = Db::getInstance()->getRow('SELECT `iso_code` FROM `' . _DB_PREFIX_ . 'state` WHERE `id_state` = ' . (int) Configuration::get('FEDEX_CARRIER_STATE'));
     // Generating soap request
     $request['WebAuthenticationDetail']['UserCredential'] = array('Key' => Configuration::get('FEDEX_CARRIER_API_KEY'), 'Password' => Configuration::get('FEDEX_CARRIER_PASSWORD'));
     $request['ClientDetail'] = array('AccountNumber' => Configuration::get('FEDEX_CARRIER_ACCOUNT'), 'MeterNumber' => Configuration::get('FEDEX_CARRIER_METER'));
     $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Available Services Request v10 using PHP ***');
     $request['Version'] = array('ServiceId' => 'crs', 'Major' => '10', 'Intermediate' => '0', 'Minor' => '0');
     $request['ReturnTransitAndCommit'] = true;
     $request['RequestedShipment']['DropoffType'] = Configuration::get('FEDEX_CARRIER_PICKUP_TYPE');
     // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
     $request['RequestedShipment']['ShipTimestamp'] = date('c');
     $request['RequestedShipment']['ServiceType'] = $wsParams['service'];
     // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
     $request['RequestedShipment']['PackagingType'] = Configuration::get('FEDEX_CARRIER_PACKAGING_TYPE');
     // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
     // Service Type and Packaging Type are not passed in the request
     $request['RequestedShipment']['Shipper']['Address'] = array('StreetLines' => $wsParams['shipper_address1'], 'City' => $wsParams['shipper_city'], 'StateOrProvinceCode' => $wsParams['shipper_state_iso'], 'PostalCode' => $wsParams['shipper_postalcode'], 'CountryCode' => $wsParams['shipper_country_iso']);
     $request['RequestedShipment']['Recipient']['Address'] = array('StreetLines' => $wsParams['recipient_address1'], 'City' => $wsParams['recipient_city'], 'StateOrProvinceCode' => $wsParams['recipient_state_iso'], 'PostalCode' => $wsParams['recipient_postalcode'], 'CountryCode' => $wsParams['recipient_country_iso']);
     $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => Configuration::get('FEDEX_CARRIER_ACCOUNT'), 'CountryCode' => 'US'));
     $request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     $request['RequestedShipment']['PackageCount'] = '2';
     $count = 1;
     foreach ($wsParams['package_list'] as $p) {
         $request['RequestedShipment']['RequestedPackageLineItems'][] = array('SequenceNumber' => $count, 'GroupPackageCount' => $count, 'Weight' => array('Value' => $p['weight'], 'Units' => substr($this->_weightUnit, 0, 2)), 'Dimensions' => array('Length' => $p['depth'], 'Width' => $p['width'], 'Height' => $p['height'], 'Units' => $this->_dimensionUnit));
         $count++;
     }
     $request['RequestedShipment']['PackageCount'] = count($request['RequestedShipment']['RequestedPackageLineItems']);
     // Get Rates
     try {
         $resultTab = $client->getRates($request);
     } catch (Exception $e) {
     }
     // Check currency
     $conversionRate = 1;
     if (isset($resultTab->RateReplyDetails->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Currency)) {
         $id_currency_return = Db::getInstance()->getValue('SELECT `id_currency` FROM `' . _DB_PREFIX_ . 'currency` WHERE `iso_code` = \'' . pSQL($resultTab->RateReplyDetails->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Currency) . '\'');
         $conversionRate = $this->getCartCurrencyRate($id_currency_return, (int) $wsParams['id_cart']);
     }
     // Return results
     if (isset($resultTab->HighestSeverity) && $resultTab->HighestSeverity != 'ERROR' && isset($resultTab->RateReplyDetails->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount)) {
         return array('connect' => true, 'cost' => number_format($resultTab->RateReplyDetails->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, '.', ',') * $conversionRate);
     }
     if (isset($resultTab->HighestSeverity) && $resultTab->HighestSeverity == 'ERROR') {
         $this->_webserviceError = $this->l('Error') . ' ' . (isset($resultTab->Notifications->Code) ? $resultTab->Notifications->Code : '') . ' : ' . (isset($resultTab->Notifications->Message) ? $resultTab->Notifications->Message : '');
     } else {
         $this->_webserviceError = $this->l('Fedex Webservice seems to be down, please wait a few minutes and try again.');
     }
     return array('connect' => false, 'cost' => 0);
 }
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:70,代码来源:fedexcarrier.php

示例10: get_result

 private function get_result($request)
 {
     $this->debug('FedEx REQUEST: <a href="#" class="debug_reveal">Reveal</a><pre class="debug_info" style="background:#EEE;border:1px solid #DDD;padding:5px;">' . print_r($request, true) . '</pre>');
     $client = new SoapClient(plugin_dir_path(dirname(__FILE__)) . 'fedex-wsdl/' . ($this->production ? 'production' : 'test') . '/RateService_v' . $this->rateservice_version . '.wsdl', array('trace' => 1));
     $result = $client->getRates($request);
     $this->debug('FedEx RESPONSE: <a href="#" class="debug_reveal">Reveal</a><pre class="debug_info" style="background:#EEE;border:1px solid #DDD;padding:5px;">' . print_r($result, true) . '</pre>');
     wc_enqueue_js("\n\t\t\tjQuery('a.debug_reveal').on('click', function(){\n\t\t\t\tjQuery(this).closest('div').find('.debug_info').slideDown();\n\t\t\t\tjQuery(this).remove();\n\t\t\t\treturn false;\n\t\t\t});\n\t\t\tjQuery('pre.debug_info').hide();\n\t\t");
     return $result;
 }
开发者ID:taeche,项目名称:SoDoEx,代码行数:9,代码来源:class-wf-fedex-woocommerce-shipping.php

示例11: date

$request['RequestedShipment']['ShipTimestamp'] = date('c');
$request['RequestedShipment']['ServiceType'] = 'INTERNATIONAL_PRIORITY';
// 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' => 100, 'Currency' => 'USD');
$request['RequestedShipment']['Shipper'] = addShipper();
$request['RequestedShipment']['Recipient'] = addRecipient();
$request['RequestedShipment']['ShippingChargesPayment'] = addShippingChargesPayment();
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = addPackageLineItem1();
try {
    if (setEndpoint('changeEndpoint')) {
        $newLocation = $client->__setLocation(setEndpoint('endpoint'));
    }
    $response = $client->getRates($request);
    if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
        $rateReply = $response->RateReplyDetails;
        echo '<table border="1">';
        echo '<tr><td>Service Type</td><td>Amount</td><td>Delivery Date</td></tr><tr>';
        $serviceType = '<td>' . $rateReply->ServiceType . '</td>';
        if ($rateReply->RatedShipmentDetails && is_array($rateReply->RatedShipmentDetails)) {
            $amount = '<td>$' . number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",") . '</td>';
        } elseif ($rateReply->RatedShipmentDetails && !is_array($rateReply->RatedShipmentDetails)) {
            $amount = '<td>$' . number_format($rateReply->RatedShipmentDetails->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",") . '</td>';
        }
        // endif
        if (array_key_exists('DeliveryTimestamp', $rateReply)) {
            $deliveryDate = '<td>' . $rateReply->DeliveryTimestamp . '</td>';
        } else {
            if (array_key_exists('TransitTime', $rateReply)) {
开发者ID:rubaiet,项目名称:fedex,代码行数:31,代码来源:RateWebServiceClient.php

示例12: total

 /**
  * Based on passed address information, calculates the total shipping cost
  *
  * @param $fields
  * @param $cart
  * @param string $country
  * @param string $zipcode
  * @param string $state
  * @param string $city
  * @param string $address2
  * @param string $address1
  * @param string $company
  * @param string $lname
  * @param string $fname
  * @return array|bool
  */
 public function total($fields, $cart, $country = '', $zipcode = '', $state = '', $city = '', $address2 = '', $address1 = '', $company = '', $lname = '', $fname = '')
 {
     $config = $this->getConfigValues(get_class($this));
     $weight = $cart->Weight;
     if (_xls_get_conf('WEIGHT_UNIT', 'lb') != 'lb') {
         $weight = $weight * 2.2;
     }
     // one KG is 2.2 pounds
     $length = $cart->Length;
     $width = $cart->Width;
     $height = $cart->Height;
     if (_xls_get_conf('DIMENSION_UNIT', 'in') != 'in') {
         $length = round($length / 2.54);
         $width = round($width / 2.54);
         $height = round($height / 2.54);
     }
     if ($length < 1 && $length > 0) {
         $length = 1;
     }
     if ($width < 1 && $width > 0) {
         $width = 1;
     }
     if ($height < 1 && $height > 0) {
         $height = 1;
     }
     if (empty($config['securitycode']) || empty($config['accnumber']) || empty($config['meternumber'])) {
         return FALSE;
     }
     $ret = array();
     $newline = "<br />";
     //The WSDL is not included with the sample code.
     //Please include and reference in $path_to_wsdl variable.
     $path_to_wsdl = dirname(__FILE__) . "/RateService_v7.wsdl";
     ini_set("soap.wsdl_cache_enabled", "0");
     $client = new SoapClient($path_to_wsdl, array('trace' => 1));
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $config['authkey'], 'Password' => $config['securitycode']));
     $request['ClientDetail'] = array('AccountNumber' => $config['accnumber'], 'MeterNumber' => $config['meternumber']);
     $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v7 using PHP ***');
     $request['Version'] = array('ServiceId' => 'crs', 'Major' => '7', 'Intermediate' => '0', 'Minor' => '0');
     $request['ReturnTransitAndCommit'] = true;
     $request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP';
     // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
     $request['RequestedShipment']['ShipTimestamp'] = date('c');
     //Uncomment these additional options below if they are needed for your shipments
     //$request['RequestedShipment']['SpecialServicesRequested'] = array( 'SpecialServiceTypes' => array('SIGNATURE_OPTION'), 'SignatureOptionDetail' => array('OptionType' => 'ADULT'));
     //$request['RequestedShipment']['SignatureOptionDetail']['OptionType'] = 'ADULT';
     //$request['RequestedShipment']['ServiceType'] = 'PRIORITY_OVERNIGHT'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
     $config['origincountry'] = Country::CodeById($config['origincountry']);
     $config['originstate'] = State::CodeById($config['originstate']);
     if ($config['origincountry'] != "CA" && $config['origincountry'] != "US") {
         //Only required for these countries
         $config['originstate'] = "";
     }
     $request['RequestedShipment']['PackagingType'] = $config['packaging'];
     $request['RequestedShipment']['Shipper'] = array('Address' => array('StreetLines' => array($config['originadde']), 'City' => $config['origincity'], 'StateOrProvinceCode' => $config['originstate'], 'PostalCode' => $config['originpostcode'], 'CountryCode' => $config['origincountry']));
     if ($country != "CA" && $country != "US") {
         //Only required for these countries
         $state = "";
     }
     $request['RequestedShipment']['Recipient'] = array('Address' => array('StreetLines' => array($address1, $address2), 'City' => $city, 'StateOrProvinceCode' => $state, 'PostalCode' => $zipcode, 'CountryCode' => $country, 'Residential' => $this->CheckoutForm->shippingResidential == 1 ? 1 : 0));
     $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => $config['accnumber'], 'CountryCode' => $config['origincountry']));
     $request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     if ($config['origincountry'] != $country && $config['customs'] == "CLEARANCEFEE") {
         $request['RequestedShipment']['InternationalDetail'] = array('CustomsValue' => array('Amount' => $cart->subtotal, 'Currency' => _xls_get_conf('CURRENCY_DEFAULT', 'USD')));
     }
     $request['RequestedShipment']['PackageCount'] = '1';
     $request['RateRequest']['CurrencyType'] = _xls_get_conf('CURRENCY_DEFAULT', 'USD');
     $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
     if ($length + $width + $height == 0) {
         $request['RequestedShipment']['RequestedPackageLineItems'] = array('0' => array('SequenceNumber' => '1', 'InsuredValue' => array('Amount' => $cart->subtotal, 'Currency' => _xls_get_conf('CURRENCY_DEFAULT', 'USD')), 'ItemDescription' => 'Ordered items', 'Weight' => array('Value' => $weight, 'Units' => 'LB'), 'CustomerReferences' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => _xls_get_conf('STORE_NAME', 'Web Order'))));
     } else {
         $request['RequestedShipment']['RequestedPackageLineItems'] = array('0' => array('SequenceNumber' => '1', 'InsuredValue' => array('Amount' => $cart->subtotal, 'Currency' => _xls_get_conf('CURRENCY_DEFAULT', 'USD')), 'ItemDescription' => 'Ordered items', 'Weight' => array('Value' => $weight, 'Units' => 'LB'), 'Dimensions' => array('Length' => $length, 'Width' => $width, 'Height' => $height, 'Units' => 'IN'), 'CustomerReferences' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => _xls_get_conf('STORE_NAME', 'Web Order'))));
     }
     try {
         $response = $client->getRates($request);
         Yii::log(get_class($this) . " sending " . print_r($request, true), $this->logLevel, 'application.' . __CLASS__ . "." . __FUNCTION__);
         Yii::log(get_class($this) . " receiving " . print_r($response, true), $this->logLevel, 'application.' . __CLASS__ . "." . __FUNCTION__);
         if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
             if (isset($response->RateReplyDetails)) {
                 if (is_array($response->RateReplyDetails) === false) {
                     $response->RateReplyDetails = array($response->RateReplyDetails);
                 }
                 foreach ($response->RateReplyDetails as $rateReply) {
//.........这里部分代码省略.........
开发者ID:uiDeveloper116,项目名称:webstore,代码行数:101,代码来源:fedex.php

示例13: fwd_fedex_rates

/**
 * Get FedEx rate quotes.
 */
function fwd_fedex_rates($params, $settings)
{
    // Configurable FedEx service methods.
    $service_list = array('FEDEX_GROUND' => 'Fedex Ground', 'FEDEX_EXPRESS_SAVER' => 'Fedex Express Saver', 'FEDEX_2_DAY' => 'Fedex 2-Day Air', 'FEDEX_2_DAY_AM' => 'Fedex 2-Day Air A.M.', 'STANDARD_OVERNIGHT' => 'Fedex Standard Overnight', 'PRIORITY_OVERNIGHT' => 'Fedex Priority Overnight', 'FIRST_OVERNIGHT' => 'Fedex First Overnight', 'INTERNATIONAL_PRIORITY' => 'Fedex Priority International');
    // If params are empty, return available methods only.
    if (empty($params)) {
        $methods = array();
        foreach ((array) $settings['methods'] as $key => $method) {
            if ($method) {
                $method = is_array($method) ? $method : array();
                $methods[] = array('id' => $key, 'name' => $method['name'] ?: $service_list[$key]);
            }
        }
        return $methods;
    }
    // Get shipper, default or specific.
    $shipper = array_merge(array('package_weight' => 100), (array) $settings['shippers'][0], (array) $settings['shippers'][$params['shipper']]);
    // Disable WSDL caching.
    ini_set('soap.wsdl_cache_enabled', '0');
    // Create SOAP client with Fedex RateService WSDL.
    $client = new SoapClient(dirname(__FILE__) . '/wsdl/RateService_v10.wsdl', array('trace' => 1));
    // Set endpoint host?
    if ($settings['host']) {
        $client->__setLocation($settings['host']);
    }
    // Split package by weight limit?
    if ($shipper['package_weight'] && $params['weight'] > $shipper['package_weight']) {
        $num_packages = ceil($params['weight'] / $shipper['package_weight']);
        for ($i = 0; $i < $num_packages; $i++) {
            if ($i >= 200) {
                break;
            }
            $params['packages'][$i] = array('insurance_amount' => $params['insurance_amount'] / $num_packages, 'insurance_currency' => $params['insurance_currency'], 'weight' => $params['weight'] / $num_packages, 'units' => $params['units']);
        }
    }
    // Setup request.
    $request = array('WebAuthenticationDetail' => array('UserCredential' => array('Key' => $settings['key'], 'Password' => $settings['password'])), 'ClientDetail' => array('AccountNumber' => $settings['account'], 'MeterNumber' => $settings['meter']), 'TransactionDetail' => array('CustomerTransactionId' => '*** Rate Request v10 using PHP ***'), 'Version' => array('ServiceId' => 'crs', 'Major' => '10', 'Intermediate' => '0', 'Minor' => '0'), 'ReturnTransitAndCommit' => true, 'RequestedShipment' => array('DropoffType' => 'REGULAR_PICKUP', 'ShipTimestamp' => date('c'), 'PackagingType' => 'YOUR_PACKAGING', 'Shipper' => array('Address' => array('StreetLines' => array($shipper['address']), 'City' => $shipper['city'], 'StateOrProvinceCode' => $shipper['state'], 'PostalCode' => $shipper['zip'], 'CountryCode' => $shipper['country'] ?: 'US')), 'Recipient' => array('Address' => array('StreetLines' => array($params['address']), 'City' => $params['city'], 'StateOrProvinceCode' => $params['state'], 'PostalCode' => $params['zip'], 'CountryCode' => $params['country'] ?: 'US')), 'ShippingChargesPayment' => array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => $shipper['account'] ?: $settings['account'], 'CountryCode' => $shipper['country'] ?: 'US')), 'RateRequestTypes' => 'ACCOUNT', 'RateRequestTypes' => 'LIST', 'PackageCount' => $params['packages'] ? count($params['packages']) : '1', 'RequestedPackages' => array()));
    // Default single package?
    if (count($params['packages']) == 0) {
        $params['packages'][0] = array('insurance_amount' => $params['insurance_amount'], 'insurance_currency' => $params['insurance_currency'], 'weight' => $params['weight'] ?: 1, 'units' => $params['units']);
        if ($params['dimensions']) {
            $params['packages'][0]['dimensions'] = array('length' => $params['dimensions']['length'], 'width' => $params['dimensions']['width'], 'height' => $params['dimensions']['height'], 'units' => $params['dimensions']['units']);
        }
    }
    // Add package(s) to request.
    foreach ($params['packages'] as $seq => $package) {
        $request['RequestedShipment']['RequestedPackageLineItems'][$seq] = array('SequenceNumber' => $seq + 1, 'GroupPackageCount' => 1, 'InsuredValue' => array('Amount' => $package['insurance_amount'] ?: 0, 'Currency' => $package['insurance_currency'] ?: 'USD'), 'Weight' => array('Value' => $package['weight'], 'Units' => $package['units'] ?: 'LB'));
        // Dimensions?
        if ($package['dimensions']) {
            $request['RequestedShipment']['RequestedPackageLineItems'][$seq]['Dimensions'] = array('Length' => $package['dimensions']['length'], 'Width' => $package['dimensions']['width'], 'Height' => $package['dimensions']['height'], 'Units' => $package['dimensions']['units'] ?: 'IN');
        }
    }
    // Try the request.
    try {
        $response = $client->getRates($request);
        if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
            if (!is_array($response->RateReplyDetails)) {
                $response->RateReplyDetails = array($response->RateReplyDetails);
            }
            foreach ($response->RateReplyDetails as $RateReplyDetail) {
                $service_type = $RateReplyDetail->ServiceType;
                if ($service_list[$service_type]) {
                    $rsd = end($RateReplyDetail->RatedShipmentDetails);
                    $tnc = $rsd->ShipmentRateDetail->TotalNetCharge;
                    $price = (double) preg_replace('/[^\\d\\.]/i', '', $tnc->Amount);
                    // Markup?
                    if ($settings['markup']) {
                        $price = Discounts::apply_value($price, '+' . $settings['markup']);
                    }
                    // Discount?
                    if ($settings['discount']) {
                        $price = Discounts::apply_value($price, $settings['markup']);
                    }
                    // Rated method configured/available?
                    if ($method = $settings['methods'][$service_type]) {
                        $method = is_array($method) ? $method : array();
                        $service_name = $method['name'] ?: $service_list[$service_type];
                        $service_price = round($price, 2);
                        $shipment_rates[] = array('id' => $service_type, 'name' => $service_name, 'price' => $service_price);
                    }
                }
            }
        } elseif ($response->HighestSeverity == 'FAILURE' || $response->HighestSeverity == 'ERROR') {
            throw new Exception($response->Notifications->LocalizedMessage ?: $response->Notifications->Message);
        }
    } catch (SoapFault $e) {
        throw new Exception($e->getMessage());
    }
    return $shipment_rates;
}
开发者ID:kfuchs,项目名称:fwdcommerce,代码行数:93,代码来源:fwd-fedex.php

示例14: _processRequest

 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 {
//.........这里部分代码省略.........
开发者ID:harshzalavadiya,项目名称:fatak,代码行数:101,代码来源:default_fedex.php

示例15: quote


//.........这里部分代码省略.........
                     $values['weight'] = 0.1;
                 }
                 $new_shipping_weight += $values['weight'];
                 $request['RequestedShipment']['RequestedPackageLineItems'][] = array('Weight' => array('Value' => $values['weight'], 'Units' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_WEIGHT));
             }
         }
         $shipping_num_boxes = $new_shipping_num_boxes;
         if (!$shipping_num_boxes || $shipping_num_boxes == 0) {
             $shipping_num_boxes = 1;
         }
         $shipping_weight = round($new_shipping_weight / $shipping_num_boxes, 2);
     } else {
         // Zen Cart default method for calculating number of packages
         if ($shipping_weight == 0) {
             $shipping_weight = 0.1;
         }
         for ($i = 0; $i < $shipping_num_boxes; $i++) {
             $request['RequestedShipment']['RequestedPackageLineItems'][] = array('Weight' => array('Value' => $shipping_weight, 'Units' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_WEIGHT));
         }
     }
     $request['RequestedShipment']['PackageCount'] = $shipping_num_boxes;
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_SATURDAY == 'true') {
         $request['RequestedShipment']['ServiceOptionType'] = 'SATURDAY_DELIVERY';
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_SIGNATURE_OPTION >= 0 && $totals >= MODULE_SHIPPING_FEDEX_WEB_SERVICES_SIGNATURE_OPTION) {
         $request['RequestedShipment']['SpecialServicesRequested'] = 'SIGNATURE_OPTION';
     }
     // echo '<!-- shippingWeight: ' . $shipping_weight . ' ' . $shipping_num_boxes . ' -->';
     // echo '<!-- ';
     // echo '<pre>';
     // print_r($request);
     // echo '</pre>';
     // echo ' -->';
     $response = $client->getRates($request);
     // echo '<!-- ';
     // echo '<pre>';
     // print_r($response);
     // echo '</pre>';
     // echo ' -->';
     if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR' && is_array($response->RateReplyDetails) || is_object($response->RateReplyDetails)) {
         if (is_object($response->RateReplyDetails)) {
             $response->RateReplyDetails = get_object_vars($response->RateReplyDetails);
         }
         // echo '<pre>';
         // print_r($response->RateReplyDetails);
         // echo '</pre>';
         $show_box_weight = " (Total items: " . $shipping_num_boxes . ' pcs. Total weight: ' . number_format($shipping_weight * $shipping_num_boxes, 2) . ' ' . strtolower(MODULE_SHIPPING_FEDEX_WEB_SERVICES_WEIGHT) . 's.)';
         $this->quotes = array('id' => $this->code, 'module' => $this->title . $show_box_weight, 'info' => $this->info());
         // echo '<pre>';
         // print_r($response->RateReplyDetails);
         // echo '</pre>';
         // EXIT();
         $methods = array();
         // echo '<pre>';
         // print_r($this->types);
         // echo '</pre>';
         foreach ($response->RateReplyDetails as $rateReply) {
             if (array_key_exists($rateReply->ServiceType, $this->types) && ($method == '' || str_replace('_', '', $rateReply->ServiceType) == $method)) {
                 if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_RATES == 'LIST') {
                     foreach ($rateReply->RatedShipmentDetails as $ShipmentRateDetail) {
                         if ($ShipmentRateDetail->ShipmentRateDetail->RateType == 'PAYOR_LIST_PACKAGE') {
                             $cost = $ShipmentRateDetail->ShipmentRateDetail->TotalNetCharge->Amount;
                             $cost = (double) round(preg_replace('/[^0-9.]/', '', $cost), 2);
                         }
                     }
                 } else {
开发者ID:digideskio,项目名称:oscmax2,代码行数:67,代码来源:fedexwebservices.php


注:本文中的SoapClient::getRates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。