/** * Constructor * * @return usps */ function canadapost() { global $order, $gBitDb, $template, $gBitLanguage; $this->code = 'canadapost'; $this->title = tra('Canada Post'); $this->description = tra('Canada Post Parcel Service<p><strong>CPC Profile Information </strong>can be obtained at http://sellonline.canadapost.ca<br /><a href=http://sellonline.canadapost.ca/servlet/LogonServlet?Language=0 target="_blank">Modify my profile</a>'); $this->icon = 'shipping_canadapost'; $this->enabled = zen_get_shipping_enabled($this->code) && CommerceSystem::isConfigActive('MODULE_SHIPPING_CANADAPOST_STATUS'); if ($this->enabled == true) { $this->server = MODULE_SHIPPING_CANADAPOST_SERVERIP; $this->port = MODULE_SHIPPING_CANADAPOST_SERVERPOST; $this->language = in_array($gBitLanguage->getLanguage(), array('en', 'fr')) ? strtolower($gBitLanguage->getLanguage()) : MODULE_SHIPPING_CANADAPOST_LANGUAGE; $this->CPCID = MODULE_SHIPPING_CANADAPOST_CPCID; $this->turnaround_time = MODULE_SHIPPING_CANADAPOST_TIME; $this->sort_order = MODULE_SHIPPING_CANADAPOST_SORT_ORDER; $this->items_qty = 0; $this->items_price = 0; $this->tax_class = MODULE_SHIPPING_CANADAPOST_TAX_CLASS; $this->tax_basis = MODULE_SHIPPING_CANADAPOST_TAX_BASIS; $this->cp_online_handling = MODULE_SHIPPING_CANADAPOST_CP_HANDLING == 'True' ? true : false; $this->lettermail = MODULE_SHIPPING_CANADAPOST_LETTERMAIL_STATUS == 'True' ? true : false; $this->lettermail_max_weight = MODULE_SHIPPING_CANADAPOST_LETTERMAIL_MAX; $this->lettermail_available = false; if (MODULE_SHIPPING_CANADAPOST_ZONE) { $this->enabled = $gBitDb->query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = ?, and zone_country_id = ?", array(MODULE_SHIPPING_CANADAPOST_ZONE, $order->delivery['country']['id'])); } } }
function purolator() { //constructor global $order, $gBitDb, $gBitLanguage; $this->code = 'purolator'; $this->title = tra('Purolator e-Ship'); $this->description = tra('Purolator Parcel Service<p><strong>eShip Profile Information </strong>can be obtained at http://eship.purolator.com'); $this->icon = 'shipping_purolator'; $this->language = in_array($gBitLanguage->getLanguage(), array('en', 'fr')) ? strtolower($gBitLanguage->getLanguage()) : MODULE_SHIPPING_CANADAPOST_LANGUAGE; $this->enabled = CommerceSystem::isConfigActive('MODULE_SHIPPING_PUROLATOR_STATUS'); if ($this->enabled == true && (int) MODULE_SHIPPING_PUROLATOR_ZONE > 0) { $this->uri = MODULE_SHIPPING_PUROLATOR_SERVERURI; $this->location = MODULE_SHIPPING_PUROLATOR_SERVERLOC; $this->key = MODULE_SHIPPING_PUROLATOR_KEY; $this->pass = MODULE_SHIPPING_PUROLATOR_PASS; $this->acct_num = MODULE_SHIPPING_PUROLATOR_ACCTNUM; $this->packaging = MODULE_SHIPPING_PUROLATOR_PACKAGING; $this->sort_order = MODULE_SHIPPING_PUROLATOR_SORT_ORDER; $this->handling_fee = MODULE_SHIPPING_PUROLATOR_HANDLING; $this->items_qty = 0; $this->items_price = 0; $this->tax_class = MODULE_SHIPPING_PUROLATOR_TAX_CLASS; $this->tax_basis = MODULE_SHIPPING_PUROLATOR_TAX_BASIS; $check_flag = false; $check = $gBitDb->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_PUROLATOR_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); while (!$check->EOF) { if ($check->fields['zone_id'] < 1) { $check_flag = true; break; } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) { $check_flag = true; break; } $check->MoveNext(); } if ($check_flag == false) { $this->enabled = false; } } }
/** * Get actual quote from USPS * * @return array of results or boolean false if no results */ function _getQuote() { global $order; global $shipping_weight, $currencies; global $logfilename; $package_id = 'USPS DOMESTIC RETURNED: ' . "\n"; $usps_groundonly = 'false'; if ($usps_groundonly == 'false') { // no GroundOnly products $usps_groundonly = ''; } else { // 1+ GroundOnly products force Standard Post only $usps_groundonly = '<Content>' . '<ContentType>HAZMAT</ContentType>' . '</Content>' . '<GroundOnly>' . $usps_groundonly . '</GroundOnly>'; } if ((int) SHIPPING_ORIGIN_ZIP == 0) { // no quotes obtained no 5 digit zip code origin set return array('module' => $this->title, 'error' => MODULE_SHIPPING_USPS_TEXT_ERROR . (MODULE_SHIPPING_USPS_SERVER == 'test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : '')); } if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs') { $usps_instance_id = date('mdYGis'); $usps_dir_logs = defined('DIR_FS_LOGS') ? DIR_FS_LOGS : DIR_FS_SQL_CACHE; $logfilename = $usps_dir_logs . '/SHIP_usps_Debug_' . $usps_instance_id . '_' . str_replace(' ', '', $order->delivery['country']['countries_iso_code_2']) . '_' . str_replace(' ', '', $order->delivery['postcode']) . '_' . $this->pounds . 'lb_' . $this->ounces . 'oz' . '.log'; } $transreq = array(); if (MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off') { // display checked boxes $usps_shipping_methods_domestic = ''; $usps_shipping_methods_international = ''; $usps_shipping_country = "\n" . '==================================' . "\n\n" . 'USPS Country - $this->countries[$order->delivery[country][iso_code_2]]: ' . $this->countries[$order->delivery['country']['countries_iso_code_2']] . ' $this->usps_countries: ' . $this->usps_countries . "\n"; if ($this->usps_countries == 'US') { $package_id_sent = 0; $usps_shipping_methods_domestic .= '<br />USPS DOMESTIC CHECKED: ' . MODULE_SHIPPING_USPS_RATE_TYPE . '<br />'; foreach ($this->typeCheckboxesSelected as $key => $val) { $requested_type = $this->typeCheckboxesSelected[$key]; $checked_request = ' min: ' . $this->typeCheckboxesSelected[$key + 1] . ' max: ' . $this->typeCheckboxesSelected[$key + 2] . ' handling: ' . $this->typeCheckboxesSelected[$key + 3]; if (is_numeric($requested_type) || empty($requested_type) || preg_match('#(GXG|International)#i', $requested_type)) { continue; } $usps_shipping_methods_domestic .= 'Package ID sent: ' . $package_id_sent . ' ' . $requested_type . ' - ' . $checked_request . "\n"; $package_id_sent++; } } else { $usps_shipping_methods_international .= '<br />USPS INTERNATIONAL CHECKED: ' . MODULE_SHIPPING_USPS_RATE_TYPE . '<br />'; foreach ($this->typeCheckboxesSelected as $key => $val) { $requested_type = $this->typeCheckboxesSelected[$key]; $checked_request = ' min: ' . $this->typeCheckboxesSelected[$key + 1] . ' max: ' . $this->typeCheckboxesSelected[$key + 2] . ' handling: ' . $this->typeCheckboxesSelected[$key + 3]; if (is_numeric($requested_type) || empty($requested_type) || !preg_match('#(GXG|International)#i', $requested_type)) { continue; } $usps_shipping_methods_international .= $requested_type . ' - ' . $checked_request . "\n"; } } if (false && $_GET['main_page'] == 'popup_shipping_estimator' && MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off') { echo '================================' . '<br />'; echo $usps_shipping_methods_domestic; echo $usps_shipping_methods_international; echo '================================' . '<br />'; } } $shipment_value = (double) $order->subtotal > 0 ? $order->subtotal + $order->getField('tax') : (!empty($_SESSION['cart']->total) ? $_SESSION['cart']->total : 0); $insurable_value = $shipment_value; // spiderr - where is this defined? - $uninsurable_value; // US Domestic destinations if ($order->delivery['country']['countries_iso_code_3'] == 'USA' || $this->usps_countries == 'US') { // build special services for domestic // Some Special Services cannot work with others $special_services_domestic = $this->special_services(); $ZipDestination = substr(str_replace(' ', '', $order->delivery['postcode']), 0, 5); if ($ZipDestination == '') { return -1; } $request = '<RateV4Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Revision>2</Revision>'; $package_count = 0; $ship_date = $this->zen_usps_shipdate(); foreach ($this->typeCheckboxesSelected as $requested_type) { if (is_numeric($requested_type) || preg_match('#(GXG|International)#i', $requested_type)) { continue; } $FirstClassMailType = ''; $Container = 'VARIABLE'; if (preg_match('#First\\-Class#i', $requested_type)) { if ($shipping_weight > 13 / 16 || $shipping_weight > 0.21875 && $requested_type == 'First-Class Mail Letter') { continue; } else { // First-Class MailRM Letter\', \'First-Class MailRM Large Envelope\', \'First-Class MailRM Parcel $service = 'First-Class Mail'; if ($requested_type == 'First-Class Mail Letter') { $FirstClassMailType = 'LETTER'; } elseif ($requested_type == 'First-Class Mail Large Envelope') { $FirstClassMailType = 'FLAT'; } else { $FirstClassMailType = 'PARCEL'; //$FirstClassMailType = 'PACKAGE SERVICE'; } } } elseif ($requested_type == 'Media Mail Parcel') { $service = 'MEDIA'; } elseif ($requested_type == 'Standard PostRM') { $service = 'PARCEL'; } elseif (preg_match('#Priority Mail(?! Express)#i', $requested_type)) { $service = 'PRIORITY COMMERCIAL'; if ($requested_type == 'Priority MailTM Flat Rate Envelope') { $Container = 'FLAT RATE ENVELOPE'; } elseif ($requested_type == 'Priority MailTM Legal Flat Rate Envelope') { $Container = 'LEGAL FLAT RATE ENVELOPE'; } elseif ($requested_type == 'Priority MailTM Padded Flat Rate Envelope') { $Container = 'PADDED FLAT RATE ENVELOPE'; } elseif ($requested_type == 'Priority MailTM Small Flat Rate Box') { $Container = 'SM FLAT RATE BOX'; } elseif ($requested_type == 'Priority MailTM Medium Flat Rate Box') { $Container = 'MD FLAT RATE BOX'; } elseif ($requested_type == 'Priority MailTM Large Flat Rate Box') { $Container = 'LG FLAT RATE BOX'; } elseif ($requested_type == 'Priority MailTM Regional Rate Box A') { $Container = 'REGIONALRATEBOXA'; } elseif ($requested_type == 'Priority MailTM Regional Rate Box B') { $Container = 'REGIONALRATEBOXB'; } elseif ($requested_type == 'Priority MailTM Regional Rate Box C') { $Container = 'REGIONALRATEBOXC'; } } elseif (preg_match('#Priority Mail Express#i', $requested_type)) { $service = 'EXPRESS COMMERCIAL'; if ($requested_type == 'Priority Mail ExpressTM Flat Rate Envelope') { $Container = 'FLAT RATE ENVELOPE'; } elseif ($requested_type == 'Priority Mail ExpressTM Legal Flat Rate Envelope') { $Container = 'LEGAL FLAT RATE ENVELOPE'; } elseif ($requested_type == 'Priority Mail ExpressTM Flat Rate Boxes') { $Container = 'FLAT RATE BOX'; } } else { continue; } $specialservices = $special_services_domestic; $width = MODULE_SHIPPING_USPS_WIDTH; $length = MODULE_SHIPPING_USPS_LENGTH; $height = MODULE_SHIPPING_USPS_HEIGHT; $girth = 108; $dimensions = '<Width>' . $width . '</Width>' . '<Length>' . $length . '</Length>' . '<Height>' . $height . '</Height>' . '<Girth>' . $girth . '</Girth>'; $dimensions = ''; $request .= '<Package ID="' . $package_count . '">' . '<Service>' . $service . '</Service>' . ($FirstClassMailType != '' ? '<FirstClassMailType>' . $FirstClassMailType . '</FirstClassMailType>' : '') . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $ZipDestination . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container>' . $Container . '</Container>' . '<Size>REGULAR</Size>' . $dimensions . '<Value>' . number_format($insurable_value, 2, '.', '') . '</Value>' . $specialservices . ($usps_groundonly != '' ? $usps_groundonly : '') . '<Machinable>' . ($this->machinable == 'True' ? 'TRUE' : 'FALSE') . '</Machinable>' . ($this->getTransitTime && $this->transitTimeCalculationMode == 'NEW' ? '<ShipDate>' . $ship_date . '</ShipDate>' : '') . '</Package>'; $package_id .= 'Package ID returned: ' . $package_count . ' $requested_type: ' . $requested_type . ' $service: ' . $service . ' $Container: ' . $Container . "\n"; $package_count++; if ($this->getTransitTime && $this->transitTimeCalculationMode == 'OLD') { $transitreq = 'USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' . '<DestinationZip>' . $ZipDestination . '</DestinationZip>'; //echo 'USPS $service: ' . $service . '<br>'; switch ($service) { case 'PRIORITY COMMERCIAL': case 'PRIORITY': $transreq[$requested_type] = 'API=PriorityMail&XML=' . urlencode('<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); break; case 'PARCEL': $transreq[$requested_type] = 'API=StandardB&XML=' . urlencode('<StandardBRequest ' . $transitreq . '</StandardBRequest>'); break; case 'First-Class Mail': $transreq[$requested_type] = 'API=FirstClassMail&XML=' . urlencode('<FirstClassMailRequest ' . $transitreq . '</FirstClassMailRequest>'); break; case 'MEDIA': default: $transreq[$requested_type] = ''; break; } } } $request .= '</RateV4Request>'; if (MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off') { // prepare request for display $this->request_display = preg_replace(array('/<\\//', '/></', '/> </', '/</', '/>/', '/> </', '/></'), array('</', '><', '> <', '<', '>', '><br> <', '><br><'), htmlspecialchars_decode($request)); if (false && $_GET['main_page'] == 'popup_shipping_estimator' && MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off') { echo '<br />USPS DOMESTIC $request: <br />' . 'API=RateV4&XML=' . $this->request_display . '<br />'; } // prepare request for debug log $this->request_display = $request; } $request = 'API=RateV4&XML=' . urlencode($request); } else { // INTERNATIONAL destinations // build extra services for international // Some Extra Services cannot work with others $extra_service_international = $this->extra_service(); $intl_gxg_requested = 0; foreach ($this->typeCheckboxesSelected as $requested_type) { if (!is_numeric($requested_type) && preg_match('#(GXG)#i', $requested_type)) { $intl_gxg_requested++; } } // rudimentary dimensions, since they cannot be passed as blanks if ($intl_gxg_requested) { $width = MODULE_SHIPPING_USPS_WIDTH_INTL; $length = MODULE_SHIPPING_USPS_LENGTH_INTL; $height = MODULE_SHIPPING_USPS_HEIGHT_INTL; $girth = 0; } else { $width = MODULE_SHIPPING_USPS_WIDTH; $length = MODULE_SHIPPING_USPS_LENGTH; $height = MODULE_SHIPPING_USPS_HEIGHT; $girth = 0; } // adjust <ValueOfContents> to not exceed $2499 per box global $shipping_num_boxes; $max_usps_allowed_price = $order->subtotal > 0 ? $order->subtotal + $order->getField('tax', 0) : (!empty($_SESSION['cart']) ? $_SESSION['cart']->total : 0); $max_usps_allowed_price = $max_usps_allowed_price / $shipping_num_boxes; $extraservices = $extra_service_international; $submission_value = $insurable_value > $max_usps_allowed_price ? $max_usps_allowed_price : $insurable_value; $request = '<IntlRateV2Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Revision>2</Revision>' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>All</MailType>' . '<GXG>' . ' <POBoxFlag>N</POBoxFlag>' . ' <GiftFlag>N</GiftFlag>' . '</GXG>' . '<ValueOfContents>' . number_format($submission_value, 2, '.', '') . '</ValueOfContents>' . '<Country>' . (empty($this->countries[$order->delivery['country']['countries_iso_code_2']]) ? zen_get_country_name($order->delivery['country']['countries_id']) : $this->countries[$order->delivery['country']['countries_iso_code_2']]) . '</Country>' . '<Container>RECTANGULAR</Container>' . '<Size>REGULAR</Size>' . '<Width>' . $width . '</Width>' . '<Length>' . $length . '</Length>' . '<Height>' . $height . '</Height>' . '<Girth>' . $girth . '</Girth>' . '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' . '<CommercialFlag>Y</CommercialFlag>' . $extraservices . '</Package>' . '</IntlRateV2Request>'; if ($this->getTransitTime) { $transreq[$requested_type] = ''; } if (MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off') { // prepare request for display $this->request_display = preg_replace(array('/<\\//', '/></', '/> </', '/</', '/>/', '/> </', '/></'), array('</', '><', '> <', '<', '>', '><br> <', '><br><'), htmlspecialchars_decode($request)); if (false && $_GET['main_page'] == 'popup_shipping_estimator' && MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off') { echo '<br />USPS INTERNATIONAL $request: <br />' . 'API=IntlRateV2&XML=' . $this->request_display . '<br />'; } // prepare request for debug log $this->request_display = $request; } $request = 'API=IntlRateV2&XML=' . urlencode($request); } switch (MODULE_SHIPPING_USPS_SERVER) { case 'production': $usps_server = 'http://production.shippingapis.com'; $api_dll = 'shippingapi.dll'; break; case 'test': default: $usps_server = 'http://stg-production.shippingapis.com'; $api_dll = 'ShippingApi.dll'; break; } $body = ''; // Send quote request via CURL global $request_type; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $usps_server . '/' . $api_dll); curl_setopt($ch, CURLOPT_REFERER, $request_type == 'SSL' ? HTTPS_SERVER . DIR_WS_HTTPS_CATALOG : HTTP_SERVER . DIR_WS_CATALOG); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_SSLVERSION, 3); curl_setopt($ch, CURLOPT_USERAGENT, 'Zen Cart'); if (CommerceSystem::isConfigActive('CURL_PROXY_REQUIRED')) { $this->proxy_tunnel_flag = defined('CURL_PROXY_TUNNEL_FLAG') && strtoupper(CURL_PROXY_TUNNEL_FLAG) == 'FALSE' ? false : true; curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, $this->proxy_tunnel_flag); curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); curl_setopt($ch, CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS); } // submit request // set to TRUE to show times when debug is enabled $show_times = FALSE; if ($show_times && MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off') { echo 'Time sent to USPS before curl_exec: ' . date('M d Y G:i:s') . ' ' . time() . '<br>'; } $body = curl_exec($ch); $this->commError = curl_error($ch); $this->commErrNo = curl_errno($ch); $this->commInfo = @curl_getinfo($ch); // SUBMIT ADDITIONAL REQUESTS FOR DELIVERY TIME ESTIMATES if ($this->transitTimeCalculationMode == 'OLD' && $this->getTransitTime && sizeof($transreq)) { while (list($key, $value) = each($transreq)) { $transitResp[$key] = ''; if ($value != '') { curl_setopt($ch, CURLOPT_POSTFIELDS, $value); $transitResp[$key] = curl_exec($ch); } } $this->parseDomesticLegacyAPITransitTimeResults($transitResp); } // done with CURL, so close connection curl_close($ch); if ($show_times && MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off') { echo 'Time sent to USPS after curl_exec: ' . date('M d Y G:i:s') . ' ' . time() . '<br><br>'; } // DEV ONLY - dump out the returned data for debugging if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Email') { mail(STORE_OWNER_EMAIL_ADDRESS, 'Debug: USPS rate quote response', '(You can turn off this debug email by editing your USPS module settings in the admin area of your store.) ' . "\n\n" . $body, 'From: <' . EMAIL_FROM . '>'); } // echo 'USPS METHODS: <pre>'; echo print_r($body); echo '</pre>'; if (MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off') { global $shipping_weight, $currencies; $body_display_header = ''; $body_display_header .= "\n" . 'USPS build: ' . MODULE_SHIPPING_USPS_VERSION . "\n\n"; $body_display_header .= 'Server: ' . MODULE_SHIPPING_USPS_SERVER . "\n"; $body_display_header .= 'Quote Request Rate Type: ' . MODULE_SHIPPING_USPS_RATE_TYPE . "\n"; $body_display_header .= 'Quote from main_page: ' . $_GET['main_page'] . "\n"; $body_display_header .= 'USPS Options (weight, time): ' . MODULE_SHIPPING_USPS_OPTIONS . "\n"; $body_display_header .= 'USPS Domestic Transit Time Calculation Mode: ' . MODULE_SHIPPING_USPS_TRANSIT_TIME_CALCULATION_MODE . "\n"; $body_display_header .= "\n" . 'Cart Weight: ' . $_SESSION['cart']->weight . "\n"; $body_display_header .= 'Total Quote Weight: ' . $shipping_weight . ' Pounds: ' . $this->pounds . ' Ounces: ' . $this->ounces . "\n"; $body_display_header .= 'Maximum: ' . SHIPPING_MAX_WEIGHT . ' Tare Rates: Small/Medium: ' . SHIPPING_BOX_WEIGHT . ' Large: ' . SHIPPING_BOX_PADDING . "\n"; $body_display_header .= 'Handling method: ' . MODULE_SHIPPING_USPS_HANDLING_METHOD . ' Handling fee Domestic: ' . $currencies->format(MODULE_SHIPPING_USPS_HANDLING) . ' Handling fee International: ' . $currencies->format(MODULE_SHIPPING_USPS_HANDLING_INT) . "\n"; $body_display_header .= 'Decimals: ' . MODULE_SHIPPING_USPS_DECIMALS . "\n"; $body_display_header .= 'Domestic Length: ' . MODULE_SHIPPING_USPS_LENGTH . ' Width: ' . MODULE_SHIPPING_USPS_WIDTH . ' Height: ' . MODULE_SHIPPING_USPS_HEIGHT . "\n"; $body_display_header .= 'International Length: ' . MODULE_SHIPPING_USPS_LENGTH_INTL . ' Width: ' . MODULE_SHIPPING_USPS_WIDTH_INTL . ' Height: ' . MODULE_SHIPPING_USPS_HEIGHT_INTL . "\n"; $body_display_header .= "\n" . 'ZipOrigination: ' . ((int) SHIPPING_ORIGIN_ZIP == 0 ? '***WARNING: NO STORE 5 DIGIT ZIP CODE SET' : SHIPPING_ORIGIN_ZIP) . "\n" . 'ZipDestination: ' . $order->delivery['postcode'] . (!empty($this->countries[$order->delivery['country']['countries_iso_code_2']]) ? ' Country: ' . $this->countries[$order->delivery['country']['countries_iso_code_2']] : '') . ($order->delivery['city'] != '' ? ' City: ' . $order->delivery['city'] : '') . ($order->delivery['state'] != '' ? ' State: ' . $order->delivery['state'] : '') . "\n"; $body_display_header .= 'Order SubTotal: ' . $currencies->format($order->info['subtotal']) . "\n"; $body_display_header .= 'Order Total: ' . $currencies->format($shipment_value) . "\n"; $body_display_header .= 'Uninsurable Portion: ' . $currencies->format($uninsurable_value) . "\n"; $body_display_header .= 'Insurable Value: ' . $currencies->format($insurable_value) . "\n"; $body_display_header .= "\n" . 'RESPONSE FROM USPS: ' . "\n"; $body_display_header .= "\n" . '==================================' . "\n"; // build list of requested shipping services $services_domestic = 'Domestic Services Selected: ' . "\n"; $services_international = 'International Services Selected: ' . "\n"; // Domestic/US destination: if ($this->usps_countries == 'US') { $dOptions = explode(', ', MODULE_SHIPPING_USPS_DMST_SERVICES); // domestic foreach ($dOptions as $key => $val) { if (strlen($dOptions[$key]) > 1) { if ($dOptions[$key + 1] == 'C' || $dOptions[$key + 1] == 'S' || $dOptions[$key + 1] == 'Y') { $services_domestic .= $dOptions[$key] . "\n"; } //echo '$dOptions[$key]: > 1 ' . $dOptions[$key] . ' $dOptions[$key+1]: ' . $dOptions[$key+1] . '<br>'; } } } else { // International destination: $iOptions = explode(', ', MODULE_SHIPPING_USPS_INTL_SERVICES); foreach ($iOptions as $key => $val) { if (strlen($iOptions[$key]) > 1) { if ($iOptions[$key + 1] == 'C' || $iOptions[$key + 1] == 'S' || $iOptions[$key + 1] == 'Y') { $services_international .= $iOptions[$key] . "\n"; } //echo '$iOptions[$key]: > 1 ' . $iOptions[$key] . ' $iOptions[$key+1]: ' . $iOptions[$key+1] . '<br>'; } } } if ($this->usps_countries == 'US') { $usps_shipping_services_selected = $services_domestic; } else { $usps_shipping_services_selected = $services_international; } $usps_shipping_country = str_replace("<br />", "\n", $usps_shipping_country); $usps_shipping_methods_domestic = str_replace("<br />", "\n", $usps_shipping_methods_domestic); $usps_shipping_methods_international = str_replace("<br />", "\n", $usps_shipping_methods_international); if ($this->usps_countries == 'US') { $usps_shipping_methods_selected = $usps_shipping_methods_domestic . "\n\n" . $package_id . "\n\n"; } else { $usps_shipping_methods_selected = $usps_shipping_methods_international . "\n\n"; } } if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Screen') { echo ($this->commErrNo != 0 ? '<br />' . $this->commErrNo . ' ' . $this->commError : '') . '<br /><pre>' . $body . '</pre><br />'; } if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs') { // skip debug log if no destination zipcode is set: 0==(int)SHIPPING_ORIGIN_ZIP $fp = @fopen($logfilename, 'a'); if ($fp && $this->commErrNo != 0) { fwrite($fp, date('M d Y G:i:s') . ' -- ' . 'CommErr (should be 0): ' . $this->commErrNo . ' - ' . $this->commError . "\n\n\n\n" . $body_display_header . "\n\n" . $usps_shipping_country . $usps_shipping_methods_selected . '==================================' . "\n\n" . $usps_shipping_services_selected . "\n" . '==================================' . "\n\n" . 'SENT TO USPS:' . "\n\n"); fclose($fp); } } //if communication error, return -1 because no quotes were found, and user doesn't need to see the actual error message (set DEBUG mode to get the messages logged instead) if ($this->commErrNo != 0) { return -1; } if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' || MODULE_SHIPPING_USPS_DEBUG_MODE == 'Screen') { $body_display = str_replace('&lt;sup&gt;&#8482;&lt;/sup&gt;', 'TM', $body); $body_display = str_replace('&lt;sup&gt;&#174;&lt;/sup&gt;', 'RM', $body_display); $body_display = str_replace('<Service ID', (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' ? "\n\n" : '<br /><br />') . '<Service ID', $body_display); $body_display = str_replace('</Service>', '</Service>' . "\n", $body_display); $body_display = str_replace('<SvcDescription', (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' ? "\n" : '<br />') . '<SvcDescription', $body_display); $body_display = str_replace('<MaxDimensions>', "\n" . '<MaxDimensions>', $body_display); $body_display = str_replace('<MaxWeight>', "\n" . '<MaxWeight>', $body_display); $body_display = str_replace('<Package ID', (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' ? "\n\n\n" : '<br /><br /><br />') . '<Package ID', $body_display); $body_display = str_replace('<Postage CLASSID', "\n" . '<Postage CLASSID', $body_display); $body_display = str_replace('<Rate>', (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' ? "\n" : '<br />') . '<Rate>', $body_display); $body_display = str_replace('<SpecialServices', (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' ? "\n" : '<br />') . '<SpecialServices', $body_display); $body_display = str_replace('<ServiceID>', "\n" . '<ServiceID>', $body_display); $body_display = str_replace('<Description>', "\n" . '<Description>', $body_display); if ($this->usps_countries == 'US') { $body_display = str_replace('</Postage>', "\n" . '</Postage>', $body_display); $body_display = str_replace('<Location>', "\n\t\t\t" . '<Location>', $body_display); $body_display = str_replace('</RateV4Response>', "\n" . '</RateV4Response>', $body_display); } if ($this->usps_countries != 'US') { $body_display = str_replace('<Postage>', (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' ? "\n" : '<br />') . '<Postage>', $body_display); $body_display = str_replace('<ValueOfContents>', "\n" . '<ValueOfContents>', $body_display); } if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Screen') { echo '<br />View Source:<br />' . "\n" . $body_display_header . "\n\n" . $body_display . '<br />'; } if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs') { // skip debug log if no destination zipcode is set $fp = @fopen($logfilename, 'a'); if ($fp) { $this->request_display = preg_replace(array('/></', '/> </'), array('>' . "\n" . '<', '>' . "\n" . ' <'), htmlspecialchars_decode($this->request_display)); fwrite($fp, date('M d Y G:i:s') . ' -- ' . $body_display_header . "\n\n" . $body_display . "\n\n" . $usps_shipping_country . $usps_shipping_methods_selected . '==================================' . "\n\n" . $usps_shipping_services_selected . "\n" . '==================================' . "\n\n" . 'SENT TO USPS:' . "\n\n" . $this->request_display . "\n\n" . "============\n\nRAW XML FROM USPS:\n\n" . print_r(simplexml_load_string($body), true) . "\n\n"); fclose($fp); } } } // This occasionally threw an error with simplexml; may only be needed for the test server but could change in the future for the production server /* $body = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '<?xml version="1.0"?>', $body); */ $body_array = simplexml_load_string($body); $body_encoded = json_decode(json_encode($body_array), TRUE); return $body_encoded; }