/** * 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'; }
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>";