Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Canada Post Automatic Labels


natrium42

Recommended Posts

Looks like Canada Post modified the login process slightly. The following change in admin/ship_canadapost.php is required.

 

Change the following code:

  ////
 // 2. LOG IN
 $response = cp_get_page($ch, 'https://sso-cal.canadapost-postescanada.ca/sso/login.jsp?~language=EN&APP_ID=B2B&SSO_REFERRER_URL=https://obc.canadapost.ca/zcpb2b/b2b/init.do?language=EN&shop=CPENCOMM&sblid=sbobclogin');

 $query_string = 'SHOP=CPFRCOMM&SSO_ITS_URL=%2Fsso%2Flogin.jsp&SSO_ACTION=0&P_SHOP=CPFRCOMM'
			. '&login_type=2&password_length=0&%7Elanguage=EN&APP_ID=B2B'
			. '&SSO_USERID=' . urlencode($cp_user)
			. '&SSO_PASSWORD=' . urlencode($cp_password);

 $response = cp_post_page($ch, 'https://sso-cal.canadapost-postescanada.ca/sso/login/redirect', $query_string);

 // get Canada Post customer number
 $regexp = "SSO_CUSTOMER_NUMBER\" value=\"([0123456789]*)(,|\")";
 $matches = '';
 preg_match("/$regexp/siU", $response, $matches);
 $cp_customer = $matches[1];

 $response = cp_submit_page($ch, $response, 'https://sso-cal.canadapost-postescanada.ca');

 // Sanity Check and Progress Report
 if (strstr($response, '<input type=hidden name="SSO_VERSION_MAJOR" value="3">') === FALSE) {
cp_error(2, 'Failed check in ' . __FILE__ . ' at line ' . __LINE__  . '. This most likely means that Canada Post has changed their user interface. You need to update your Canada Post Automatic Shipping Labels module.');
curl_close($ch); die(); /////////////////////
 } else {
cp_progress(2, 'Logged in.');
 }

to the new code:

  ////
 // 2. LOG IN

 $response = cp_get_page($ch, 'https://sso-cal.canadapost-postescanada.ca/cpid/apps/signIn?LOCALE=en&~language=EN&APP_ID=B2B&SSO_REFERRER_URL=https://obc.canadapost.ca/zcpb2b/b2b/init.do?language=EN&shop=CPENCOMM');

 $query_string = 'frmCPIDSignIn:signIn.x=46&frmCPIDSignIn:signIn.y=11&frmCPIDSignIn_SUBMIT=1'
			. '&frmCPIDSignIn:j_username=' . urlencode($cp_user)
			. '&frmCPIDSignIn:j_password=' . urlencode($cp_password);

 $response = cp_post_page($ch, 'https://sso-cal.canadapost-postescanada.ca/cpid/apps/signIn?execution=e1s1', $query_string);

 $query_string = 'SHOP=CPFRCOMM&SSO_ITS_URL=%2Fcpid%2Flogin.jsp&SSO_ACTION=0&P_SHOP=CPFRCOMM'
			. '&login_type=2&password_length=0&%7Elanguage=EN&APP_ID=B2B'
			. '&SSO_USERID=' . urlencode($cp_user)
			. '&SSO_PASSWORD=' . urlencode($cp_password);

 $response = cp_post_page($ch, 'https://sso-cal.canadapost-postescanada.ca/cpid/login/redirect', $query_string);

 // get Canada Post customer number
 $regexp = "SSO_CUSTOMER_NUMBER\" value=\"([0123456789]*)(,|\")";
 $matches = '';
 preg_match("/$regexp/siU", $response, $matches);
 $cp_customer = $matches[1];

 $response = cp_submit_page($ch, $response, 'https://sso-cal.canadapost-postescanada.ca');

 // Sanity Check and Progress Report
 if (strstr($response, '<input type=hidden name="SSO_VERSION_MAJOR" value="3">') === FALSE) {
cp_error(2, 'Failed check in ' . __FILE__ . ' at line ' . __LINE__  . '. This most likely means that Canada Post has changed their user interface. You need to update your Canada Post Automatic Shipping Labels module.');
curl_close($ch); die(); /////////////////////
 } else {
cp_progress(2, 'Logged in.');
 }

Everything should start working again.

Link to comment
Share on other sites

  • Replies 68
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...

Thanks for the great Mod.

 

I'm not sure If the issue has to do with the Canada Post change recently, but this is the error I'm receiving (this is WITH the new #2 mod above):

 

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /home/xxxx/public_html/xxxx/admin/ship_canadapost.php on line 613

Step 1. Initialized.

Step 2. Error: Failed check in /home/xxxx/public_html/xxxx/admin/ship_canadapost.php at line 651. This most likely means that Canada Post has changed their user interface. You need to update your Canada Post Automatic Shipping Labels module.

 

The warning message makes me wonder if I am missing something. Ideas?

 

Thanks.

Link to comment
Share on other sites

Just create a php file with phpinfo() call: http://ca2.php.net/manual/en/function.phpinfo.php

It should show all modules and their options.

 

Perfect.. and it looks like it is enabled. I'll keep poking at it, and see what I can come up with. That is, unless you have any other ideas =). Thanks!

 

I also found in the osc admin panel, the TOOLS menu also shows this now. The things you learn.. =)

 

PHP Version 5.2.9

cURL support enabled

cURL Information libcurl/7.19.4 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5

Link to comment
Share on other sites

  • 2 weeks later...

Hey guys. I've been trying to add this module and have overcome some problems by looking through these forums but i've come across something and im not sure how to fix it. When i go to ship something it goes through the steps up until step 5 then it gives me the following error:

 

"Step 5. Error: (1447) The Shipping Point is invalid."

 

I'm not really sure what could be causing that error and i don't know what information I could give you to help me solve this. When i look at the phpinfo here is the cURL information: " libcurl/7.16.0 OpenSSL/0.9.8i zlib/1.2.3 " i know i don't have libssh2 installed and i thought that you absolutely needed that in order to pass step 2 but it looks like it logged me in without having that added on. Do you think that because i don't have libssh2 this is why it won't go past step 5? or is there something else? any tips or info would be much appreciated.

 

Thanks

Link to comment
Share on other sites

Hi Alexei,

 

First, thank you for taking the time to make a such a great contribution.

 

I'm also having the same issue as the Andrei, where it fails at step 5. As far as I know the address is set up correctly in EST - I don't have to re-enter it or correct it in order to complete it.

 

Is there anyway I can confirm that everything is as it should be on EST?

 

Thank you,

 

Alex

Link to comment
Share on other sites

Has Canada POst changed the login code again? Anyone else having errors with the login code again from this weekend?

 

 

yep ! I got a problem in step 2..... Error: Failed check in /home/r.../catalog/admin/ship_canadapost.php at line 657. This most likely means that Canada Post has changed their user interface. You need to update your Canada Post Automatic Shipping Labels module.

 

anyone got this problem?

Link to comment
Share on other sites

Looks like Canada Post changed the names of the login fields slightly, here are the fixed lines:

  ////
 // 2. LOG IN

 $response = cp_get_page($ch, 'https://sso-cal.canadapost-postescanada.ca/cpid/apps/signIn?LOCALE=en&~language=EN&APP_ID=B2B&SSO_REFERRER_URL=https://obc.canadapost.ca/zcpb2b/b2b/init.do?language=EN&shop=CPENCOMM');

 $query_string = 'cpidSignIn:signIn.x=46&cpidSignIn:signIn.y=11&cpidSignIn_SUBMIT=1'
			. '&cpidSignIn:j_username=' . urlencode($cp_user)
			. '&cpidSignIn:j_password=' . urlencode($cp_password);

Also make sure to go to the EST site manually and update the account when requested.

Link to comment
Share on other sites

  • 2 weeks later...
What kind of shipping option does this happen with? Is this with domestic shipping? I usually use eShipper to ship domestically, so might have missed a cropped up problem.

 

Sorry about the delay in my response. The shipping addresses that I've tried are to the USA. I've tried every shipping method available and it still fails at Step 5.

 

Thanks,

 

Alex

Link to comment
Share on other sites

  • 5 weeks later...

I released PayPal Automated Labels mod to supplement this one. It allows to ship via Canada Post Light Packets Air among others, which is very cheap if your package is 2cm or thinner and 0.1kg or lower. Usually you can only ship via this method if you go to a postal office in person, but apparently Canada Post gave PayPal the ability to do it online.

Link to comment
Share on other sites

  • 3 months later...

Canada Post Automatic Labels 1.2.2

==================================

 

Version 1.2.2 (2009-11-17)

- Fix changed login process

- Remove Purolator and add the new FedEx shipping methods

 

Please see http://addons.oscommerce.com/info/5445 to download

 

Doesn't seem to work! All I am getting now is

 

Fatal error: Call to undefined function cp_post_var() in ship_canadapost.php on line 273

Link to comment
Share on other sites

Whoops, looks like I missed to include the changes to admin/includes/functions/ship_canadapost.php

You need to add this function at the end of that file:

function cp_post_var($var) {
 if(get_magic_quotes_gpc()) {
   return stripslashes($_POST[$var]);
 } else {
   return $HTTP_POST_VARS[$var];
 }
}

I fixed this in the package with version 1.2.3.

Edited by natrium42
Link to comment
Share on other sites

  • 3 months later...

I'm getting error at Step 7; it seems like the credit card is being charged but then it crashes somewhere...

 

Step 7. Error: Failed check in .../public_html/shop/admin/ship_canadapost.php at line 740. This most likely means that Canada Post has changed their user interface. You need to update your Canada Post Automatic Shipping Labels module.

 

Any idea what's going on? I just reinstalled this contrib to see if it would fix it but no.

Link to comment
Share on other sites

  • 3 weeks later...

The new invoice.php has things for customs (like Harmonization code and short description). Use at your own discretion.

 

You can run the SQL statements through a screen in myPhpAdmin by copying and pasting the code out of the new_install.sql. Of course, backup your database or better yet use a test server.

 

Thanks,

 

Now one more problem - in the Manufacturers section of Admin, if I try to change the country code it is not successful UNLESS I also define a Manufacturer's Image at the same time! I tried just doing the Manufacturer's URL instead of Image but while it did record the URL that did not change the countries_id from '0', only if I added an image or changed the image would it update the manufacturer's country of origin...

 

Is this a bug or did I miss a step during install?

 

John :-#)#

Link to comment
Share on other sites

OK, reinstalled the 1.2.3 label program, but getting stuck at step 5 - I'm testing a US customer address and looking over the code sent back by CP I see this in the middle of Step 3:

 

<form name="theForm" action="../ShippingServlet" method="post">

<input type="Hidden" name="translatorName" value="cpc.ui.online.shipping.ShippingInfoTranslator">

<input type="Hidden" name="pageName" value="shipping/estShipping.jsp?locale=en_CA&formId=130">

<input type="Hidden" name="errorMessage" value="">

<input type="Hidden" name="errorField" value="">

<input type="Hidden" name="nextPageFormId" value="121">

<input type="hidden" name="clientId" value=""> <!--this field is used in retrieving an address from address book-->

<input type="hidden" name="formId" value="130">

<input type="hidden" name="maxAddrBookEntry" value="250">

<input type="hidden" name="numAddrBookEntry" value="0">

<input type="hidden" name="irsNo" value="">

 

Note that "formId" value (130 - International) appears to be set by these lines:

 

<tr><td class="nav" height="25" width="200"><a href="javascript: submitNavigationForm('shipping/estShipping.jsp?locale=en_CA&formId=110')" class="nav" target="_top" >Ship Canada</a></td></tr>

<tr><td class="nav" height="25" width="200"><a href="javascript: submitNavigationForm('ShippingEOE?useraction=start&locale=en_CA')" class="nav" target="_top" >Ship Canada - Express Order Entry</a></td></tr>

<tr><td class="nav" height="25" width="200"><a href="javascript: submitNavigationForm('shipping/estShipping.jsp?locale=en_CA&formId=120')" class="nav" target="_top">Ship USA</a></td></tr>

<tr><td class="nav" height="25" width="200"><a href="javascript: submitNavigationForm('shipping/estShipping.jsp?locale=en_CA&formId=130')" class="nav" target="_top">Ship International</a></td></tr>

 

so somewhere the "US" destination (formId=120) is not getting passed through - leading to the program defaulting to International (formId=130). This explains why it fails in Step five with the error message:

 

Step 5. Error: Failed check in /xxx/.../catalog/admin/ship_canadapost.php at line 545

 

with line 545 showing the result of the country code (if wrong) I assume.

 

Trying to figure out where the "US" destination is passed through to CP so I can fix the problem, however my PHP error log only shows when I send the label request to CP (press "Submit" button http://www....com/catalog/admin/ship_canadapost.php?oID=4&action=new&status=3:)

 

[20-Mar-2010 21:57:15] PHP Notice: Constant AFFILIATE_NOTIFY_AFTER_BILLING already defined in /usr/..../catalog/admin/includes/application_top.php on line 69

[20-Mar-2010 21:57:16] PHP Notice: Undefined index: cID in /usr/..../catalog/admin/ship_canadapost.php on line 261

[20-Mar-2010 21:57:34] PHP Notice: Constant AFFILIATE_NOTIFY_AFTER_BILLING already defined in /usr/.../catalog/admin/includes/application_top.php on line 69

[20-Mar-2010 21:57:34] PHP Notice: Undefined variable: HTTP_POST_VARS in /usr/..../catalog/admin/includes/functions/ship_canadapost.php on line 123

[20-Mar-2010 21:57:34] PHP Notice: Undefined variable: HTTP_POST_VARS in /usr/..../catalog/admin/includes/functions/ship_canadapost.php on line 123

(repeats same error another 15 times then ends with)

[20-Mar-2010 21:57:39] PHP Notice: Undefined offset: 1 in /usr/..../catalog/admin/includes/functions/ship_canadapost.php on line 108

 

Ideas?

 

John :-#)#

Link to comment
Share on other sites

OK, reinstalled the 1.2.3 label program, but getting stuck at step 5 - I'm testing a US customer address and looking over the code sent back by CP I see this in the middle of Step 3:

 

<form name="theForm" action="../ShippingServlet" method="post">

<input type="Hidden" name="translatorName" value="cpc.ui.online.shipping.ShippingInfoTranslator">

<input type="Hidden" name="pageName" value="shipping/estShipping.jsp?locale=en_CA&formId=130">

<input type="Hidden" name="errorMessage" value="">

<input type="Hidden" name="errorField" value="">

<input type="Hidden" name="nextPageFormId" value="121">

<input type="hidden" name="clientId" value=""> <!--this field is used in retrieving an address from address book-->

<input type="hidden" name="formId" value="130">

<input type="hidden" name="maxAddrBookEntry" value="250">

<input type="hidden" name="numAddrBookEntry" value="0">

<input type="hidden" name="irsNo" value="">

 

Note that "formId" value (130 - International) appears to be set by these lines:

 

<tr><td class="nav" height="25" width="200"><a href="javascript: submitNavigationForm('shipping/estShipping.jsp?locale=en_CA&formId=110')" class="nav" target="_top" >Ship Canada</a></td></tr>

<tr><td class="nav" height="25" width="200"><a href="javascript: submitNavigationForm('ShippingEOE?useraction=start&locale=en_CA')" class="nav" target="_top" >Ship Canada - Express Order Entry</a></td></tr>

<tr><td class="nav" height="25" width="200"><a href="javascript: submitNavigationForm('shipping/estShipping.jsp?locale=en_CA&formId=120')" class="nav" target="_top">Ship USA</a></td></tr>

<tr><td class="nav" height="25" width="200"><a href="javascript: submitNavigationForm('shipping/estShipping.jsp?locale=en_CA&formId=130')" class="nav" target="_top">Ship International</a></td></tr>

 

so somewhere the "US" destination (formId=120) is not getting passed through - leading to the program defaulting to International (formId=130). This explains why it fails in Step five with the error message:

 

Step 5. Error: Failed check in /xxx/.../catalog/admin/ship_canadapost.php at line 545

 

with line 545 showing the result of the country code (if wrong) I assume.

 

Trying to figure out where the "US" destination is passed through to CP so I can fix the problem, however my PHP error log only shows when I send the label request to CP (press "Submit" button http://www....com/catalog/admin/ship_canadapost.php?oID=4&action=new&status=3:)

 

[20-Mar-2010 21:57:15] PHP Notice: Constant AFFILIATE_NOTIFY_AFTER_BILLING already defined in /usr/..../catalog/admin/includes/application_top.php on line 69

[20-Mar-2010 21:57:16] PHP Notice: Undefined index: cID in /usr/..../catalog/admin/ship_canadapost.php on line 261

[20-Mar-2010 21:57:34] PHP Notice: Constant AFFILIATE_NOTIFY_AFTER_BILLING already defined in /usr/.../catalog/admin/includes/application_top.php on line 69

[20-Mar-2010 21:57:34] PHP Notice: Undefined variable: HTTP_POST_VARS in /usr/..../catalog/admin/includes/functions/ship_canadapost.php on line 123

[20-Mar-2010 21:57:34] PHP Notice: Undefined variable: HTTP_POST_VARS in /usr/..../catalog/admin/includes/functions/ship_canadapost.php on line 123

(repeats same error another 15 times then ends with)

[20-Mar-2010 21:57:39] PHP Notice: Undefined offset: 1 in /usr/..../catalog/admin/includes/functions/ship_canadapost.php on line 108

 

Ideas?

 

John :-#)#

 

OK, chatting with Alexei it turns out that OSCommerce/OSCMax are using something called long arrays, which are being phased out of php - they are not going to be available once php 6.0 is released (this needs to be addressed!).

 

So the cure for the undefined variable HTTP_POST_VARS (and HTP_GET_VARS) is to simply replace $HTTP_POST_VARS with $_POST and to replace $HTTP_GET_VARS with $_GET in his contribution which is Canada Post Automatic Labels 1.2.3.

 

BUT NOT for the rest of your OSCMax/Commerce site...for now...

 

I used a good text editor (TextWrangler - MAC) to do the required search & replace and now I get past this problem as shown above, and down to the Payment section, where I have inserted the php code "die();" which terminates the PHP code before making a payment to Canada Post (section 6 as I recall).

 

I'll try to write this up a bit clearer once I have verified that this works for me, and have checked with Alexei - he is very busy right now with exams I believe.

 

John :-#)#

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...