/** * Get FedEx meter number */ function fn_settings_actions_shippings_fedex_fedex_meter_get(&$new_value, $old_value) { if ($new_value != 'Y') { return false; } echo "Retreiving information from FEDEX server..."; fn_flush(); include_once DIR_SHIPPING_FILES . 'fedex/fedexdc.php'; $shipping_settings = fn_get_settings('Shippings', 'fedex'); $account_number = $shipping_settings['account_number']; $params = array('fedex_uri' => $shipping_settings['test_mode'] == 'Y' ? 'https://gatewaybeta.fedex.com:443/GatewayDC' : 'https://gateway.fedex.com:443/GatewayDC'); $fed = new FedExDC($shipping_settings['account_number'], '', $params); $ship_ret = $fed->subscribe(array(1 => uniqid(TIME), 4003 => $shipping_settings['fedex_meter_name'], 4008 => $shipping_settings['fedex_meter_street'], 4011 => $shipping_settings['fedex_meter_city'], 4012 => $shipping_settings['fedex_meter_state'], 4013 => $shipping_settings['fedex_meter_zipcode'], 4014 => $shipping_settings['fedex_meter_country'], 4015 => $shipping_settings['fedex_meter_phone'])); echo "<br />Done."; fn_flush(); $error_tr = $fed->lookup('transaction_error_message'); $error_req = $fed->getError(); if ($error_tr || $error_req) { fn_set_notification('E', fn_get_lang_var('error'), (!empty($error_req) ? $error_req . '<br />' : '') . (!empty($error_tr) ? $error_tr : '')); } else { $meter_number = $fed->lookup('meter_number'); db_query("UPDATE ?:settings SET ?u WHERE option_name = 'meter_number' AND section_id = 'Shippings' AND subsection_id = 'fedex'", array('value' => $meter_number)); } $new_value = 'N'; }
$fedex_vars = array(10 => 'MODULE_SHIPPING_FEDEX1_ACCOUNT', 498 => 'MODULE_SHIPPING_FEDEX1_METER'); // determine if we're using test or production gateway $value_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FEDEX1_SERVER'"); $value = tep_db_fetch_array($value_query); $fedex_gateway = $value['configuration_value']; $i = 0; $fedex_keys = array_keys($fedex_vars); foreach ($fedex_vars as $var) { $value_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = '" . $var . "'"); $value = tep_db_fetch_array($value_query); $value = $value['configuration_value']; $fedex_vars[$fedex_keys[$i]] = $value; $i++; } // create new FedExDC object $fed = new FedExDC($fedex_vars[10], $fedex_vars[498]); // get the tracking number from the order record $fedex_tracking_query = tep_db_query("select fedex_tracking from " . TABLE_ORDERS . " where orders_id = '" . $order . "'"); $r = tep_db_fetch_array($fedex_tracking_query); $fedex_tracking = $r['fedex_tracking']; // get the shipment type from the shipping manifest $ship_type_query = tep_db_query("select shipping_type from " . TABLE_SHIPPING_MANIFEST . " where orders_id = '" . $order . "'"); $ship_type = tep_db_fetch_array($ship_type_query); if ($ship_type['shipping_type'] == 90 or $ship_type['shipping_type'] == 92) { $ship_type = 'FDXG'; } else { $ship_type = 'FDXE'; } // simple array with transaction code, tracking number, carrier code $cancelData = array(0 => $transaction_code, 1 => ORDER_NUMBER . $order, 29 => $fedex_tracking, 3025 => $ship_type); $cancelData = $fedex_keys + $cancelData;
function update_meter_number() { global $vendor_name, $vendor_address, $vendor_city, $vendor_state, $vendor_zip, $vendor_country_2_code, $vendor_phone, $vmLogger; $fed = new FedExDC(FEDEX_ACCOUNT_NUMBER); $db = new ps_DB(); $db->query('SELECT `contact_first_name`, `contact_last_name` FROM `#__{vm}_vendor` WHERE `vendor_id` =' . intval($_SESSION['ps_vendor_id'])); $db->next_record(); $aRet = $fed->subscribe(array(1 => uniqid('vmFed_'), 4003 => $db->f('contact_first_name') . ' ' . $db->f('contact_last_name'), 4008 => $vendor_address, 4011 => $vendor_city, 4012 => $vendor_state, 4013 => $vendor_zip, 4014 => $vendor_country_2_code, 4015 => $vendor_phone)); if ($error = $fed->getError()) { $vmLogger->err($error); return false; } $meter_number = $aRet[498]; foreach ($this->config_array as $config_key) { $d[$config_key] = constant($config_key); } $d['FEDEX_METER_NUMBER'] = $meter_number; $this->write_configuration($d); define('FEDEX_METER_NUMBER_TEMP', $meter_number); return true; }
function tep_ship_request($shipData, $ship_type, $order) { $fed = new FedExDC($shipData[0][10], $shipData[1][498]); $ship_Ret = $fed->{$ship_type}($shipData); // todo: add appropriate error checking for at least some of the possible errors if ($error = $fed->getError()) { // in case the ship date is a holiday, check for the error and correct the date // todo: correct the date! if (preg_match('/FF43/', $error)) { echo 'You cannot schedule a pickup on a weekend or holiday! Please go back and change the pickup date.'; die; } else { echo 'This transaction could not be completed. Please note the error message below.<br><br>'; die("ERROR: " . $error); } // if successful, we get the tracking number, write the label *.png file to images/fedex, // and display the label } else { $trackNum = $ship_Ret[29]; // decode and save label, named for the tracking number $fed->label(DIR_WS_FEDEX_LABELS . $trackNum . '.png'); } return $trackNum; }
<form name="track_fedex" action="<?php FILENAME_TRACK_FEDEX; ?> " method="get"><b> Tracking number: <input type="text" name="track"> <input type="submit" value="Submit"></b> </form> <?php } else { include DIR_WS_INCLUDES . 'fedexdc.php'; // get tracking number from form $tracking_number = $_GET['track']; // create new FedExDC object // For tracking results you do not need an account# or meter# $fed = new FedExDC(); //tracking $track_Ret = $fed->ref_track(array(1537 => $tracking_number)); // debug (prints array of all data returned) if ($debug) { echo '<pre>'; if ($error = $fed->getError()) { echo "ERROR :" . $error; } else { echo $fed->debug_str . "\n<BR>"; print_r($track_Ret); echo "\n\n"; for ($i = 1; $i <= $track_Ret[1584]; $i++) { echo PACKAGE_DELIVERED_ON . ' ' . $track_Ret['1720-' . $i]; echo '\\n' . PACKAGE_SIGNED_BY . $track_Ret['1706-' . $i]; }
function fn_fedex_ship($data, &$auth, $shipping_settings, $origination) { $ground_codes = array('90', '92'); $account_number = $shipping_settings['fedex']['account_number']; $meter_number = $shipping_settings['fedex']['meter_number']; $package_type = $shipping_settings['fedex']['package_type']; $drop_off_type = $shipping_settings['fedex']['drop_off_type']; $height = $shipping_settings['fedex']['height']; $width = $shipping_settings['fedex']['width']; $length = $shipping_settings['fedex']['length']; // Normalize supplier address data $origination_address1 = substr($origination['address'], 0, 32); preg_match_all("/[\\d\\w]/", $origination['zipcode'], $matches); $origination_postal = !empty($matches[0]) ? implode('', $matches[0]) : ''; preg_match_all("/[\\d]/", $origination['phone'], $matches); $origination_phone = !empty($matches[0]) ? implode('', $matches[0]) : '8001234567'; $origination_phone = strlen($origination_phone) >= 10 ? substr($origination_phone, 0, 10) : str_pad($origination_phone, 10, '0'); $origination_name = substr($origination['company'], 0, 35); $origination_city = $origination['city']; $origination_state = $origination['state']; $origination_country = $origination['country']; // Normalize customer address data $destination_address1 = substr($location['address'], 0, 32); preg_match_all("/[\\d\\w]/", $location['zipcode'], $matches); $destination_postal = !empty($matches[0]) ? implode('', $matches[0]) : ''; preg_match_all("/[\\d]/", $location['phone'], $matches); $destination_phone = !empty($matches[0]) ? implode('', $matches[0]) : ''; $destination_phone = strlen($destination_phone) >= 10 ? substr($destination_phone, 0, 10) : str_pad($destination_phone, 10, '0'); $destination_name = $location['firstname'] . ' ' . $location['lastname']; $destination_city = $location['city']; $destination_state = $location['state']; $destination_country = $location['country']; $is_domestic = $destination_country == $origination_country ? true : false; // define weight unit and value $weight_unit = 'LBS'; $weight_unit_short = 'LB'; $weight = $weight_data['full_pounds']; $fed = new FedExDC($account_number, $meter_number); $ship_data = array('weight_units' => $weight_unit, 11 => $destination_name, 13 => $destination_address1, 15 => $destination_city, 16 => $destination_state, 17 => $destination_postal, 18 => $destination_phone, 50 => $destination_country, 4 => $origination_name, 5 => $origination_address1, 7 => $origination_city, 8 => $origination_state, 9 => $origination_postal, 117 => $origination_country, 183 => $origination_phone, 57 => $height, 58 => $width, 59 => $length, 1116 => 'I', 1273 => $package_type, 1274 => $code, 23 => '1', 1333 => $drop_off_type, 1401 => $weight, 116 => '1', 68 => 'USD', 2399 => '1'); $today = getdate(TIME); if ($today['wday'] == 0 || $today['wday'] == 6) { // if today is saturday or sunday, set ship date manually $next_time = strtotime($today['wday'] == 0 ? "+1 day" : "+2 days"); $next_date = getdate($next_time); $ship_data[24] = $next_date['year'] . $next_date['month'] . $next_date['day']; } if ($is_domestic == false) { $customs_total = fn_format_price($_SESSION['cart']['total']); $ship_data[70] = 1; // INTL: who pay the duties (2 - recipient) $ship_data[79] = 'Good contents'; // INTL: description of content $ship_data[80] = $origination_country; // INTL: producer of goods $ship_data[82] = 1; // INTL: number of units in one good $ship_data[1408] = '1.000000'; // INTL: value of each unit $ship_data[414] = $weight_unit_short; // INTL: weight unit measure $ship_data[1407] = '0.1'; // INTL: weight of each unit $ship_data[1411] = $customs_total; // INTL: customs total } if (in_array($code, $ground_codes)) { if ($code == '90') { $ship_data[440] = 'Y'; } $ship_data[1119] = 'N'; $ship_data[2399] = '2'; // indirect signature // $ship_ret = $fed->ship_ground($ship_data); } else { // $ship_ret = $fed->ship_express($ship_data); } $ship_ret = $fed->rate_services($ship_data); $charge = $fed->lookup('net_charge_amount'); $result = array('cost' => $charge); if (!empty($charge)) { return $result; } else { if (defined('SHIPPING_DEBUG')) { return array('error' => $fed->getError()); } } return false; }
<?php // $Id: ship.php 5807 2008-08-26 09:27:03Z zeke $ /* Example express shipment request. */ include 'fedexdc.php'; // create new FedExDC object $fed = new FedExDC('318370788', '1054992'); // Ship example // You can either pass the FedEx tag value or the field name in the // $FE_RE array // This will send a ship express shipment to FedEx. FedEx will return // a bunch of data including a PNG image label. Accessed through $fed->label $ship_Ret = $fed->ship_express(array('weight_units' => 'LBS', 16 => 'Ma', 13 => '44 Main street', 5 => '312 stuart st', 1273 => '01', 1274 => '01', 18 => '6173335555', 15 => 'Boston', 23 => '1', 9 => '02134', 183 => '6175556985', 8 => 'MA', 117 => 'US', 17 => '02116', 50 => 'US', 4 => 'Vermonster LLC', 7 => 'Boston', 12 => 'Jay Powers', 1333 => '1', 1401 => '2.0', 116 => 1, 68 => 'USD', 1368 => 2, 1369 => 1, 1370 => 5, 2399 => 1)); echo "<PRE>"; if ($error = $fed->getError()) { die("ERROR: " . $error); } else { // decode and save label $fed->label('/tmp/myLabel.png'); echo $fed->debug_str . "\n<BR>"; echo "\n\n"; echo "Price \$" . $fed->lookup('net_charge_amount'); echo "\n"; echo "Tracking# " . $ship_Ret[29]; } echo "</PRE>";
protected function UpdateShipmentLabels() { $this->lblShipDate->Text = $this->objShipment->ShipDate->__toString(); $this->lblFromCompany->Text = $this->objShipment->FromCompany->__toStringWithLink(); $this->lblFromContact->Text = $this->objShipment->FromContact->__toStringWithLink(); $this->lblFromAddress->Text = $this->objShipment->FromAddress->__toStringWithLink(); $this->lblToCompany->Text = $this->objShipment->ToCompany->__toStringWithLink(); $this->lblToContact->Text = $this->objShipment->ToContact->__toStringWithLink(); $this->lblToAddress->Text = $this->objShipment->ToAddress->__toStringWithLink(); if (QApplication::$TracmorSettings->CustomShipmentNumbers) { $this->lblShipmentNumber->Text = $this->objShipment->ShipmentNumber; } $this->lblCourier->Text = $this->objShipment->CourierId ? $this->objShipment->Courier->__toString() : "Other"; $this->lblTrackingNumber->Text = $this->objShipment->__toStringTrackingNumber(); $this->pnlNote->Text = nl2br($this->objShipment->Transaction->Note); if ($this->objFedexShipment) { $this->lblToPhone->Text = $this->objFedexShipment->ToPhone; $this->lblBillTransportationTo->Text = $this->objFedexShipment->FedexServiceTypeId == 6 ? FedExDC::ground_pay_type($this->objFedexShipment->PayType) : FedExDC::express_pay_type($this->objFedexShipment->PayType); $this->lblPayerAccount->Text = $this->objFedexShipment->PayType === 1 ? $this->objFedexShipment->ShippingAccount->__toString() : $this->objFedexShipment->PayerAccountNumber; $this->lblReference->Text = $this->objFedexShipment->Reference; $this->lblFedexNotifySenderEmail->Text = $this->objFedexShipment->NotifySenderEmail; $this->lblFedexNotifyRecipientEmail->Text = $this->objFedexShipment->NotifyRecipientEmail; $this->lblFedexNotifyOtherEmail->Text = $this->objFedexShipment->NotifyOtherEmail; $this->lblFxServiceType->Text = $this->objFedexShipment->FedexServiceType ? $this->objFedexShipment->FedexServiceType->__toString() : ''; $this->lblPackageType->Text = $this->objFedexShipment->PackageType ? $this->objFedexShipment->PackageType->__toString() : ''; $this->lblPackageWeight->Text = $this->objFedexShipment->PackageWeight; $this->lblPackageLength->Text = $this->objFedexShipment->PackageLength; $this->lblPackageWidth->Text = $this->objFedexShipment->PackageWidth; $this->lblPackageHeight->Text = $this->objFedexShipment->PackageHeight; $this->lblValue->Text = $this->objFedexShipment->DeclaredValue; $this->lblWeightUnit->Text = $this->objFedexShipment->WeightUnit->__toString(); $this->lblLengthUnit->Text = $this->objFedexShipment->LengthUnit->__toString(); $this->lblCurrencyUnit->Text = $this->objFedexShipment->CurrencyUnit->__toString(); $this->lblHoldAtLocationAddress->Text = $this->objFedexShipment->HoldAtLocationAddress; $this->lblHoldAtLocationCity->Text = $this->objFedexShipment->HoldAtLocationCity; $this->lblHoldAtLocationState->Text = $this->objFedexShipment->HoldAtLocationStateObject ? $this->objFedexShipment->HoldAtLocationStateObject->__toString() : ''; $this->lblHoldAtLocationPostalCode->Text = $this->objFedexShipment->HoldAtLocationPostalCode; $this->lblFedexLabelPrinterType->Text = FedExDC::label_printer_type($this->objFedexShipment->LabelPrinterType); $this->lblFedexLabelFormatType->Text = FedExDC::label_format_type($this->objFedexShipment->LabelFormatType); $this->lblFedexThermalPrinterPort->Text = $this->objFedexShipment->ThermalPrinterPort; } // Update custom labels if ($this->arrCustomFields) { CustomField::UpdateLabels($this->arrCustomFields); } }
<?php //$Id: track.php 5807 2008-08-26 09:27:03Z zeke $ /* Example tracking request. */ include 'fedexdc.php'; // create new FedExDC object // For tracking results you do not need an account# or meter# $fed = new FedExDC(); //tracking example $track_Ret = $fed->ref_track(array('1537' => '790204649977', '1534' => 'Y')); echo '<pre>'; if ($error = $fed->getError()) { echo "ERROR :" . $error; } else { echo $fed->debug_str . "\n<BR>"; print_r($track_Ret); echo "\n\n"; for ($i = 1; $i <= $track_Ret[1584]; $i++) { echo "This package was deliverd on " . $track_Ret['1720-' . $i]; echo "\nSigned for by " . $track_Ret['1706-' . $i]; } } echo '</pre>';