function _upsGetQuote() { if (!isset($this->_upsActionCode)) { $this->_upsActionCode = '4'; } $request = join('&', array('accept_UPS_license_agreement=yes', '10_action=' . $this->_upsActionCode, '13_product=' . $this->_upsProductCode, '14_origCountry=' . $this->_upsOriginCountryCode, '15_origPostal=' . $this->_upsOriginPostalCode, '19_destPostal=' . $this->_upsDestPostalCode, '22_destCountry=' . $this->_upsDestCountryCode, '23_weight=' . $this->_upsPackageWeight, '47_rate_chart=' . $this->_upsRateCode, '48_container=' . $this->_upsContainerCode, '49_residential=' . $this->_upsResComCode)); $http = new httpClient(); if ($http->Connect('www.ups.com', 80)) { $http->addHeader('Host', 'www.ups.com'); $http->addHeader('User-Agent', 'osCommerce'); $http->addHeader('Connection', 'Close'); if ($http->Get('/using/services/rave/qcostcgi.cgi?' . $request)) { $body = $http->getBody(); } $http->Disconnect(); } else { return 'error'; } /* mail('*****@*****.**','UPS response',$body,'From: <*****@*****.**>'); */ $body_array = explode("\n", $body); $returnval = array(); $errorret = 'error'; // only return error if NO rates returned $n = sizeof($body_array); for ($i = 0; $i < $n; $i++) { $result = explode('%', $body_array[$i]); $errcode = substr($result[0], -1); switch ($errcode) { case 3: if (is_array($returnval)) { $returnval[] = array($result[1] => $result[8]); } break; case 4: if (is_array($returnval)) { $returnval[] = array($result[1] => $result[8]); } break; case 5: $errorret = $result[1]; break; case 6: if (is_array($returnval)) { $returnval[] = array($result[3] => $result[10]); } break; } } if (empty($returnval)) { $returnval = $errorret; } return $returnval; }
/** * Sent request for quote to UPS via older HTML method * * @return array */ function _upsGetQuote() { if (!isset($this->_upsActionCode)) { $this->_upsActionCode = '4'; } $request = join('&', array('accept_UPS_license_agreement=yes', '10_action=' . $this->_upsActionCode, '13_product=' . $this->_upsProductCode, '14_origCountry=' . $this->_upsOriginCountryCode, '15_origPostal=' . $this->_upsOriginPostalCode, '19_destPostal=' . $this->_upsDestPostalCode, '22_destCountry=' . $this->_upsDestCountryCode, '23_weight=' . $this->_upsPackageWeight, '47_rate_chart=' . $this->_upsRateCode, '48_container=' . $this->_upsContainerCode, '49_residential=' . $this->_upsResComCode)); $http = new httpClient(); if ($http->Connect('www.ups.com', 80)) { $http->addHeader('Host', 'www.ups.com'); $http->addHeader('User-Agent', 'Zen Cart'); $http->addHeader('Connection', 'Close'); if ($http->Get('/using/services/rave/qcostcgi.cgi?' . $request)) { $body = $http->getBody(); } $http->Disconnect(); } else { return 'error'; } // BOF: UPS USPS /* TEST by checking out in the catalog; try a variety of shipping destinations to be sure your customers will be properly served. If you are not getting any quotes, try enabling more alternatives in admin. Make sure your store's postal code is set in Admin -> Configuration -> Shipping/Packaging, since you won't get any quotes unless there is a origin that UPS recognizes. If you STILL don't get any quotes, here is a way to find out exactly what UPS is sending back in response to rate quote request, you can uncomment the following mail() line and then check your email after visiting the shipping page in checkout ... */ //mail(STORE_OWNER_EMAIL_ADDRESS, 'UPS response', $body, 'From: <'.STORE_OWNER_EMAIL_ADDRESS.'>'); // EOF: UPS USPS $body_array = explode("\n", $body); /* //DEBUG ONLY $n = sizeof($body_array); for ($i=0; $i<$n; $i++) { $result = explode('%', $body_array[$i]); print_r($result); } die('END'); */ $returnval = array(); $errorret = 'error'; // only return 'error' if NO rates returned $n = sizeof($body_array); for ($i = 0; $i < $n; $i++) { $result = explode('%', $body_array[$i]); $errcode = substr($result[0], -1); switch ($errcode) { case 3: if (is_array($returnval)) { $returnval[] = array($result[1] => $result[10]); } break; case 4: if (is_array($returnval)) { $returnval[] = array($result[1] => $result[10]); } break; case 5: $errorret = $result[1]; break; case 6: if (is_array($returnval)) { $returnval[] = array($result[3] => $result[10]); } break; } } if (empty($returnval)) { $returnval = $errorret; } return $returnval; }
function _getQuote() { global $order; if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { $request = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">'; $services_count = 0; if (isset($this->service)) { $this->types = array($this->service => $this->types[$this->service]); } $dest_zip = str_replace(' ', '', $order->delivery['postcode']); if ($order->delivery['country']['iso_code_2'] == 'US') { $dest_zip = substr($dest_zip, 0, 5); } reset($this->types); while (list($key, $value) = each($this->types)) { $request .= '<Package ID="' . $services_count . '">' . '<Service>' . $key . '</Service>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container>' . $this->container . '</Container>' . '<Size>' . $this->size . '</Size>' . '<Machinable>' . $this->machinable . '</Machinable>' . '</Package>'; $services_count++; } $request .= '</RateRequest>'; $request = 'API=Rate&XML=' . urlencode($request); } else { $request = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>Package</MailType>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '</Package>' . '</IntlRateRequest>'; $request = 'API=IntlRate&XML=' . urlencode($request); } switch (MODULE_SHIPPING_USPS_SERVER) { case 'production': $usps_server = 'production.shippingapis.com'; $api_dll = 'shippingapi.dll'; break; case 'test': default: $usps_server = 'testing.shippingapis.com'; $api_dll = 'ShippingAPITest.dll'; break; } $body = ''; $http = new httpClient(); if ($http->Connect($usps_server, 80)) { $http->addHeader('Host', $usps_server); $http->addHeader('User-Agent', 'osCommerce'); $http->addHeader('Connection', 'Close'); if ($http->Get('/' . $api_dll . '?' . $request)) { $body = $http->getBody(); } $http->Disconnect(); } else { return false; } $response = array(); while (true) { if ($start = strpos($body, '<Package ID=')) { $body = substr($body, $start); $end = strpos($body, '</Package>'); $response[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $rates = array(); if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { if (sizeof($response) == '1') { if (ereg('<Error>', $response[0])) { $number = ereg('<Number>(.*)</Number>', $response[0], $regs); $number = $regs[1]; $description = ereg('<Description>(.*)</Description>', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } } $n = sizeof($response); for ($i = 0; $i < $n; $i++) { if (strpos($response[$i], '<Postage>')) { $service = ereg('<Service>(.*)</Service>', $response[$i], $regs); $service = $regs[1]; $postage = ereg('<Postage>(.*)</Postage>', $response[$i], $regs); $postage = $regs[1]; $rates[] = array($service => $postage); } } } else { if (ereg('<Error>', $response[0])) { $number = ereg('<Number>(.*)</Number>', $response[0], $regs); $number = $regs[1]; $description = ereg('<Description>(.*)</Description>', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } else { $body = $response[0]; $services = array(); while (true) { if ($start = strpos($body, '<Service ID=')) { $body = substr($body, $start); $end = strpos($body, '</Service>'); $services[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $size = sizeof($services); for ($i = 0, $n = $size; $i < $n; $i++) { if (strpos($services[$i], '<Postage>')) { $service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs); $service = $regs[1]; $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); $postage = $regs[1]; if (isset($this->service) && $service != $this->service) { continue; } $rates[] = array($service => $postage); } } } } return sizeof($rates) > 0 ? $rates : false; }
function _getQuote() { global $order; if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { $dest_zip = str_replace(' ', '', $order->delivery['postcode']); if ($order->delivery['country']['iso_code_2'] == 'US') { $dest_zip = substr($dest_zip, 0, 5); } $request = '<RateV3Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Package ID="0">' . '<Service>' . 'ALL' . '</Service>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container/><Size>Regular</Size><Machinable>True</Machinable>' . '</Package></RateV3Request>'; $request = 'API=RateV3&XML=' . urlencode($request); } else { $request = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>Package</MailType>' . '<GXG>' . '<Length>12</Length><Width>12</Width><Height>12</Height>' . '<POBoxFlag>N</POBoxFlag><GiftFlag>N</GiftFlag>' . '</GXG>' . '<ValueOfContents>50</ValueOfContents>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '</Package>' . '</IntlRateRequest>'; $request = 'API=IntlRate&XML=' . urlencode($request); } $body = ''; if (!class_exists('httpClient')) { include 'includes/classes/http_client.php'; } $http = new httpClient(); if ($http->Connect('production.shippingapis.com', 80)) { $http->addHeader('Host', 'production.shippingapis.com'); $http->addHeader('User-Agent', 'osCommerce'); $http->addHeader('Connection', 'Close'); if ($http->Get('/shippingapi.dll?' . $request)) { $body = $http->getBody(); } $http->Disconnect(); } else { return false; } $response = array(); while (true) { if ($start = strpos($body, '<Package ID=')) { $body = substr($body, $start); $end = strpos($body, '</Package>'); $response[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $rates = array(); if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { if (sizeof($response) == '1') { if (preg_match('/<Error>/', $response[0])) { $number = preg_match('/<Number>(.*)<\\/Number>/', $response[0], $regs); $number = $regs[1]; $description = preg_match('/<Description>(.*)<\\/Description>/', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } } $n = sizeof($response); for ($i = 0; $i < $n; $i++) { $resp = $response[$i]; $pos = 0; while (1) { $pos = strpos($response[$i], '<Postage', $pos); if ($pos === FALSE) { break; } $end = strpos($response[$i], '</Postage>', $pos); if ($end === FALSE) { break; } $resp = substr($response[$i], $pos, $end - $pos); $service = preg_match('/<MailService>(.*)<\\/MailService>/', $resp, $regs); $service = $regs[1]; $postage = preg_match('/<Rate>(.*)<\\/Rate>/', $resp, $regs); $postage = $regs[1]; $pos = $end; $rates[] = array($service => $postage); } } } else { if (preg_match('/<Error>/', $response[0])) { $number = preg_match('/<Number>(.*)<\\/Number>/', $response[0], $regs); $number = $regs[1]; $description = preg_match('/<Description>(.*)<\\/Description>/', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } else { $body = $response[0]; $services = array(); while (true) { if ($start = strpos($body, '<Service ID=')) { $body = substr($body, $start); $end = strpos($body, '</Service>'); $services[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $size = sizeof($services); for ($i = 0, $n = $size; $i < $n; $i++) { if (strpos($services[$i], '<Postage>')) { $service = preg_match('/<SvcDescription>(.*)<\\/SvcDescription>/', $services[$i], $regs); $service = $regs[1]; $postage = preg_match('/<Postage>(.*)<\\/Postage>/', $services[$i], $regs); $postage = $regs[1]; if (isset($this->service) && $service != $this->service) { continue; } $rates[] = array($service => $postage); } } } } return sizeof($rates) > 0 ? $rates : false; }
function _getQuote() { global $order, $transittime; if (in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) { $transit = TRUE; } if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { $request = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">'; $services_count = 0; if (isset($this->service)) { $this->types = array($this->service => $this->types[$this->service]); } $dest_zip = str_replace(' ', '', $order->delivery['postcode']); if ($order->delivery['country']['iso_code_2'] == 'US') { $dest_zip = substr($dest_zip, 0, 5); } reset($this->types); $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES); while (list($key, $value) = each($this->types)) { if (!in_array($key, $allowed_types)) { continue; } $request .= '<Package ID="' . $services_count . '">' . '<Service>' . $key . '</Service>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container>' . $this->container . '</Container>' . '<Size>' . $this->size . '</Size>' . '<Machinable>' . $this->machinable . '</Machinable>' . '</Package>'; if ($transit) { $transitreq = 'USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">' . '<OriginZip>' . STORE_ORIGIN_ZIP . '</OriginZip>' . '<DestinationZip>' . $dest_zip . '</DestinationZip>'; switch ($key) { case 'Express': $transreq[$key] = 'API=ExpressMail&XML=' . urlencode('<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>'); break; case 'Priority': $transreq[$key] = 'API=PriorityMail&XML=' . urlencode('<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); break; case 'Parcel': $transreq[$key] = 'API=StandardB&XML=' . urlencode('<StandardBRequest ' . $transitreq . '</StandardBRequest>'); break; default: $transreq[$key] = ''; break; } } $services_count++; } $request .= '</RateRequest>'; $request = 'API=Rate&XML=' . urlencode($request); } else { $request = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>Package</MailType>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '</Package>' . '</IntlRateRequest>'; $request = 'API=IntlRate&XML=' . urlencode($request); } switch (MODULE_SHIPPING_USPS_SERVER) { case 'production': $usps_server = 'production.shippingapis.com'; $api_dll = 'ShippingAPI.dll'; break; case 'test': default: $usps_server = 'stg-production.shippingapis.com'; $api_dll = 'shippingapi.dll'; break; } $body = ''; $http = new httpClient(); if ($http->Connect($usps_server, 80)) { $http->addHeader('Host', $usps_server); $http->addHeader('User-Agent', 'osCommerce'); $http->addHeader('Connection', 'Close'); if ($http->Get('/' . $api_dll . '?' . $request)) { $body = $http->getBody(); } // mail('*****@*****.**','USPS rate quote response',$body,'From: <*****@*****.**>'); if ($transit && is_array($transreq) && $order->delivery['country']['id'] == STORE_COUNTRY) { while (list($key, $value) = each($transreq)) { if ($http->Get('/' . $api_dll . '?' . $value)) { $transresp[$key] = $http->getBody(); } } } $http->Disconnect(); } else { return false; } $response = array(); while (true) { if ($start = strpos($body, '<Package ID=')) { $body = substr($body, $start); $end = strpos($body, '</Package>'); $response[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $rates = array(); if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { if (sizeof($response) == '1') { if (ereg('<Error>', $response[0])) { $number = ereg('<Number>(.*)</Number>', $response[0], $regs); $number = $regs[1]; $description = ereg('<Description>(.*)</Description>', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } } $n = sizeof($response); for ($i = 0; $i < $n; $i++) { if (strpos($response[$i], '<Postage>')) { $service = ereg('<Service>(.*)</Service>', $response[$i], $regs); $service = $regs[1]; $postage = ereg('<Postage>(.*)</Postage>', $response[$i], $regs); $postage = $regs[1]; $rates[] = array($service => $postage); if ($transit) { switch ($service) { case 'Express': $time = ereg('<MonFriCommitment>(.*)</MonFriCommitment>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } else { $time = 'Tomorrow by ' . $time; } break; case 'Priority': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } elseif ($time == '1') { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } break; case 'Parcel': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } elseif ($time == '1') { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } break; case 'First Class': $time = '2 - 5 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; break; default: $time = ''; break; } if ($time != '') { $transittime[$service] = ' (' . $time . ')'; } } } } } else { if (ereg('<Error>', $response[0])) { $number = ereg('<Number>(.*)</Number>', $response[0], $regs); $number = $regs[1]; $description = ereg('<Description>(.*)</Description>', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } else { $body = $response[0]; $services = array(); while (true) { if ($start = strpos($body, '<Service ID=')) { $body = substr($body, $start); $end = strpos($body, '</Service>'); $services[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $allowed_types = array(); foreach (explode(", ", MODULE_SHIPPING_USPS_TYPES_INTL) as $value) { $allowed_types[$value] = $this->intl_types[$value]; } $size = sizeof($services); for ($i = 0, $n = $size; $i < $n; $i++) { if (strpos($services[$i], '<Postage>')) { $service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs); $service = $regs[1]; $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); $postage = $regs[1]; $time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs); $time = $tregs[1]; $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time); $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time); $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time); if (!in_array($service, $allowed_types)) { continue; } if (isset($this->service) && $service != $this->service) { continue; } $rates[] = array($service => $postage); if ($time != '') { $transittime[$service] = ' (' . $time . ')'; } } } } } return sizeof($rates) > 0 ? $rates : false; }
/** * Get actual quote from USPS * * @return array of results or boolean false if no results */ function _getQuote() { // BOF: UPS USPS global $order, $transittime; if (in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) { $transit = TRUE; } // EOF: UPS USPS // translate for US Territories // if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY || SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US') { $request = '<RateV3Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">'; $services_count = 0; if (isset($this->service)) { $this->types = array($this->service => $this->types[$this->service]); } $dest_zip = str_replace(' ', '', $order->delivery['postcode']); // translate for US Territories if ($order->delivery['country']['iso_code_2'] == 'US' || SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US') { $dest_zip = substr($dest_zip, 0, 5); } reset($this->types); // BOF: UPS USPS $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES); while (list($key, $value) = each($this->types)) { // BOF: UPS USPS if (!in_array($key, $allowed_types)) { continue; } //For Options list, go to page 6 of document: http://www.usps.com/webtools/_pdf/Rate-Calculators-v1-2.pdf //FIRST CLASS MAIL OPTIONS if ($key == 'FIRST CLASS') { $this->FirstClassMailType = '<FirstClassMailType>LETTER</FirstClassMailType>'; } else { $this->FirstClassMailType = ''; } //PRIORITY MAIL OPTIONS if ($key == 'PRIORITY') { $this->container = ''; // Blank, Flate Rate Envelope, or Flat Rate Box // Sm Flat Rate Box, Md Flat Rate Box and Lg Flat Rate Box } //EXPRESS MAIL OPTIONS if ($key == 'EXPRESS') { $this->container = ''; // Blank, or Flate Rate Envelope } //PARCEL POST OPTIONS if ($key == 'PARCEL') { $this->container = 'Regular'; $this->machinable = 'true'; } //BPM OPTIONS //MEDIA MAIL OPTIONS //LIBRARY MAIL OPTIONS $request .= '<Package ID="' . $services_count . '">' . '<Service>' . $key . '</Service>' . '<FirstClassMailType>' . $this->fctype . '</FirstClassMailType>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container>' . $this->container . '</Container>' . '<Size>' . $this->size . '</Size>' . '<Machinable>' . $this->machinable . '</Machinable>' . '</Package>'; // BOF: UPS USPS if ($transit) { $transitreq = 'USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<OriginZip>' . STORE_ORIGIN_ZIP . '</OriginZip>' . '<DestinationZip>' . $dest_zip . '</DestinationZip>'; switch ($key) { case 'EXPRESS': $transreq[$key] = 'API=ExpressMail&XML=' . urlencode('<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>'); break; case 'PRIORITY': $transreq[$key] = 'API=PriorityMail&XML=' . urlencode('<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); break; case 'PARCEL': $transreq[$key] = 'API=StandardB&XML=' . urlencode('<StandardBRequest ' . $transitreq . '</StandardBRequest>'); break; default: $transreq[$key] = ''; break; } } // EOF: UPS USPS $services_count++; } $request .= '</RateV3Request>'; $request = 'API=RateV3&XML=' . urlencode($request); } else { $request = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>Package</MailType>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '</Package>' . '</IntlRateRequest>'; $request = 'API=IntlRate&XML=' . urlencode($request); } switch (MODULE_SHIPPING_USPS_SERVER) { case 'production': $usps_server = 'production.shippingapis.com'; $api_dll = 'shippingapi.dll'; break; case 'test': default: $usps_server = 'testing.shippingapis.com'; $api_dll = 'ShippingAPI.dll'; break; } $body = ''; $http = new httpClient(); $http->timeout = 5; if ($http->Connect($usps_server, 80)) { $http->addHeader('Host', $usps_server); $http->addHeader('User-Agent', 'Zen Cart'); $http->addHeader('Connection', 'Close'); if ($http->Get('/' . $api_dll . '?' . $request)) { $body = $http->getBody(); } 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 . '>'); } // BOF: UPS USPS // translate for US Territories // if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) { if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY || SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) { while (list($key, $value) = each($transreq)) { if ($http->Get('/' . $api_dll . '?' . $value)) { $transresp[$key] = $http->getBody(); } } } // EOF: UPS USPS $http->Disconnect(); } else { return -1; } $response = array(); while (true) { if ($start = strpos($body, '<Package ID=')) { $body = substr($body, $start); $end = strpos($body, '</Package>'); $response[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $rates = array(); // translate for US Territories // if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY || SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US') { if (sizeof($response) == '1') { if (preg_match('/<Error>/i', $response[0])) { $number = preg_match('/<Number>(.*)<\\/Number>/msi', $response[0], $regs); $number = $regs[1]; $description = preg_match('/<Description>(.*)<\\/Description>/msi', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } } $n = sizeof($response); for ($i = 0; $i < $n; $i++) { if (strpos($response[$i], '<Rate>')) { $service = preg_match('/<MailService>(.*)<\\/MailService>/msi', $response[$i], $regs); $service = $regs[1]; if (preg_match('/Express/i', $service)) { $service = 'EXPRESS'; } if (preg_match('/Priority/i', $service)) { $service = 'PRIORITY'; } if (preg_match('/First-Class Mail/i', $service)) { $service = 'FIRST CLASS'; } if (preg_match('/Parcel/i', $service)) { $service = 'PARCEL'; } if (preg_match('/Media/i', $service)) { $service = 'MEDIA'; } if (preg_match('/Bound Printed/i', $service)) { $service = 'BPM'; } if (preg_match('/Library/i', $service)) { $service = 'LIBRARY'; } $postage = preg_match('/<Rate>(.*)<\\/Rate>/msi', $response[$i], $regs); $postage = $regs[1]; $rates[] = array($service => $postage); // BOF: UPS USPS if ($transit) { switch ($service) { case 'EXPRESS': $time = preg_match('/<MonFriCommitment>(.*)<\\/MonFriCommitment>/msi', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } else { $time = 'Tomorrow by ' . $time; } break; case 'PRIORITY': $time = preg_match('/<Days>(.*)<\\/Days>/msi', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } elseif ($time == '1') { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } break; case 'PARCEL': $time = preg_match('/<Days>(.*)<\\/Days>/msi', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } elseif ($time == '1') { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } break; case 'FIRST CLASS': $time = '2 - 5 ' . MODULE_SHIPPING_USPS_TEXT_DAYS; break; default: $time = ''; break; } if ($time != '') { $transittime[$service] = ' (' . $time . ')'; } } // EOF: UPS USPS } } } else { if (preg_match('/<Error>/i', $response[0])) { $number = preg_match('/<Number>(.*)<\\/Number>/msi', $response[0], $regs); $number = $regs[1]; $description = preg_match('/<Description>(.*)<\\/Description>/msi', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } else { $body = $response[0]; $services = array(); while (true) { if ($start = strpos($body, '<Service ID=')) { $body = substr($body, $start); $end = strpos($body, '</Service>'); $services[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } // BOF: UPS USPS $allowed_types = array(); foreach (explode(", ", MODULE_SHIPPING_USPS_TYPES_INTL) as $value) { $allowed_types[$value] = $this->intl_types[$value]; } // EOF: UPS USPS $size = sizeof($services); for ($i = 0, $n = $size; $i < $n; $i++) { if (strpos($services[$i], '<Postage>')) { $service = preg_match('/<SvcDescription>(.*)<\\/SvcDescription>/msi', $services[$i], $regs); $service = $regs[1]; $postage = preg_match('/<Postage>(.*)<\\/Postage>/i', $services[$i], $regs); $postage = $regs[1]; // BOF: UPS USPS $time = preg_match('/<SvcCommitments>(.*)<\\/SvcCommitments>/msi', $services[$i], $tregs); $time = $tregs[1]; $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time); $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time); $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time); if (!in_array($service, $allowed_types)) { continue; } if ($_SESSION['cart']->total > 400 && strstr($services[$i], 'Priority Mail International Flat Rate Envelope')) { continue; } // skip value > $400 Priority Mail International Flat Rate Envelope // EOF: UPS USPS if (isset($this->service) && $service != $this->service) { continue; } $rates[] = array($service => $postage); // BOF: UPS USPS if ($time != '') { $transittime[$service] = ' (' . $time . ')'; } // EOF: UPS USPS } } } } //echo 'RATE RESPONSE: ' . "\n" . print_r($rates); return sizeof($rates) > 0 ? $rates : false; }
function _getIntlQuote($pkg, $method) { global $order; if (tep_not_null($method) && in_array($method, $this->intl_available)) { $request_types = array($method); } else { $request_types = $this->intl_available; } $this->intl_request_types = $request_types; $shipping_weight = $pkg['item_weight'] < 0.0625 ? 0.0625 : $pkg['item_weight']; $shipping_pounds = floor($shipping_weight); $shipping_ounces = ceil(16 * ($shipping_weight - $shipping_pounds) * 100) / 100; // rounded to two decimal digits $nonuspsinsurancecost = 0; if (MODULE_SHIPPING_USPS_NON_USPS_INSURE == 'True') { if ($pkg['item_price'] <= 50) { $nonuspsinsurancecost = MODULE_SHIPPING_USPS_INS1; } else { if ($pkg['item_price'] <= 100) { $nonuspsinsurancecost = MODULE_SHIPPING_USPS_INS2; } else { if ($pkg['item_price'] <= 200) { $nonuspsinsurancecost = MODULE_SHIPPING_USPS_INS3; } else { if ($pkg['item_price'] <= 300) { $nonuspsinsurancecost = MODULE_SHIPPING_USPS_INS4; } else { $nonuspsinsurancecost = MODULE_SHIPPING_USPS_INS4 + (ceil($pkg['item_price'] / 100) - 3) * MODULE_SHIPPING_USPS_INS5; } } } } } if (empty($this->intl_maxinsure) || MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'False') { $checkvalues = array($pkg['item_price']); } else { $checkvalues = array(); foreach ($this->intl_maxinsure as $maxins) { if ($pkg['item_price'] <= $maxins) { $checkvalues[] = $pkg['item_price']; break; // stop once we find package value is less than allowed maximum } else { $checkvalues[] = $maxins; } } } rsort($checkvalues); // values must be checked in reverse order $request = '<IntlRateV2Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Revision>2</Revision>'; foreach ($checkvalues as $pkgvalue) { $request .= '<Package ID="' . intval($pkgvalue) . '">' . '<Pounds>' . $shipping_pounds . '</Pounds>' . '<Ounces>' . $shipping_ounces . '</Ounces>' . '<Machinable>True</Machinable>' . '<MailType>All</MailType>' . '<GXG>' . '<POBoxFlag>N</POBoxFlag>' . '<GiftFlag>N</GiftFlag>' . '</GXG>' . '<ValueOfContents>' . number_format($pkgvalue, 2, '.', '') . '</ValueOfContents>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '<Container>RECTANGULAR</Container>' . '<Size>' . (max($pkg['item_length'], $pkg['item_width'], $pkg['item_height']) > 12 ? ' LARGE' : 'REGULAR') . '</Size>' . '<Width>' . $pkg['item_width'] . '</Width>' . '<Length>' . $pkg['item_length'] . '</Length>' . '<Height>' . $pkg['item_height'] . '</Height>' . '<Girth>' . ($pkg['item_height'] + $pkg['item_height'] + $pkg['item_width'] + $pkg['item_width']) . '</Girth>' . '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' . '<CommercialFlag>Y</CommercialFlag>' . '<ExtraServices>' . '<ExtraService>1</ExtraService>' . '</ExtraServices>' . '</Package>'; } $request .= '</IntlRateV2Request>'; $request = 'API=IntlRateV2&XML=' . urlencode($request); $usps_server = 'production.shippingapis.com'; $api_dll = 'shippingAPI.dll'; $body = ''; if (!class_exists('httpClient')) { include DIR_FS_CATALOG . DIR_WS_CLASSES . 'http_client.php'; } $http = new httpClient(); if ($http->Connect($usps_server, 80)) { $http->addHeader('Host', $usps_server); $http->addHeader('User-Agent', 'osCommerce'); $http->addHeader('Connection', 'Close'); if ($http->Get('/' . $api_dll . '?' . $request)) { $body = $http->getBody(); } $http->Disconnect(); } else { $body = '<Error><Number></Number><Description>' . MODULE_SHIPPING_USPS_TEXT_CONNECTION_ERROR . '</Description></Error>'; } $doc = XML_unserialize($body); // print_R( $doc ); // exit; $quotes = array(); if (isset($doc['Error'])) { return array('error' => $doc['Error']['Number'] . ' ' . $doc['Error']['Description']); } if (isset($doc['IntlRateV2Response']['Package']['Error'])) { return array('error' => $doc['IntlRateV2Response']['Package']['Error']['Number'] . ' ' . $doc['IntlRateV2Response']['Package']['Error']['Description']); } if (isset($doc['IntlRateV2Response']['Package'][0]['Error'])) { return array('error' => $doc['IntlRateV2Response']['Package']['Error'][0]['Number'] . ' ' . $doc['IntlRateV2Response']['Package'][0]['Error']['Description']); } if (isset($doc['IntlRateV2Response']['Package']['Service']['SvcDescription'])) { // single mail service response $tmp = $this->_decode_intl_response($doc['RateV4Response']['Package']['Service'], $nonuspsinsurancecost, $pkg['item_price']); if (!empty($tmp)) { $quotes[$tmp['id']] = $tmp; } } elseif (isset($doc['IntlRateV2Response']['Package']['Service'][0])) { // multiple mailing services returned foreach ($doc['IntlRateV2Response']['Package']['Service'] as $mailsvc) { if (isset($mailsvc['SvcDescription'])) { $tmp = $this->_decode_intl_response($mailsvc, $nonuspsinsurancecost, $pkg['item_price']); if (!empty($tmp)) { $quotes[$tmp['id']] = $tmp; } } } } elseif (isset($doc['IntlRateV2Response']['Package'][0]['Service'])) { // multiple packages requested for insurance purposes foreach ($doc['IntlRateV2Response']['Package'] as $package) { if (isset($package['Service']['SvcDescription'])) { // single mail service response for package $tmp = $this->_decode_intl_response($package['Service'], $nonuspsinsurancecost, $pkg['item_price']); if (!empty($tmp)) { if (!isset($quotes[$tmp['id']])) { $quotes[$tmp['id']] = $tmp; } } // save only first valid response } elseif (isset($package['Service'][0])) { // multiple mailing services returned for package foreach ($package['Service'] as $mailsvc) { if (isset($mailsvc['SvcDescription'])) { $tmp = $this->_decode_intl_response($mailsvc, $nonuspsinsurancecost, $pkg['item_price']); if (!empty($tmp)) { if (!isset($quotes[$tmp['id']])) { $quotes[$tmp['id']] = $tmp; } } // save only first valid response } } } } } return $quotes; }
echo "<br>\n );<br>\n"; // international $intl_types = array(); $x = array(array('l' => 16, 'w' => 12, 'h' => 3, 'g' => 20, 'c' => 'NONRECTANGULAR', 'p' => 10, 'o' => 10), array('l' => 5, 'w' => 3, 'h' => 0.1, 'g' => 6.2, 'c' => 'RECTANGULAR', 'p' => 0, 'o' => 1)); foreach ($x as $d) { // international requires two requests to get all types $request = '<IntlRateV2Request USERID="' . $id . '"><Revision>2</Revision><Package ID="1st"><Pounds>' . $d['p'] . '</Pounds><Ounces>' . $d['o'] . '</Ounces><Machinable>true</Machinable><MailType>All</MailType><GXG><POBoxFlag>N</POBoxFlag><GiftFlag>N</GiftFlag></GXG><ValueOfContents>0</ValueOfContents><Country>Canada</Country><Container>' . $d['c'] . '</Container><Size>' . (max($d['w'], $d['l'], $d['h']) > 12 ? 'LARGE' : 'REGULAR') . '</Size><Width>' . $d['w'] . '</Width><Length>' . $d['l'] . '</Length><Height>' . $d['h'] . '</Height><Girth>' . $d['g'] . '</Girth></Package></IntlRateV2Request>'; $request = 'API=IntlRateV2&XML=' . urlencode($request); $usps_server = 'production.shippingapis.com'; $api_dll = 'shippingAPI.dll'; $body = ''; if (!class_exists('httpClient')) { include DIR_FS_CATALOG . 'includes/classes/http_client.php'; } $http = new httpClient(); if ($http->Connect($usps_server, 80)) { $http->addHeader('Host', $usps_server); $http->addHeader('User-Agent', 'osCommerce'); $http->addHeader('Connection', 'Close'); if ($http->Get('/' . $api_dll . '?' . $request)) { $body = $http->getBody(); } $http->Disconnect(); } else { $body = '<error>Connection Failed</error>'; } $doc = XML_unserialize($body); $usps_intl_types = array(); if (isset($doc['IntlRateV2Response']['Package']['Service'])) { foreach ($doc['IntlRateV2Response']['Package']['Service'] as $key => $method) { if (isset($method['SvcDescription'])) {
function _getQuote() { global $order, $transittime, $dispinsure; if (MODULE_SHIPPING_USPS_INSURE_TAX) { $insurable = $order->info['subtotal'] + $order->info['tax']; } else { $insurable = $order->info['subtotal']; } $transit = in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS)); $dispinsurance = in_array('Display insurance', explode(', ', MODULE_SHIPPING_USPS_OPTIONS)); $Authentication = explode(", ", MODULE_SHIPPING_USPS_USERID); if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { $request = '<RateV4Request USERID="' . $Authentication[0] . '" PASSWORD="******">' . '<Revision>2</Revision>'; $services_count = 0; if (isset($this->service)) { $this->types = array($this->service => $this->types[$this->service]); } $dest_zip = str_replace(' ', '', $order->delivery['postcode']); if ($order->delivery['country']['iso_code_2'] == 'US') { $dest_zip = substr($dest_zip, 0, 5); } reset($this->types); ///////////////////////////////////////// //// REQUEST IF WITHIN ALLOWED LIST ///// ///////////////////////////////////////// $allowed_types = explode(", ", MODULE_SHIPPING_USPS_DMSTC_TYPES); while (list($key, $value) = each($this->types)) { if (!in_array($key, $allowed_types)) { continue; } ///////////////////////////////////////// // REQUEST IF WITHIN WEIGHT THRESHOLDS // ///////////////////////////////////////// $FMT = explode(", ", MODULE_SHIPPING_USPS_DMSTC_FIRSTCLASS_THRESHOLD); if ($key == 'First-Class Mail regimark') { $transid = $key; $key = 'First-Class Mail'; if ($this->pounds == 0) { if ($FMT[0] < $this->ounces && $this->ounces <= $FMT[1]) { $transid = 'First-Class Mail regimark Letter'; $this->FirstClassMailType = 'LETTER'; $this->machinable = 'TRUE'; $this->size = 'REGULAR'; $this->container = 'VARIABLE'; } else { if ($FMT[2] < $this->ounces && $this->ounces <= $FMT[3]) { $transid = 'First-Class Mail regimark Large Envelope'; $this->FirstClassMailType = 'FLAT'; $this->machinable = 'TRUE'; $this->size = 'REGULAR'; $this->container = 'VARIABLE'; } else { if ($FMT[4] < $this->ounces && $this->ounces <= $FMT[5]) { $transid = 'First-Class Mail regimark Package'; $this->FirstClassMailType = 'PARCEL'; $this->machinable = 'TRUE'; $this->size = 'REGULAR'; $this->container = 'VARIABLE'; } else { $key = 'none'; } } } } } $OMT = explode(", ", MODULE_SHIPPING_USPS_DMSTC_OTHER_THRESHOLD); if ($key == 'Priority Mail regimark') { $transid = $key; if ($OMT[8] < $this->weight && $this->weight <= $OMT[9]) { $key = 'Priority Commercial'; $this->container = ''; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Priority Mail regimark Flat Rate Envelope') { $transid = $key; if ($OMT[0] < $this->weight && $this->weight <= $OMT[1]) { $key = 'Priority Commercial'; $this->container = 'FLAT RATE ENVELOPE'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Priority Mail regimark Small Flat Rate Box') { $transid = $key; if ($OMT[2] < $this->weight && $this->weight <= $OMT[3]) { $key = 'Priority Commercial'; $this->container = 'SM FLAT RATE BOX'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Priority Mail regimark Medium Flat Rate Box') { $transid = $key; if ($OMT[4] < $this->weight && $this->weight <= $OMT[5]) { $key = 'Priority Commercial'; $this->container = 'MD FLAT RATE BOX'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Priority Mail regimark Large Flat Rate Box') { $transid = $key; if ($OMT[6] < $this->weight && $this->weight <= $OMT[7]) { $key = 'Priority Commercial'; $this->container = 'LG FLAT RATE BOX'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Express Mail regimark') { $transid = $key; if ($OMT[12] < $this->weight && $this->weight <= $OMT[13]) { $this->container = ''; $key = 'Express Commercial'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Express Mail regimark Flat Rate Envelope') { $transid = $key; if ($OMT[10] < $this->weight && $this->weight <= $OMT[11]) { $key = 'Express Commercial'; $this->container = 'FLAT RATE ENVELOPE'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Parcel Post regimark') { $transid = $key; $key = 'Parcel Post'; if ($OMT[14] < $this->weight && $this->weight <= $OMT[15]) { $this->machinable = 'TRUE'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Media Mail regimark') { $transid = $key; $key = 'Media Mail'; if ($OMT[16] < $this->weight && $this->weight <= $OMT[17]) { $this->size = 'REGULAR'; } else { $key = 'none'; } } ///////////////////////////////////////////// // END REQUEST IF WITHIN WEIGHT THRESHOLDS // ///////////////////////////////////////////// $request .= '<Package ID="' . $services_count . '">' . '<Service>' . $key . '</Service>' . '<FirstClassMailType>' . $this->FirstClassMailType . '</FirstClassMailType>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container>' . $this->container . '</Container>' . '<Size>' . $this->size . '</Size>' . '<Value>' . $insurable . '</Value>' . '<Machinable>' . $this->machinable . '</Machinable>' . '<ShipDate>' . date('d-M-Y') . '</ShipDate>' . '</Package>'; ///////////////////////////////////////// ////// START USPS TRANSIT REQUEST /////// ///////////////////////////////////////// if ($transit) { $transitreq = 'USERID="' . $Authentication[0] . '">' . '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' . '<DestinationZip>' . $dest_zip . '</DestinationZip>'; switch ($key) { case 'First-Class Mail': $transreq[$transid] = 'API=PriorityMail&XML=' . urlencode('<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); break; case 'Media Mail': $transreq[$transid] = 'API=StandardB&XML=' . urlencode('<StandardBRequest ' . $transitreq . '</StandardBRequest>'); break; case 'Parcel Post': $transreq[$transid] = 'API=StandardB&XML=' . urlencode('<StandardBRequest ' . $transitreq . '</StandardBRequest>'); break; case 'Priority Commercial': $transreq[$transid] = 'API=PriorityMail&XML=' . urlencode('<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); break; default: $transreq[$transid] = ''; break; } } ///////////////////////////////////////// //////// END USPS TRANSIT REQUEST /////// ///////////////////////////////////////// $services_count++; } ///////////////////////////////////////// ////// END IF WITHIN ALLOWED LIST /////// ///////////////////////////////////////// $request .= '</RateV4Request>'; $request = 'API=RateV4&XML=' . urlencode($request); } else { $request = '<IntlRateV2Request USERID="' . $Authentication[0] . '">' . '<Revision>2</Revision>' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Machinable>True</Machinable>' . '<MailType>All</MailType>' . '<GXG>' . '<POBoxFlag>N</POBoxFlag>' . '<GiftFlag>N</GiftFlag>' . '</GXG>' . '<ValueOfContents>' . $insurable . '</ValueOfContents>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '<Container>RECTANGULAR</Container>' . '<Size>REGULAR</Size>'; $IPS = explode(", ", MODULE_SHIPPING_USPS_INTL_SIZE); $request .= '<Width>' . $IPS[0] . '</Width>' . '<Length>' . $IPS[1] . '</Length>' . '<Height>' . $IPS[2] . '</Height>' . '<Girth>' . $IPS[3] . '</Girth>' . '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' . '<CommercialFlag>Y</CommercialFlag>' . '<ExtraServices>' . '<ExtraService>1</ExtraService>' . '<ExtraService>2</ExtraService>' . '</ExtraServices>' . '</Package>' . '</IntlRateV2Request>'; $request = 'API=IntlRateV2&XML=' . urlencode($request); } ///////////////////////////////////////// //// END USPS INTERNATIONAL REQUEST ///// ///////////////////////////////////////// ///////////////////////////////////////// /////// USPS HTTP COMMUNICATION ///////// ///////////////////////////////////////// $usps_server = 'production.shippingapis.com'; $api_dll = 'shippingAPI.dll'; $body = ''; if (!class_exists('httpClient')) { include 'includes/classes/http_client.php'; } $http = new httpClient(); if ($http->Connect($usps_server, 80)) { $http->addHeader('Host', $usps_server); $http->addHeader('User-Agent', 'osCommerce'); $http->addHeader('Connection', 'Close'); if ($http->Get('/' . $api_dll . '?' . $request)) { $body = $http->getBody(); } #mail('*****@*****.**','USPS Rate Quote response',$body,'From: <*****@*****.**>'); if ($transit && is_array($transreq) && $order->delivery['country']['id'] == STORE_COUNTRY) { while (list($key, $value) = each($transreq)) { if ($http->Get('/' . $api_dll . '?' . $value)) { $transresp[$key] = $http->getBody(); } #mail('*****@*****.**','USPS Transit Response',$transresp[$key],'From: <*****@*****.**>'); } } $http->Disconnect(); } else { return false; } $body = htmlspecialchars_decode($body); $body = preg_replace('/\\<sup\\>\\&reg;\\<\\/sup\\>/', ' regimark', $body); $body = preg_replace('/\\<sup\\>\\&trade;\\<\\/sup\\>/', ' tradmrk', $body); ///////////////////////////////////////// /////END USPS HTTP COMMUNICATION //////// ///////////////////////////////////////// ///////////////////////////////////////// /////////// START RATE RESPONSE ///////// ///////////////////////////////////////// $response = array(); while (true) { if ($start = strpos($body, '<Package ID=')) { $body = substr($body, $start); $end = strpos($body, '</Package>'); $response[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $rates = array(); $rates_sorter = array(); if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { ///////////////////////////////////////// ///////// START DOMESTIC RESPONSE /////// ///////////////////////////////////////// if (sizeof($response) == '1') { if (preg_match('/<Error>/', $response[0])) { $number = preg_match('/<Number>(.*)<\\/Number>/', $response[0], $regs); $number = $regs[1]; $description = preg_match('/<Description>(.*)<\\/Description>/', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } } $n = sizeof($response); for ($i = 0; $i < $n; $i++) { if (strpos($response[$i], '<Rate>')) { $service = ereg('<MailService>(.*)</MailService>', $response[$i], $regs); $service = $regs[1]; if (MODULE_SHIPPING_USPS_DMSTC_RATE == 'Internet' && preg_match('/CommercialRate/', $response[$i])) { $postage = ereg('<CommercialRate>(.*)</CommercialRate>', $response[$i], $regs); $postage = $regs[1]; } else { $postage = ereg('<Rate>(.*)</Rate>', $response[$i], $regs); $postage = $regs[1]; } if (preg_match('/Insurance<\\/ServiceName><Available>true<\\/Available><AvailableOnline>true/', $response[$i])) { $insurance = ereg('Insurance</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>(.*)</Price>', $response[$i], $regs); $insurance = $regs[1]; } elseif (preg_match('/Insurance<\\/ServiceName><Available>true<\\/Available><AvailableOnline>false/', $response[$i])) { $insurance = ereg('Insurance</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>(.*)</Price>', $response[$i], $regs); $insurance = $regs[1]; } else { $insurance = 0; } if ($insurable <= 50) { $uinsurance = MODULE_SHIPPING_USPS_INS1; } else { if ($insurable <= 100) { $uinsurance = MODULE_SHIPPING_USPS_INS2; } else { if ($insurable <= 200) { $uinsurance = MODULE_SHIPPING_USPS_INS3; } else { if ($insurable <= 300) { $uinsurance = MODULE_SHIPPING_USPS_INS4; } else { $uinsurance = MODULE_SHIPPING_USPS_INS4 + (ceil($insurable / 100) - 3) * MODULE_SHIPPING_USPS_INS5; } } } } if (MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True' && MODULE_SHIPPING_USPS_INSURE == 'True') { $postage = $postage + max($insurance, $uinsurance); } elseif (MODULE_SHIPPING_USPS_INSURE == 'True') { $postage = $postage + $uinsurance; } elseif (MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True' && $insurance > 0) { $postage = $postage + $insurance; } if (MODULE_SHIPPING_USPS_DMST_DEL_CONF == 'True' && preg_match('/Delivery Confirmation tradmrk<\\/ServiceName><Available>true<\\/Available>/', $response[$i])) { if (MODULE_SHIPPING_USPS_DMSTC_RATE == 'Retail') { $del_conf = preg_match('/Delivery Confirmation tradmrk<\\/ServiceName><Available>true<\\/Available><AvailableOnline>true<\\/AvailableOnline><Price>(.*)<\\/Price>/', $response[$i], $regs); } elseif (MODULE_SHIPPING_USPS_DMSTC_RATE == 'Internet') { if (preg_match('/Delivery Confirmation tradmrk<\\/ServiceName><Available>true<\\/Available><AvailableOnline>true<\\/AvailableOnline><Price>0.70<\\/Price>/', $response[$i])) { $del_conf = preg_match('/Delivery Confirmation tradmrk<\\/ServiceName><Available>true<\\/Available><AvailableOnline>true<\\/AvailableOnline><Price>0.70<\\/Price><PriceOnline>(.*)<\\/PriceOnline>/', $response[$i], $regs); } elseif (preg_match('/Delivery Confirmation tradmrk<\\/ServiceName><Available>true<\\/Available><AvailableOnline>true<\\/AvailableOnline><Price>0.80<\\/Price>/', $response[$i])) { $del_conf = preg_match('/Delivery Confirmation tradmrk<\\/ServiceName><Available>true<\\/Available><AvailableOnline>true<\\/AvailableOnline><Price>0.80<\\/Price><PriceOnline>(.*)<\\/PriceOnline>/', $response[$i], $regs); } } $del_conf = $regs[1]; $postage = $postage + $del_conf; } if (MODULE_SHIPPING_USPS_DMST_SIG_CONF == 'True' && $this->sig_conf_thresh <= $order->info['subtotal'] && preg_match('/Signature Confirmation tradmrk<\\/ServiceName><Available>true<\\/Available>/', $response[$i])) { if (MODULE_SHIPPING_USPS_DMSTC_RATE == 'Retail') { $sig_conf = preg_match('/Signature Confirmation tradmrk<\\/ServiceName><Available>true<\\/Available><AvailableOnline>true<\\/AvailableOnline><Price>(.*)<\\/Price>/', $response[$i], $regs); } elseif (MODULE_SHIPPING_USPS_DMSTC_RATE == 'Internet') { $sig_conf = preg_match('/Signature Confirmation tradmrk<\\/ServiceName><Available>true<\\/Available><AvailableOnline>true<\\/AvailableOnline><Price>2.35<\\/Price><PriceOnline>(.*)<\\/PriceOnline>/', $response[$i], $regs); } $sig_conf = $regs[1]; $postage = $postage + $sig_conf; } switch ($service) { case 'First-Class Mail regimark': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[0]; break; case 'First-Class Mail regimark Letter': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[0]; break; case 'First-Class Mail regimark Large Envelope': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[0]; break; case 'First-Class Mail regimark Package': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[0]; break; case 'Media Mail regimark': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[1]; break; case 'Parcel Post regimark': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[2]; break; case 'Priority Mail regimark': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[3]; break; case 'Priority Mail regimark Flat Rate Envelope': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[4]; break; case 'Priority Mail regimark Small Flat Rate Box': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[5]; break; case 'Priority Mail regimark Medium Flat Rate Box': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[6]; break; case 'Priority Mail regimark Large Flat Rate Box': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == 'Military Mail') { $time = $time; } else { if ($this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing); } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } } $message = ereg('<Message>(.*)</Message>', $transresp[$service], $mess); $message = $mess[1]; if ($message != '') { $time .= ' - ' . $message; } $postage = $postage + $this->dmstc_handling[7]; break; case 'Express Mail regimark': $time = ereg('<CommitmentDate>(.*)</CommitmentDate>', $response[$i], $regs); $time = $regs[1]; if ($time == 'Overnight to many areas' && $this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($this->processing + 1) . MODULE_SHIPPING_USPS_TEXT_DAYS; } elseif ($time == 'Overnight to many areas') { $time = '---' . $time; } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } elseif ($time > '2' && $time <= '9') { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[8]; break; case 'Express Mail regimark Flat Rate Envelope': $time = ereg('<CommitmentDate>(.*)</CommitmentDate>', $response[$i], $regs); $time = $regs[1]; if ($time == 'Overnight to many areas' && $this->processing > 0) { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($this->processing + 1) . MODULE_SHIPPING_USPS_TEXT_DAYS; } elseif ($time == 'Overnight to many areas') { $time = '---' . $time; } else { $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time; } if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } elseif ($time > '2' && $time <= '9') { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[8]; break; } if ($dispinsurance && (MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True' && $insurance > 0 || MODULE_SHIPPING_USPS_INSURE == 'True' && $uinsurance > 0)) { $dispinsure[$service] = '<br>' . MODULE_SHIPPING_USPS_TEXT_INSURED . '$' . tep_round_up($insurable, 2); } else { $dispinsure[$service] = ''; } if ($transit && $time != '') { $transittime[$service] = '<br>' . $time; } else { $transittime[$service] = ''; } $rates[] = array($service => $postage); $rates_sorter[] = $postage; } } } else { if (ereg('<Error>', $response[0])) { $number = ereg('<Number>(.*)</Number>', $response[0], $regs); $number = $regs[1]; $description = ereg('<Description>(.*)</Description>', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } else { $body = $response[0]; $services = array(); while (true) { if ($start = strpos($body, '<Service ID=')) { $body = substr($body, $start); $end = strpos($body, '</Service>'); $services[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $allowed_types = array(); foreach (explode(", ", MODULE_SHIPPING_USPS_INTL_TYPES) as $value) { $allowed_types[$value] = $this->intl_types[$value]; } $size = sizeof($services); for ($i = 0, $n = $size; $i < $n; $i++) { if (strpos($services[$i], '<Postage>')) { $service = preg_match('/<SvcDescription>(.*)<\\/SvcDescription>/', $services[$i], $regs); $service = $regs[1]; $CMP = preg_match('/<CommercialPostage>(.*)<\\/CommercialPostage>/', $services[$i], $regs); $CMP = $regs[1]; if ($CMP == 0) { $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); $postage = $regs[1]; } else { switch (MODULE_SHIPPING_USPS_INTL_RATE) { case 'Internet': if (preg_match('/<CommercialPostage>/', $services[$i])) { $postage = ereg('<CommercialPostage>(.*)</CommercialPostage>', $services[$i], $regs); $postage = $regs[1]; } else { $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); $postage = $regs[1]; } break; case 'Retail': $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); $postage = $regs[1]; break; } } $postage = $postage + $this->intl_handling[0]; if (preg_match('/Insurance<\\/ServiceName><Available>True/', $services[$i])) { $iinsurance = ereg('Insurance</ServiceName><Available>True</Available><Price>(.*)</Price>', $services[$i], $regs); $iinsurance = $regs[1]; } else { $iinsurance = 0; } if ($insurable <= 50) { $iuinsurance = MODULE_SHIPPING_USPS_INS1; } else { if ($insurable <= 100) { $iuinsurance = MODULE_SHIPPING_USPS_INS2; } else { if ($insurable <= 200) { $iuinsurance = MODULE_SHIPPING_USPS_INS3; } else { if ($insurable <= 300) { $iuinsurance = MODULE_SHIPPING_USPS_INS4; } else { $iuinsurance = MODULE_SHIPPING_USPS_INS4 + (ceil($insurable / 100) - 3) * MODULE_SHIPPING_USPS_INS5; } } } } if (MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'True' && MODULE_SHIPPING_USPS_INSURE == 'True') { $postage = $postage + max($iinsurance, $iuinsurance); } elseif (MODULE_SHIPPING_USPS_INSURE == 'True') { $postage = $postage + $iuinsurance; } elseif (MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'True') { $postage = $postage + $iinsurance; } $time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs); $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $tregs[1]; $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time); $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time); $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time); if (!in_array($service, $allowed_types)) { continue; } if (isset($this->service) && $service != $this->service) { continue; } if ($dispinsurance && (MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'True' && $iinsurance > 0 || MODULE_SHIPPING_USPS_INSURE == 'True' && $iuinsurance > 0)) { $dispinsure[$service] = '<br>' . MODULE_SHIPPING_USPS_TEXT_INSURED . '$' . tep_round_up($insurable, 2); } else { $dispinsure[$service] = ''; } if ($transit && $time != '') { $transittime[$service] = '<br>' . $time; } else { $transittime[$service] = ''; } $rates[] = array($service => $postage); $rates_sorter[] = $postage; } } } } asort($rates_sorter); $sorted_rates = array(); foreach (array_keys($rates_sorter) as $key) { $sorted_rates[] = $rates[$key]; } ///////////////////////////////////////// /////// END INTERNATIONAL RESPONSE ////// ///////////////////////////////////////// return sizeof($sorted_rates) > 0 ? $sorted_rates : false; }
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Payworks</title> </head> <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"> <?php require 'http_client.php'; $http = new httpClient(); $http->Connect("eps.banorte.com", 443) or die("Connect problem"); $params = array("Name" => "usuario_comercio", "Password" => "password_comercio", "ClientId" => "00000", "Mode" => "R", "TransType" => "Auth", "Number" => "4111111111111111", "Expires" => "01/16", "Cvv2Indicator" => "1", "Cvv2Val" => "000", "Total" => ".10", 'OrderId' => '84216', 'ChargeDesc1' => 'DESCRIPCION DEL CARGO'); $status = $http->Post("/recibo", $params); $raw = array('ResponseCode' => $status, 'CcErrCode' => $http->getHeader("CcErrCode"), 'AuthCode' => $http->getHeader("AuthCode"), 'Text' => $http->getHeader("Text"), 'CcReturnMsg' => $http->getHeader("CcReturnMsg"), 'ProcReturnMsg' => $http->getHeader("ProcReturnMsg"), 'Total' => $http->getHeader("Total")); $http->Disconnect(); if ($http->getHeader("CcErrCode") == 1) { echo "<b>¡Aprobada! transacción: " . $http->getHeader('AuthCode') . " </b>"; } else { echo "<b>¡Declinada!, motivo: " . $http->getHeader('Text') . " </b>"; } ?> <pre> <?php echo print_r($raw); ?> </pre> </body> </html>