/** * 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'; }
} 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; // remove shipment data from the shipping manifest $delete_manifest_query = tep_db_query("delete from " . TABLE_SHIPPING_MANIFEST . " where orders_id = '" . $order . "'"); if ($delete_manifest_query) { } elseif (!$delete_manifest_query) { echo COULD_NOT_DELETE_ENTRIES; } // cancel the shipment $cancelRet = $fed->cancel_ground($cancelData); // todo: add appropriate error checking for at least some of the possible errors if ($error = $fed->getError()) { die(ERROR . $error); } // delete the tracking number from the order record $delete_trackNum = array('fedex_tracking' => ''); tep_db_perform(TABLE_ORDERS, $delete_trackNum, 'update', "orders_id = '" . $order . "'"); // ...mark the order record "pending"... $update_status = array('orders_status' => 2); tep_db_perform(TABLE_ORDERS, $update_status, 'update', "orders_id = '" . $order . "'"); // ...add a comment to the order history to show what we've done... $fedex_comments = ORDER_HISTORY_CANCELLED . $trackNum; tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) values ('" . $order . "', 2, now(), '', '" . $fedex_comments . "')"); // ...delete the record from the manifest... tep_db_query("delete from " . TABLE_SHIPPING_MANIFEST . " where orders_id = '" . $order . "'"); // ...and refresh the orders page tep_redirect(FILENAME_ORDERS . '?oID=' . $order);
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; }
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; }
protected function FedExCancel() { // Create the new Fedex object if ($this->objFedexShipment->ShippingAccountId) { $fed = new FedExDC($this->objFedexShipment->ShippingAccount->AccessId, $this->objFedexShipment->ShippingAccount->AccessCode); } else { // if not billing to a sender account, use the default fedex account from admin_setting for FedEx communication $objFedexAccount = ShippingAccount::Load(QApplication::$TracmorSettings->FedexAccountId); $fed = new FedExDC($objFedexAccount->AccessId, $objFedexAccount->AccessCode); } // create new FedExDC object //$fed = new FedExDC($this->objShipment->ShippingAccount->Value, QApplication::$TracmorSettings->FedexMeterNumber); // Populate an array with the necessary information $fdx_arr = array(1 => $this->objShipment->ShipmentNumber, 29 => $this->objShipment->TrackingNumber); // If ground service // if($this->objShipment->FedexServiceType->Value == '92') if ($this->objFedexShipment->FedexServiceType->Value == '92') { $cancel_Ret = $fed->ground_cancel($fdx_arr); } else { $cancel_Ret = $fed->express_cancel($fdx_arr); } // If there is an error, display it and return false if ($error = $fed->getError()) { $this->btnCancelCompleteShipment->Warning = $error; return false; } else { return true; } }