function deleteLabel($shipment_id = '') { global $db, $messageStack; if (!$shipment_id) { $messageStack->add('Cannot delete shipment, shipment ID was not provided!', 'error'); return false; } if ($this->tracking_number) { $tracking_number = $this->tracking_number; } else { $shipments = $db->Execute("select ship_date, tracking_id from " . TABLE_SHIPPING_LOG . " where shipment_id = " . $shipment_id); $tracking_number = $shipments->fields['tracking_id']; } $strXML = $this->FormatUPSDeleteRequest($tracking_number); $this->labelDelRequest = $strXML; //echo 'Delete Request xmlString = ' . htmlspecialchars($strXML) . '<br />'; $url = MODULE_SHIPPING_UPS_TEST_MODE == 'Test' ? MODULE_SHIPPING_UPS_VOID_SHIPMENT_TEST : MODULE_SHIPPING_UPS_VOID_SHIPMENT; $SubmitXML = GetXMLString($strXML, $url, "POST"); $this->labelDelResponse = $SubmitXML['xmlString']; //echo 'Delete Request response string = ' . htmlspecialchars($SubmitXML['xmlString']) . '<br />'; // Check for XML request errors if ($SubmitXML['result'] == 'error') { $messageStack->add(SHIPPING_UPS_CURL_ERROR . $SubmitXML['message'], 'error'); return false; } $ResponseXML = $SubmitXML['xmlString']; $XMLFail = GetNodeData($ResponseXML, 'VoidShipmentResponse:Response:Error:ErrorCode'); // Check for errors returned from UPS $XMLWarn = GetNodeData($ResponseXML, 'VoidShipmentResponse:Response:Error:ErrorSeverity'); // Check for warnings returned from UPS (process continues) if ($XMLFail && $XMLWarn == 'Warning') { // soft error, report it and continue $messageStack->add('UPS Label Delete Warning # ' . $XMLFail . ' - ' . GetNodeData($ResponseXML, 'VoidShipmentResponse:Response:Error:ErrorDescription'), 'caution'); } elseif ($XMLFail && $XMLWarn != 'Warning') { // hard error - return with bad news $messageStack->add('UPS Label Delete Error # ' . $XMLFail . ' - ' . GetNodeData($ResponseXML, 'VoidShipmentResponse:Response:Error:ErrorDescription'), 'error'); return false; } // delete the label file $date = explode('-', $shipments->fields['ship_date']); $file_path = DIR_FS_MY_FILES . $_SESSION['company'] . '/shipping/labels/' . $this->code . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/'; if (file_exists($file_path . $shipments->fields['tracking_id'] . '.lpt')) { $file_name = $shipments->fields['tracking_id'] . '.lpt'; } elseif (file_exists($file_path . $shipments->fields['tracking_id'] . '.gif')) { $file_name = $shipments->fields['tracking_id'] . '.gif'; } else { $file_name = false; // file does not exist, skip } if ($file_name) { if (!unlink($file_path . $file_name)) { $messageStack->add_session('Trouble deleting label file (' . $file_path . $file_name . ')', 'caution'); } } // if we are here the delete was successful, the lack of an error indicates success $messageStack->add_session('Successfully deleted the UPS shipping label. Tracking # ' . $tracking_number, 'success'); return true; }
function closeFedEx($close_date = '', $report_only = false, $report_type = 'MANIFEST') { global $messageStack; $today = date('Y-m-d'); if (!$close_date) { $close_date = $today; } $report_only = $close_date == $today ? false : true; $date = explode('-', $close_date); $error = false; foreach (array('FDXG', 'FDXE') as $code) { $strXML = $this->FormatFedExCloseRequest($code, $close_date, $report_only); //echo 'strXML = ' . htmlspecialchars($strXML) . '<br /><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'); $error = true; continue; } $ResponseXML = $SubmitXML['xmlString']; //echo 'ResponseXML = ' . htmlspecialchars($ResponseXML) . '<br /><br />'; // Check for errors returned from FedEx $XMLFail = GetNodeData($ResponseXML, 'Error:Code'); if ($XMLFail) { // fetch the error code $messageStack->add('FedEx service: ' . $code . ' Close Error # ' . $XMLFail . ' - ' . GetNodeData($ResponseXML, 'Error:Message'), 'caution'); $error = true; continue; } // Fetch the FedEx reports $file_path = DIR_FS_MY_FILES . $_SESSION['company'] . '/shipping/reports/' . $this->code . '/' . $date[0] . '/' . $date[1] . '/'; validate_path($file_path); //echo 'file_path = ' . ($file_path) . '<br />'; $file_name = $date[2] . '-' . GetNodeData($ResponseXML, 'Manifest:FileName') . '.txt'; //echo 'file_name = ' . ($file_name) . '<br />'; $mwReport = base64_decode(GetNodeData($ResponseXML, 'MultiweightReport')); $closeReport = base64_decode(GetNodeData($ResponseXML, 'Manifest:File')); //echo 'close report = ' . $closeReport . '<br />'; $codReport = base64_decode(GetNodeData($ResponseXML, 'CODReport')); // $hazMatReport = base64_decode(GetNodeData($ResponseXML, 'HazMatCertificate')); if (!($handle = fopen($file_path . $file_name, 'w'))) { echo 'Cannot open file (' . $file_path . $file_name . ')'; $error = true; continue; } if (fwrite($handle, $closeReport) === false) { $messageStack->add('Cannot write close report to file (' . $file_path . $file_name . ')', 'error'); $error = true; continue; } if (fwrite($handle, $mwReport) === false) { $messageStack->add('Cannot write multi-weight report to file (' . $file_path . $file_name . ')', 'error'); $error = true; continue; } if (fwrite($handle, $codReport) === false) { $messageStack->add('Cannot write COD report to file (' . $file_path . $file_name . ')', 'error'); $error = true; continue; } /* if (fwrite($handle, $hazMatReport) === false) { $messageStack->add('Cannot write Hazmat report to file (' . $file_path . $file_name . ')','error'); $error = true; continue; } */ fclose($handle); } if (!$error) { $messageStack->add('Successfully closed the FedEx shipments for today.', 'success'); } return true; }
function queryUSPS($pkg, $user_choices, $num_packages) { // Fetch the book rates from USPS global $messageStack; $arrRates = array(); if (MODULE_SHIPPING_USPS_SERVER == 'production') { $strXML = 'API=RateV2&XML=' . $this->production_FormatUSPSRateRequest($pkg, $num_packages); $RateURL = 'http://Production.ShippingAPIs.com/ShippingAPI.dll'; } else { $strXML = 'API=RateV2&XML=' . $this->FormatUSPSRateRequest($pkg, $num_packages); $RateURL = 'http://testing.shippingapis.com/ShippingAPITest.dll'; } $SubmitXML = GetXMLString($strXML, $RateURL, "GET"); // Check for XML request errors if ($SubmitXML['result'] == 'error') { $messageStack->add(SHIPPING_USPS_CURL_ERROR . $SubmitXML['message'], 'error'); return false; } $ResponseXML = $SubmitXML['xmlString']; //echo 'USPS response XML string = ' . htmlspecialchars($ResponseXML) . '<br />'; // Check for errors $XMLFail = GetNodeData($ResponseXML, 'Error:Number'); if ($XMLFail) { // fetch the error code $XMLErrorDesc = GetNodeData($ResponseXML, 'Error:Description'); $messageStack->add($this->code . ' - ' . $XMLFail . ' - ' . $XMLErrorDesc, 'error'); return false; } // Fetch the USPS Rates return $this->GetUSPSRateArray($ResponseXML, $packageID = '1'); }