Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] - USPS Methods


Recommended Posts

This is the best USPS module out there, bar none.

Worked right off the bat for me, first install.

 

I'd like to know if there's any way to turn off domestic shipments altogether. I offer USPS on international shipments only . I tried unchecking all domestic options but then it returns the "An error occured with the USPS shipping calculations" when the shipping destination is domestic.

 

Thanks

Link to comment
Share on other sites

Problem with module.

 

Normally it works fine, however today got an order for 2 items. Shipped in flat rate medium priority box.

 

I have the option set for all shipments types have a 2.50 handling fee. It was not added.

 

Also in the website addon description, should not the link to the forum be added? I found the link in the instructions.

 

Thanks!

Link to comment
Share on other sites

The more I read the more confussed I'm getting. crying.gif

 

Here's where I am at:

Either - version 2.9.2 uppercase fix + insurance by bkpie 19 Nov 2007 or (I think this one) version 3.0 by olsonsp4c (Scott) 29 Feb 2008.

Either way it works without any problems.

I only ship domestic, insurance is turned on in admin (not a customers option).

 

Up until now my shipping has been; Parcel Post, Priority Mail, and Express Mail.

No problems since even my smallest items shipped in a box.

 

But now I have a dilemma...

 

I am now carrying products that get shipped out First-Class, small (non-machineable) & large envelopes up to 13 ounces.

I also have some products that are under 13 ounces but need to be shipped in a box, not envelope.

Tried working out in Admin > Shipping/Packaging the tare weight and Larger Packages - percentage increase and came close.

BUT of course First-Class still shows as an option for the under 13 ounce items that need a box.

 

Is there a version that might help me work out a way to seperate what would be allowed shipping via First-Class?

 

Customers aren't really happy to see an envelope arrive with $0.64 postage after they were billed $3.45. whistling.gif

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

Sounds like a hard one. Just print postal through paypal.com/shipnow (no monthly) or stamps.com (monthly fee) and choose hidden postage. $2 handling is fine. I charge more for express shipments that I have to run to the post office myself for a rush order.

 

 

 

The more I read the more confussed I'm getting. crying.gif

 

Here's where I am at:

Either - version 2.9.2 uppercase fix + insurance by bkpie 19 Nov 2007 or (I think this one) version 3.0 by olsonsp4c (Scott) 29 Feb 2008.

Either way it works without any problems.

I only ship domestic, insurance is turned on in admin (not a customers option).

 

Up until now my shipping has been; Parcel Post, Priority Mail, and Express Mail.

No problems since even my smallest items shipped in a box.

 

But now I have a dilemma...

 

I am now carrying products that get shipped out First-Class, small (non-machineable) & large envelopes up to 13 ounces.

I also have some products that are under 13 ounces but need to be shipped in a box, not envelope.

Tried working out in Admin > Shipping/Packaging the tare weight and Larger Packages - percentage increase and came close.

BUT of course First-Class still shows as an option for the under 13 ounce items that need a box.

 

Is there a version that might help me work out a way to seperate what would be allowed shipping via First-Class?

 

Customers aren't really happy to see an envelope arrive with $0.64 postage after they were billed $3.45. whistling.gif

Link to comment
Share on other sites

Sounds like a hard one. Just print postal through paypal.com/shipnow (no monthly) or stamps.com (monthly fee) and choose hidden postage. $2 handling is fine. I charge more for express shipments that I have to run to the post office myself for a rush order.

 

I wouldn't mind printing and hidding the postage, but a lot of customers get scared off during checkout when they see what shipping is costing them compared to other sites selling similar items.

 

sad.gif

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

I doubt anyone is comparing postage for $1-2. If your clients are that worried rather than be concerned with the personal customer service that you provide, perhaps you are in the wrong business selling those widgets.

 

Too bad instead of a min order fee there is just a min postage fee.

 

$5 for all postage under $5 and actual postage for anything over.

 

I wouldn't mind printing and hidding the postage, but a lot of customers get scared off during checkout when they see what shipping is costing them compared to other sites selling similar items.

 

sad.gif

Link to comment
Share on other sites

Hey guys, I'm sorry if I sounds noobish but that's pretty much the case with myself working with oscommerce. Does the "USPS Methods" module contain in itself everything that you need to set up USPS quotes or do you need the "United States Postal Service" Module as well? Or is there another module for USPS API V3? I'm sorry, I'm totally lost and I just want to get the shipping set up so that I can get some items up on my site =p

 

Thanks a lot!

 

James

Link to comment
Share on other sites

Hi, i installed the version 4.3.2 and it has threshold limits settings for domestic shippings. I wanted to put a limit of 13oz for the First-Class Mail International and 4LBs for Priority Mail International, is there a simple way I can do this? it can be hard coded and does not need to be adjustable in admin. Please help with the codes. Thank you.

Link to comment
Share on other sites

Which version should I use?

 

USPS Methods for USPS XML API v3 - 26 Feb 2010,

USPS Methods for API v3 (osC 2.2) - 19 Feb 2010 or

USPS Methods 4.3.2 Fix international services - 8 Jan 2010?

 

The 4.3.2 file has installation instructions. Should I use this verision as a base install and then update wiht USPS XML API v3?

 

thx

Link to comment
Share on other sites

Hey guys, I'm sorry if I sounds noobish but that's pretty much the case with myself working with oscommerce. Does the "USPS Methods" module contain in itself everything that you need to set up USPS quotes or do you need the "United States Postal Service" Module as well? Or is there another module for USPS API V3? I'm sorry, I'm totally lost and I just want to get the shipping set up so that I can get some items up on my site =p

 

Thanks a lot!

 

James

 

Hey James,

 

I'm not sure about the newer versions of the module, but I am using version 2.9.2 or 3 and all that was needed was the module, nothing else.

 

The only "real" updates that where needed for my version since it's release was regarding international shipping. If I remember correctly (I don't ship international so I didn't bother) the shipping classes where changed from lowercase letters to capitals. There might have been one or two others not sure.

 

Hope that helps spread a little light on what you need. wink.gif

 

P.S. Don't forget, you need to establish an account with USPS. smile.gif

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

  • 1 month later...

I am using version 2.7d

 

Here is what I noticed. I have only the Express and Priority Mail shipping method active. At checkout, no matter which shipping method you choose, Express is the one that gets added to the order. This happens every time so I had to remove the Express and now only offer Priority Mail shipping.

 

Is there a fix for this?

 

Also, I do not have handling fees added and no matter what the weight if the item is, checkout will always add between $2.65 and $3.50 to the shipping amount. Why is this?

Thanks,

Scooter

Link to comment
Share on other sites

  • 3 weeks later...

Hi, I am new to OS commerce programming but I have osCommerce Online Merchant v2.2 RC 2a.

 

I just installed a new add-on "USPS Methods 4.3.2 Fix international services" from scratch. I can see usps module from admin url but when I want to edit "United States Postal Service", it failed. it does not return USPS edit that I want. it displays the following :

 

Shipping Modules

 

Modules Sort Order Action

Federal Express 0

United Parcel Service 0

United States Postal Service 0

 

=====

Note : Here is the step to go to USPS edit :

Admin -> Modules -> Shipping.

Click the green button next to United States Postal Service.

Click the Edit button.

=====

I also tried the following but "USPS edit" still does not work.

1. If you are getting a "parse error" when you click edit in the admin OR

your international options with checkboxes are not showing up in the admin,

you may need to use phpMyAdmin to update the database -> configuration TABLE

and CHANGE "set_function" to TEXT from VARCHAR.

 

Afterwards:

A. Remove the USPS module in the admin

B. Re-install the USPS module in the admin

C. The options will appear

 

Here is what I followed when I installed that add-on :

******************************************

* PRE v.4.3.0 Installation Instructions *

******************************************

 

please help ..

 

Regards,

Link to comment
Share on other sites

  • 2 months later...

Hi guys,

 

We are using osCommerce v 2.2. (We made a lot of changes, that's why we are using old version)

 

One day 'Priority Main International' shipping method stopped working. I tied to change the value of "intl_types" array entry, but it didn't help.

 

this is the Shipping Module version from usps.php file

$Id: usps.php,v 1.3 2005/12/24 06:10:34 Sean Exp $

 

I know that reinstalling the module could help, but I think that installing module with version 4 instead of version 1 will break some functionality.

 

Does anybody know how to fix this problem?

Link to comment
Share on other sites

  • 1 month later...

I'm still playing around with this contribution... sad.gif

 

Is there a version that includes - "First Class non-machinable"?

 

If not, where and how can I find the code to add it?

 

I called USPS web tech and they said I should have access to that option.

They can't help me and pointed me back to my cart provider to add the code or fix my module.

 

http://www.usps.com/...m#_Toc220743992

 

Here's the only code in my USPS.php file that resembles First Class nonmachinable:

if($shipping_pounds > 35 || ($shipping_pounds == 0 && $shipping_ounces < 6)){
 	$this->_setMachinable('False');
   	}
 	else{
 	$this->_setMachinable('True');
 	}
...
...
...
function _setMachinable($machinable) {
 	$this->machinable = $machinable;
}
...
...
...
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>';

 

I can't seem to find anything resembling = FirstClassMailType='LETTER'

 

crying.gif

 

huh.gif

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

  • 4 weeks later...

Hello,

I am using OSC MS2.2 and just installed 4.3.2, and for some reason it is not showing in checkout? I am getting no errors? I have read through the install a few times, but sure I am missing something simple. Any help would be great. I also tried some of the Alpha's, but still no luck?

 

I also noticed, that when I installed the alpha's, I no longer get the setup in the admin, like insurance configuration and check boxes for shipping methods? Are they all default in the code now in Alpha?

 

Thanks JR

Link to comment
Share on other sites

Is there a way to not have the radio button, selecting the shipping option, automatically selected in checkout_shipping.php? Some of my products can not be shipped by the Media Mail option, but it is the least expensive way to ship my CD products. I would like to just have the customer select the option based on my instructions I placed on that page. Having the options automatically selected is too easy for customers to select the wrong shipping method. Is there some code to comment out or change to do this? I am not even sure what page should be changed.

 

Thanks much,

Bruce

Link to comment
Share on other sites

Ok. In the spirit of this wonderful and amazing and friendly forum, I'm just posting this to share my issues with my USPS Methods 4.3.2 installation and what eventually solved them:

 

~ I had contacted USPS and gotten a username and password and had told them to switch me to the Production server (and consequently got a reply message saying they had done that).

 

~ I had uninstalled the former USPS module before running through the installation instructions.

 

~ My zipcode in the admin configuration was correct.

 

~ The shipping address for the account I was using on the website to test was valid.

 

YET

 

I kept on getting this message in the checkout area of the site where there should have been the listing of options:

 

"An error occured with the USPS shipping calculations.

If you prefer to use USPS as your shipping method, please contact the store owner."

 

SO

 

Taking the troubleshooting suggestion from the installation instructions, I went into the catalog/includes/modules/shipping/usps.php script that sends an email containing the rate quote response from USPS. I found the commented statement at line 526, inserted my correct email address in place of "[email protected]" in both places it occurs, and removed the leading "//" characters that make the line a comment.

 

I then "checked out" with another shopping cart full of items in my site and found the same error ("... error occurred with the USP shipping..."). I went into my email's *SPAM* box where the USPS Rate Request email was deposited. It said:

 

<Error>

<Number>80040b1a</Number>

<Description>Authorization failure. Perhaps username and/or password is incorrect.</Description>

<Source>UspsCom::DoAuth</Source>

</Error>

 

 

 

On reading another forum post that referred to this Error response from USPS where the user said they went back and found some code they forgot to insert during installation. Well, I went back and found nothing in the first section of the installation instructions, but then I went into the second part that begins...

 

 

 

 

"***************************************

* PRE v.3.0 Installation Instructions *

***************************************

 

YOU DO NOT NEED TO DO THIS IF YOU ALREADY HAVE 3.0 to 4.2.x INSTALLED..."

 

 

I did not before understand this part to apply to me, but just out of pure frustration, I went ahead and tried step 5, which seems to be the only difference in this set of instructions:

 

 

**********

* STEP 5 *

**********

 

catalog/admin/modules.php

 

*****************************************

Find This code somewhere around line 43:

*****************************************

 

if (tep_not_null($action)) {

switch ($action) {

case 'save':

while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {

 

***********************************************

INSERT THE FOLLOWING CODE AFTER THE ABOVE LINE:

***********************************************

 

if( is_array( $value ) ){

$value = implode( ", ", $value);

$value = ereg_replace (", --none--", "", $value);

}

 

****************************

SO IT SHOULD LOOK LIKE THIS:

****************************

 

if (tep_not_null($action)) {

switch ($action) {

case 'save':

while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {

if( is_array( $value ) ){

$value = implode( ", ", $value);

$value = ereg_replace (", --none--", "", $value);

}

tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");

}

tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));

break;

case 'install':

 

 

.....

 

 

Well, IT WORKED! I'm in no state to wonder why or figure it out right now because I've spent HOURS trying to get this working. It might be the answer you're looking for as well, so hopefully it helps you into USPS Methods bliss like the majority of the contrib-users here!

 

Cheers,

 

Julie :thumbsup:

Link to comment
Share on other sites

  • 1 month later...

I recently received this email from USPS:

 

Dear Webtools Integrator,

On January 2, 2011, USPS will update domestic shipping services and international pricing and product features. For detailed information on prices and new product features, please reference the Federal Register Notice at http://pe.usps.com/FederalRegisterNotices.asp#Jan_2011_Prices <http://pe.usps.com/FederalRegisterNotices.asp> .

For a list of the new prices, please reference the Postal Explorer website at http://pe.usps.com/. The information is on the left hand side under "NEW* Jan. 2, 2011 Pricing Information"

Price Change updates will be available in the Web Tools testing environment for integrator access on or around December 13. The test environment can be accessed, using your production UserID, via the following URL scheme, host and path:

Secure APIs: https://stg-secure.shippingapis.com/ShippingApi.dll

Non-secure APIs: http://stg-production.shippingapis.com/ShippingApi.dll

Please note that the changes below are intended to be backwards compatible, however, may not be depending on how individual programs are integrated with the APIs. Technical guides, inclusive of the changes below, can be obtained from the USPS Internet Customer Care Center (1-800-344-7779 or [email protected]).

Web Tools APIs will be affected in the following manner:

§ All Web Tools APIs with postage prices incorporated will be updated to reflect the price changes

§ All Rate Calculator API integrators are encouraged to migrate to the latest API versions (RateV4, IntlRateV2):

o RateV4 and IntlRateV2 will be the only Rate Calculator API versions to offer the full range of new products and functionality

o Rate, RateV2, RateV3 and IntlRate will be retired in May 2011, requiring all integrators to migrate to the latest versions

§ Domestic Rate Calculator API Changes

o New <Container> request enumerations will be added to RateV4 to support the USPS product offerings and prices listed in the Federal Register Notice

o New response nodes in Rate, RateV2, RateV3 and RateV4 to support the USPS product offerings and prices listed in the Federal Register Notice

o New optional request values in RateV4 to support USPS extra services offerings and prices

o New optional response nodes in RateV4 to support USPS extra services offerings and prices

§ International Rate Calculator API

o New response nodes in IntlRate and IntlRateV2 to support the USPS product offerings and prices listed in the Federal Register Notice

o New optional request values in IntlRateV2 to support USPS extra services offerings and prices

o New optional response nodes in IntlRateV2 to support USPS extra services offerings and prices

o New <additionalRestrictions> response value in IntlRate and IntlRateV2

§ Express Mail Label and Hold For Pickup Express API

o New <Revision> and <Container> request data tags to support the Legal Flat Rate Box

o New <Size>, <Length>, <Width>, <Height> and <Girth> request data tags

§ Delivery Confirmation and Signature Confirmation

o New <Revision> and <Container> request data tags to support the USPS product offering and prices listed in the Federal Register Notice

§ International Label APIs

o New <Container> request enumerations will be added to support the USPS product offerings and prices listed in the Federal Register Notice

o New <Revision>, <Size>, <Length>, <Width>, <Height> and <Girth> request data tags

o New <additionalRestrictions> response value

§ Customs Forms CN22 and CP72

o New <additionalRestrictions> response value

Please contact the USPS Internet Customer Care Center with any questions or concerns at 1-800-344-7779 or [email protected].

- Web Tools Program Office

 

 

 

Does this mean my shipping calculations are going to stop working on the 2nd?

 

Thanks,

 

Scott

Link to comment
Share on other sites

I hope not but you never know. Last years didn't do anything to mine but the year before that it screwed it all up because they changed the name of a service. Nothing beats sending out a sale email on the 1st and then having site issues on the 2nd. Crossing my fingers.

 

I recently received this email from USPS:

 

Dear Webtools Integrator,

On January 2, 2011, USPS will update domestic shipping services and international pricing and product features. For detailed information on prices and new product features, please reference the Federal Register Notice at http://pe.usps.com/FederalRegisterNotices.asp#Jan_2011_Prices <http://pe.usps.com/FederalRegisterNotices.asp> .

For a list of the new prices, please reference the Postal Explorer website at http://pe.usps.com/. The information is on the left hand side under "NEW* Jan. 2, 2011 Pricing Information"

Price Change updates will be available in the Web Tools testing environment for integrator access on or around December 13. The test environment can be accessed, using your production UserID, via the following URL scheme, host and path:

Secure APIs: https://stg-secure.shippingapis.com/ShippingApi.dll

Non-secure APIs: http://stg-production.shippingapis.com/ShippingApi.dll

Please note that the changes below are intended to be backwards compatible, however, may not be depending on how individual programs are integrated with the APIs. Technical guides, inclusive of the changes below, can be obtained from the USPS Internet Customer Care Center (1-800-344-7779 or [email protected]).

Web Tools APIs will be affected in the following manner:

§ All Web Tools APIs with postage prices incorporated will be updated to reflect the price changes

§ All Rate Calculator API integrators are encouraged to migrate to the latest API versions (RateV4, IntlRateV2):

o RateV4 and IntlRateV2 will be the only Rate Calculator API versions to offer the full range of new products and functionality

o Rate, RateV2, RateV3 and IntlRate will be retired in May 2011, requiring all integrators to migrate to the latest versions

§ Domestic Rate Calculator API Changes

o New <Container> request enumerations will be added to RateV4 to support the USPS product offerings and prices listed in the Federal Register Notice

o New response nodes in Rate, RateV2, RateV3 and RateV4 to support the USPS product offerings and prices listed in the Federal Register Notice

o New optional request values in RateV4 to support USPS extra services offerings and prices

o New optional response nodes in RateV4 to support USPS extra services offerings and prices

§ International Rate Calculator API

o New response nodes in IntlRate and IntlRateV2 to support the USPS product offerings and prices listed in the Federal Register Notice

o New optional request values in IntlRateV2 to support USPS extra services offerings and prices

o New optional response nodes in IntlRateV2 to support USPS extra services offerings and prices

o New <additionalRestrictions> response value in IntlRate and IntlRateV2

§ Express Mail Label and Hold For Pickup Express API

o New <Revision> and <Container> request data tags to support the Legal Flat Rate Box

o New <Size>, <Length>, <Width>, <Height> and <Girth> request data tags

§ Delivery Confirmation and Signature Confirmation

o New <Revision> and <Container> request data tags to support the USPS product offering and prices listed in the Federal Register Notice

§ International Label APIs

o New <Container> request enumerations will be added to support the USPS product offerings and prices listed in the Federal Register Notice

o New <Revision>, <Size>, <Length>, <Width>, <Height> and <Girth> request data tags

o New <additionalRestrictions> response value

§ Customs Forms CN22 and CP72

o New <additionalRestrictions> response value

Please contact the USPS Internet Customer Care Center with any questions or concerns at 1-800-344-7779 or [email protected].

- Web Tools Program Office

 

 

 

Does this mean my shipping calculations are going to stop working on the 2nd?

 

Thanks,

 

Scott

Link to comment
Share on other sites

I have Usps working on one site. I don't know if the rates are correct but at least site is not down. Now to work on the other four sites. I will include the files here. Uninstall and reinstall.

includes/modules/shipping/Usps

<?php

/*

$Id$

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2008 osCommerce

 

Released under the GNU General Public License

 

Based on USPS Methods 26-Feb-2010

http://addons.oscommerce.com/info/487

*/

 

class usps {

var $code, $title, $description, $icon, $enabled, $countries;

 

// class constructor

function usps() {

global $order;

 

$this->code = 'usps';

$this->title = MODULE_SHIPPING_USPS_TEXT_TITLE;

$this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION;

$this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER;

$this->icon = DIR_WS_ICONS . 'shipping_usps.gif';

$this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS;

$this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);

 

if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_USPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");

while ($check = tep_db_fetch_array($check_query)) {

if ($check['zone_id'] < 1) {

$check_flag = true;

break;

} elseif ($check['zone_id'] == $order->delivery['zone_id']) {

$check_flag = true;

break;

}

}

 

if ($check_flag == false) {

$this->enabled = false;

}

}

 

$this->types = array(

// Domestic Types

'Express Mail',

//'Express Mail Flat Rate Envelope',

'Priority Mail',

//'Priority Mail Flat Rate Envelope',

//'Priority Mail Small Flat Rate Box',

'Priority Mail Medium Flat Rate Box',

//'Priority Mail Large Flat Rate Box',

//'First-Class Mail Flat',

//'First-Class Mail Parcel',

//'Parcel Post',

//'Bound Printed Matter',

//'Media Mail',

//'Library Mail',

// International Types

'Global Express Guaranteed (GXG)',

//'Global Express Guaranteed Non-Document Rectangular',

//'Global Express Guaranteed Non-Document Non-Rectangular',

//'USPS GXG Envelopes',

'Express Mail International',

//'Express Mail International Flat Rate Envelope',

'Priority Mail International',

//'Priority Mail International Large Flat Rate Box',

'Priority Mail International Medium Flat Rate Box'

//'Priority Mail International Small Flat Rate Box',

//'Priority Mail International Flat Rate Envelope',

//'First-Class Mail International Package',

//'First-Class Mail International Large Envelope'

);

 

$this->countries = $this->country_list();

}

 

// class methods

function quote($method = '') {

global $order, $shipping_weight, $shipping_num_boxes;

 

// if ( tep_not_null($method) && in_array($method, $this->types)) {

// $this->_setService($method);

// }

 

$this->_setMachinable('False');

$this->_setContainer('None');

$this->_setSize('REGULAR');

 

// usps doesnt accept zero weight

$shipping_weight = ($shipping_weight < 0.1 ? 0.1 : $shipping_weight);

$shipping_pounds = floor ($shipping_weight);

$shipping_ounces = round(16 * ($shipping_weight - floor($shipping_weight)));

$this->_setWeight($shipping_pounds, $shipping_ounces);

$uspsQuote = $this->_getQuote();

if (is_array($uspsQuote)) {

if (isset($uspsQuote['error'])) {

$this->quotes = array('module' => $this->title,

'error' => $uspsQuote['error']);

} else {

$this->quotes = array('id' => $this->code,

'module' => $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)');

 

$methods = array();

$size = sizeof($uspsQuote);

for ($i=0; $i<$size; $i++) {

list($type, $cost) = each($uspsQuote[$i]);

 

// echo "USPS $type @ $cost<br />";

if (($method == '' && in_array($type, $this->types)) || $method == $type) {

if (strpos($type, "Flat Rate")) $type_flat = $type . ', subject to verification';

else $type_flat = $type;

$methods[] = array('id' => $type,

'title' => $type_flat,

'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);

}

}

 

$this->quotes['methods'] = $methods;

 

if ($this->tax_class > 0) {

$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

}

}

} else {

$this->quotes = array('module' => $this->title,

'error' => MODULE_SHIPPING_USPS_TEXT_ERROR);

}

 

if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

 

return $this->quotes;

}

 

function check() {

if (!isset($this->_check)) {

$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'");

$this->_check = tep_db_num_rows($check_query);

}

return $this->_check;

}

 

function install() {

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS', 'True', 'Do you want to offer USPS shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE', 'Enter the USPS USERID assigned to you.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS Password', 'MODULE_SHIPPING_USPS_PASSWORD', 'NONE', 'See USERID, above.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_USPS_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_USPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_USPS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_USPS_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");

}

 

function remove() {

tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");

}

 

function keys() {

return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_PASSWORD', 'MODULE_SHIPPING_USPS_HANDLING', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER');

}

 

function _setService($service) {

$this->service = $service;

}

 

function _setWeight($pounds, $ounces=0) {

$this->pounds = $pounds;

$this->ounces = $ounces;

}

 

function _setContainer($container) {

$this->container = $container;

}

 

function _setSize($size) {

$this->size = $size;

}

 

function _setMachinable($machinable) {

$this->machinable = $machinable;

}

 

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 country_list() {

$list = array('AF' => 'Afghanistan',

'AL' => 'Albania',

'DZ' => 'Algeria',

'AD' => 'Andorra',

'AO' => 'Angola',

'AI' => 'Anguilla',

'AG' => 'Antigua and Barbuda',

'AR' => 'Argentina',

'AM' => 'Armenia',

'AW' => 'Aruba',

'AU' => 'Australia',

'AT' => 'Austria',

'AZ' => 'Azerbaijan',

'BS' => 'Bahamas',

'BH' => 'Bahrain',

'BD' => 'Bangladesh',

'BB' => 'Barbados',

'BY' => 'Belarus',

'BE' => 'Belgium',

'BZ' => 'Belize',

'BJ' => 'Benin',

'BM' => 'Bermuda',

'BT' => 'Bhutan',

'BO' => 'Bolivia',

'BA' => 'Bosnia-Herzegovina',

'BW' => 'Botswana',

'BR' => 'Brazil',

'VG' => 'British Virgin Islands',

'BN' => 'Brunei Darussalam',

'BG' => 'Bulgaria',

'BF' => 'Burkina Faso',

'MM' => 'Burma',

'BI' => 'Burundi',

'KH' => 'Cambodia',

'CM' => 'Cameroon',

'CA' => 'Canada',

'CV' => 'Cape Verde',

'KY' => 'Cayman Islands',

'CF' => 'Central African Republic',

'TD' => 'Chad',

'CL' => 'Chile',

'CN' => 'China',

'CX' => 'Christmas Island (Australia)',

'CC' => 'Cocos Island (Australia)',

'CO' => 'Colombia',

'KM' => 'Comoros',

'CG' => 'Congo (Brazzaville),Republic of the',

'ZR' => 'Congo, Democratic Republic of the',

'CK' => 'Cook Islands (New Zealand)',

'CR' => 'Costa Rica',

'CI' => 'Cote d\'Ivoire (Ivory Coast)',

'HR' => 'Croatia',

'CU' => 'Cuba',

'CY' => 'Cyprus',

'CZ' => 'Czech Republic',

'DK' => 'Denmark',

'DJ' => 'Djibouti',

'DM' => 'Dominica',

'DO' => 'Dominican Republic',

'TP' => 'East Timor (Indonesia)',

'EC' => 'Ecuador',

'EG' => 'Egypt',

'SV' => 'El Salvador',

'GQ' => 'Equatorial Guinea',

'ER' => 'Eritrea',

'EE' => 'Estonia',

'ET' => 'Ethiopia',

'FK' => 'Falkland Islands',

'FO' => 'Faroe Islands',

'FJ' => 'Fiji',

'FI' => 'Finland',

'FR' => 'France',

'GF' => 'French Guiana',

'PF' => 'French Polynesia',

'GA' => 'Gabon',

'GM' => 'Gambia',

'GE' => 'Georgia, Republic of',

'DE' => 'Germany',

'GH' => 'Ghana',

'GI' => 'Gibraltar',

'GB' => 'Great Britain and Northern Ireland',

'GR' => 'Greece',

'GL' => 'Greenland',

'GD' => 'Grenada',

'GP' => 'Guadeloupe',

'GT' => 'Guatemala',

'GN' => 'Guinea',

'GW' => 'Guinea-Bissau',

'GY' => 'Guyana',

'HT' => 'Haiti',

'HN' => 'Honduras',

'HK' => 'Hong Kong',

'HU' => 'Hungary',

'IS' => 'Iceland',

'IN' => 'India',

'ID' => 'Indonesia',

'IR' => 'Iran',

'IQ' => 'Iraq',

'IE' => 'Ireland',

'IL' => 'Israel',

'IT' => 'Italy',

'JM' => 'Jamaica',

'JP' => 'Japan',

'JO' => 'Jordan',

'KZ' => 'Kazakhstan',

'KE' => 'Kenya',

'KI' => 'Kiribati',

'KW' => 'Kuwait',

'KG' => 'Kyrgyzstan',

'LA' => 'Laos',

'LV' => 'Latvia',

'LB' => 'Lebanon',

'LS' => 'Lesotho',

'LR' => 'Liberia',

'LY' => 'Libya',

'LI' => 'Liechtenstein',

'LT' => 'Lithuania',

'LU' => 'Luxembourg',

'MO' => 'Macao',

'MK' => 'Macedonia, Republic of',

'MG' => 'Madagascar',

'MW' => 'Malawi',

'MY' => 'Malaysia',

'MV' => 'Maldives',

'ML' => 'Mali',

'MT' => 'Malta',

'MQ' => 'Martinique',

'MR' => 'Mauritania',

'MU' => 'Mauritius',

'YT' => 'Mayotte (France)',

'MX' => 'Mexico',

'MD' => 'Moldova',

'MC' => 'Monaco (France)',

'MN' => 'Mongolia',

'MS' => 'Montserrat',

'MA' => 'Morocco',

'MZ' => 'Mozambique',

'NA' => 'Namibia',

'NR' => 'Nauru',

'NP' => 'Nepal',

'NL' => 'Netherlands',

'AN' => 'Netherlands Antilles',

'NC' => 'New Caledonia',

'NZ' => 'New Zealand',

'NI' => 'Nicaragua',

'NE' => 'Niger',

'NG' => 'Nigeria',

'KP' => 'North Korea (Korea, Democratic People\'s Republic of)',

'NO' => 'Norway',

'OM' => 'Oman',

'PK' => 'Pakistan',

'PA' => 'Panama',

'PG' => 'Papua New Guinea',

'PY' => 'Paraguay',

'PE' => 'Peru',

'PH' => 'Philippines',

'PN' => 'Pitcairn Island',

'PL' => 'Poland',

'PT' => 'Portugal',

'QA' => 'Qatar',

'RE' => 'Reunion',

'RO' => 'Romania',

'RU' => 'Russia',

'RW' => 'Rwanda',

'SH' => 'Saint Helena',

'KN' => 'Saint Kitts (St. Christopher and Nevis)',

'LC' => 'Saint Lucia',

'PM' => 'Saint Pierre and Miquelon',

'VC' => 'Saint Vincent and the Grenadines',

'SM' => 'San Marino',

'ST' => 'Sao Tome and Principe',

'SA' => 'Saudi Arabia',

'SN' => 'Senegal',

'YU' => 'Serbia-Montenegro',

'SC' => 'Seychelles',

'SL' => 'Sierra Leone',

'SG' => 'Singapore',

'SK' => 'Slovak Republic',

'SI' => 'Slovenia',

'SB' => 'Solomon Islands',

'SO' => 'Somalia',

'ZA' => 'South Africa',

'GS' => 'South Georgia (Falkland Islands)',

'KR' => 'South Korea (Korea, Republic of)',

'ES' => 'Spain',

'LK' => 'Sri Lanka',

'SD' => 'Sudan',

'SR' => 'Suriname',

'SZ' => 'Swaziland',

'SE' => 'Sweden',

'CH' => 'Switzerland',

'SY' => 'Syrian Arab Republic',

'TW' => 'Taiwan',

'TJ' => 'Tajikistan',

'TZ' => 'Tanzania',

'TH' => 'Thailand',

'TG' => 'Togo',

'TK' => 'Tokelau (Union) Group (Western Samoa)',

'TO' => 'Tonga',

'TT' => 'Trinidad and Tobago',

'TN' => 'Tunisia',

'TR' => 'Turkey',

'TM' => 'Turkmenistan',

'TC' => 'Turks and Caicos Islands',

'TV' => 'Tuvalu',

'UG' => 'Uganda',

'UA' => 'Ukraine',

'AE' => 'United Arab Emirates',

'UY' => 'Uruguay',

'UZ' => 'Uzbekistan',

'VU' => 'Vanuatu',

'VA' => 'Vatican City',

'VE' => 'Venezuela',

'VN' => 'Vietnam',

'WF' => 'Wallis and Futuna Islands',

'WS' => 'Western Samoa',

'YE' => 'Yemen',

'ZM' => 'Zambia',

'ZW' => 'Zimbabwe');

 

return $list;

}

}

?>

 

 

 

/includes/languages/english/modules/shipping/

 

<?php

/*

$Id$

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Public License

*/

 

define('MODULE_SHIPPING_USPS_TEXT_TITLE', 'United States Postal Service');

define('MODULE_SHIPPING_USPS_TEXT_DESCRIPTION', 'United States Postal Service<br /><br />You will need to have registered an account with USPS at http://www.uspsprioritymail.com/et_regcert.html to use this module<br /><br />USPS expects you to use pounds as weight measure for your products.');

define('MODULE_SHIPPING_USPS_TEXT_OPT_PP', 'Parcel Post');

define('MODULE_SHIPPING_USPS_TEXT_OPT_PM', 'Priority Mail');

define('MODULE_SHIPPING_USPS_TEXT_OPT_EX', 'Express Mail');

define('MODULE_SHIPPING_USPS_TEXT_ERROR', 'An error occured with the USPS shipping calculations.<br />If you prefer to use USPS as your shipping method, please contact the store owner.');

?>

Link to comment
Share on other sites

it's not working at all. this is leaving us dead in the water.

 

Sorry I posted the wrong files. I have it working for US on two sites Sorry I haven't gotten International to work

 

includes/modules/shipping

 

<?php

/*

$Id: usps.php 1783 2008-01-10 01:16:16Z hpdl $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2008 osCommerce

 

Released under the GNU General Public License

*/

 

class usps {

var $code, $title, $description, $icon, $enabled, $countries;

 

// class constructor

function usps() {

global $order;

 

$this->code = 'usps';

$this->title = MODULE_SHIPPING_USPS_TEXT_TITLE;

$this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION;

$this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER;

$this->icon = DIR_WS_ICONS . 'shipping_usps.gif';

$this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS;

$this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);

 

if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_USPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");

while ($check = tep_db_fetch_array($check_query)) {

if ($check['zone_id'] < 1) {

$check_flag = true;

break;

} elseif ($check['zone_id'] == $order->delivery['zone_id']) {

$check_flag = true;

break;

}

}

 

if ($check_flag == false) {

$this->enabled = false;

}

}

 

$this->types = array('EXPRESS' => 'Express Mail',

'FIRST CLASS' => 'First-Class Mail',

'PRIORITY' => 'Priority Mail',

'PARCEL' => 'Parcel Post');

 

$this->intl_types = array('Global Express Guaranteed',

'Global Express Guaranteed Non-Document Rectangular',

'Global Express Guaranteed Non-Document Non-Rectangular',

'Express Mail International (EMS)',

'Express Mail International (EMS) Flat Rate Envelope',

'Priority Mail International',

'Priority Mail International Flat Rate Envelope',

'Priority Mail International Flat Rate Box',

'First-Class Mail International');

 

$this->countries = $this->country_list();

}

 

// class methods

function quote($method = '') {

global $order, $shipping_weight, $shipping_num_boxes;

 

if ( tep_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {

$this->_setService($method);

}

 

$this->_setMachinable('False');

$this->_setContainer('None');

$this->_setSize('REGULAR');

 

// usps doesnt accept zero weight

$shipping_weight = ($shipping_weight < 0.1 ? 0.1 : $shipping_weight);

$shipping_pounds = floor ($shipping_weight);

$shipping_ounces = round(16 * ($shipping_weight - floor($shipping_weight)));

$this->_setWeight($shipping_pounds, $shipping_ounces);

 

$uspsQuote = $this->_getQuote();

 

if (is_array($uspsQuote)) {

if (isset($uspsQuote['error'])) {

$this->quotes = array('module' => $this->title,

'error' => $uspsQuote['error']);

} else {

$this->quotes = array('id' => $this->code,

'module' => $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)');

 

$methods = array();

$size = sizeof($uspsQuote);

for ($i=0; $i<$size; $i++) {

list($type, $cost) = each($uspsQuote[$i]);

 

$methods[] = array('id' => $type,

'title' => ((isset($this->types[$type])) ? $this->types[$type] : $type),

'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);

}

 

$this->quotes['methods'] = $methods;

 

if ($this->tax_class > 0) {

$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

}

}

} else {

$this->quotes = array('module' => $this->title,

'error' => MODULE_SHIPPING_USPS_TEXT_ERROR);

}

 

if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

 

return $this->quotes;

}

 

function check() {

if (!isset($this->_check)) {

$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'");

$this->_check = tep_db_num_rows($check_query);

}

return $this->_check;

}

 

function install() {

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS', 'True', 'Do you want to offer USPS shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE', 'Enter the USPS USERID assigned to you.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS Password', 'MODULE_SHIPPING_USPS_PASSWORD', 'NONE', 'See USERID, above.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_USPS_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_USPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_USPS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_USPS_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");

}

 

function remove() {

tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");

}

 

function keys() {

return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_PASSWORD', 'MODULE_SHIPPING_USPS_HANDLING', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER');

}

 

function _setService($service) {

$this->service = $service;

}

 

function _setWeight($pounds, $ounces=0) {

$this->pounds = $pounds;

$this->ounces = $ounces;

}

 

function _setContainer($container) {

$this->container = $container;

}

 

function _setSize($size) {

$this->size = $size;

}

 

function _setMachinable($machinable) {

$this->machinable = $machinable;

}

 

function _getQuote() {

global $order;

 

if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {

$request = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="' . MODULE_SHIPPING_USPS_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="' . MODULE_SHIPPING_USPS_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);

}

 

$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 (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 country_list() {

$list = array('AF' => 'Afghanistan',

'AL' => 'Albania',

'DZ' => 'Algeria',

'AD' => 'Andorra',

'AO' => 'Angola',

'AI' => 'Anguilla',

'AG' => 'Antigua and Barbuda',

'AR' => 'Argentina',

'AM' => 'Armenia',

'AW' => 'Aruba',

'AU' => 'Australia',

'AT' => 'Austria',

'AZ' => 'Azerbaijan',

'BS' => 'Bahamas',

'BH' => 'Bahrain',

'BD' => 'Bangladesh',

'BB' => 'Barbados',

'BY' => 'Belarus',

'BE' => 'Belgium',

'BZ' => 'Belize',

'BJ' => 'Benin',

'BM' => 'Bermuda',

'BT' => 'Bhutan',

'BO' => 'Bolivia',

'BA' => 'Bosnia-Herzegovina',

'BW' => 'Botswana',

'BR' => 'Brazil',

'VG' => 'British Virgin Islands',

'BN' => 'Brunei Darussalam',

'BG' => 'Bulgaria',

'BF' => 'Burkina Faso',

'MM' => 'Burma',

'BI' => 'Burundi',

'KH' => 'Cambodia',

'CM' => 'Cameroon',

'CA' => 'Canada',

'CV' => 'Cape Verde',

'KY' => 'Cayman Islands',

'CF' => 'Central African Republic',

'TD' => 'Chad',

'CL' => 'Chile',

'CN' => 'China',

'CX' => 'Christmas Island (Australia)',

'CC' => 'Cocos Island (Australia)',

'CO' => 'Colombia',

'KM' => 'Comoros',

'CG' => 'Congo (Brazzaville),Republic of the',

'ZR' => 'Congo, Democratic Republic of the',

'CK' => 'Cook Islands (New Zealand)',

'CR' => 'Costa Rica',

'CI' => 'Cote d\'Ivoire (Ivory Coast)',

'HR' => 'Croatia',

'CU' => 'Cuba',

'CY' => 'Cyprus',

'CZ' => 'Czech Republic',

'DK' => 'Denmark',

'DJ' => 'Djibouti',

'DM' => 'Dominica',

'DO' => 'Dominican Republic',

'TP' => 'East Timor (Indonesia)',

'EC' => 'Ecuador',

'EG' => 'Egypt',

'SV' => 'El Salvador',

'GQ' => 'Equatorial Guinea',

'ER' => 'Eritrea',

'EE' => 'Estonia',

'ET' => 'Ethiopia',

'FK' => 'Falkland Islands',

'FO' => 'Faroe Islands',

'FJ' => 'Fiji',

'FI' => 'Finland',

'FR' => 'France',

'GF' => 'French Guiana',

'PF' => 'French Polynesia',

'GA' => 'Gabon',

'GM' => 'Gambia',

'GE' => 'Georgia, Republic of',

'DE' => 'Germany',

'GH' => 'Ghana',

'GI' => 'Gibraltar',

'GB' => 'Great Britain and Northern Ireland',

'GR' => 'Greece',

'GL' => 'Greenland',

'GD' => 'Grenada',

'GP' => 'Guadeloupe',

'GT' => 'Guatemala',

'GN' => 'Guinea',

'GW' => 'Guinea-Bissau',

'GY' => 'Guyana',

'HT' => 'Haiti',

'HN' => 'Honduras',

'HK' => 'Hong Kong',

'HU' => 'Hungary',

'IS' => 'Iceland',

'IN' => 'India',

'ID' => 'Indonesia',

'IR' => 'Iran',

'IQ' => 'Iraq',

'IE' => 'Ireland',

'IL' => 'Israel',

'IT' => 'Italy',

'JM' => 'Jamaica',

'JP' => 'Japan',

'JO' => 'Jordan',

'KZ' => 'Kazakhstan',

'KE' => 'Kenya',

'KI' => 'Kiribati',

'KW' => 'Kuwait',

'KG' => 'Kyrgyzstan',

'LA' => 'Laos',

'LV' => 'Latvia',

'LB' => 'Lebanon',

'LS' => 'Lesotho',

'LR' => 'Liberia',

'LY' => 'Libya',

'LI' => 'Liechtenstein',

'LT' => 'Lithuania',

'LU' => 'Luxembourg',

'MO' => 'Macao',

'MK' => 'Macedonia, Republic of',

'MG' => 'Madagascar',

'MW' => 'Malawi',

'MY' => 'Malaysia',

'MV' => 'Maldives',

'ML' => 'Mali',

'MT' => 'Malta',

'MQ' => 'Martinique',

'MR' => 'Mauritania',

'MU' => 'Mauritius',

'YT' => 'Mayotte (France)',

'MX' => 'Mexico',

'MD' => 'Moldova',

'MC' => 'Monaco (France)',

'MN' => 'Mongolia',

'MS' => 'Montserrat',

'MA' => 'Morocco',

'MZ' => 'Mozambique',

'NA' => 'Namibia',

'NR' => 'Nauru',

'NP' => 'Nepal',

'NL' => 'Netherlands',

'AN' => 'Netherlands Antilles',

'NC' => 'New Caledonia',

'NZ' => 'New Zealand',

'NI' => 'Nicaragua',

'NE' => 'Niger',

'NG' => 'Nigeria',

'KP' => 'North Korea (Korea, Democratic People\'s Republic of)',

'NO' => 'Norway',

'OM' => 'Oman',

'PK' => 'Pakistan',

'PA' => 'Panama',

'PG' => 'Papua New Guinea',

'PY' => 'Paraguay',

'PE' => 'Peru',

'PH' => 'Philippines',

'PN' => 'Pitcairn Island',

'PL' => 'Poland',

'PT' => 'Portugal',

'QA' => 'Qatar',

'RE' => 'Reunion',

'RO' => 'Romania',

'RU' => 'Russia',

'RW' => 'Rwanda',

'SH' => 'Saint Helena',

'KN' => 'Saint Kitts (St. Christopher and Nevis)',

'LC' => 'Saint Lucia',

'PM' => 'Saint Pierre and Miquelon',

'VC' => 'Saint Vincent and the Grenadines',

'SM' => 'San Marino',

'ST' => 'Sao Tome and Principe',

'SA' => 'Saudi Arabia',

'SN' => 'Senegal',

'YU' => 'Serbia-Montenegro',

'SC' => 'Seychelles',

'SL' => 'Sierra Leone',

'SG' => 'Singapore',

'SK' => 'Slovak Republic',

'SI' => 'Slovenia',

'SB' => 'Solomon Islands',

'SO' => 'Somalia',

'ZA' => 'South Africa',

'GS' => 'South Georgia (Falkland Islands)',

'KR' => 'South Korea (Korea, Republic of)',

'ES' => 'Spain',

'LK' => 'Sri Lanka',

'SD' => 'Sudan',

'SR' => 'Suriname',

'SZ' => 'Swaziland',

'SE' => 'Sweden',

'CH' => 'Switzerland',

'SY' => 'Syrian Arab Republic',

'TW' => 'Taiwan',

'TJ' => 'Tajikistan',

'TZ' => 'Tanzania',

'TH' => 'Thailand',

'TG' => 'Togo',

'TK' => 'Tokelau (Union) Group (Western Samoa)',

'TO' => 'Tonga',

'TT' => 'Trinidad and Tobago',

'TN' => 'Tunisia',

'TR' => 'Turkey',

'TM' => 'Turkmenistan',

'TC' => 'Turks and Caicos Islands',

'TV' => 'Tuvalu',

'UG' => 'Uganda',

'UA' => 'Ukraine',

'AE' => 'United Arab Emirates',

'UY' => 'Uruguay',

'UZ' => 'Uzbekistan',

'VU' => 'Vanuatu',

'VA' => 'Vatican City',

'VE' => 'Venezuela',

'VN' => 'Vietnam',

'WF' => 'Wallis and Futuna Islands',

'WS' => 'Western Samoa',

'YE' => 'Yemen',

'ZM' => 'Zambia',

'ZW' => 'Zimbabwe');

 

return $list;

}

}

?>

 

/includes/languages/english/modules/

 

<?php

/*

$Id: usps.php 1739 2007-12-20 00:52:16Z hpdl $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Public License

*/

 

define('MODULE_SHIPPING_USPS_TEXT_TITLE', 'United States Postal Service');

define('MODULE_SHIPPING_USPS_TEXT_DESCRIPTION', 'United States Postal Service<br><br>You will need to have registered an account with USPS at http://www.uspsprioritymail.com/et_regcert.html to use this module<br><br>USPS expects you to use pounds as weight measure for your products.');

define('MODULE_SHIPPING_USPS_TEXT_OPT_PP', 'Parcel Post');

define('MODULE_SHIPPING_USPS_TEXT_OPT_PM', 'Priority Mail');

define('MODULE_SHIPPING_USPS_TEXT_OPT_EX', 'Express Mail');

define('MODULE_SHIPPING_USPS_TEXT_ERROR', 'An error occured with the USPS shipping calculations.<br>If you prefer to use USPS as your shipping method, please contact the store owner.');

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...