Full service web hosting, great prices and support. Starts at $1.99/month!
Results 1 to 3 of 3

Thread: Canada Post's sellonline module now requires an API (REST/SOAP) to give shipping quotes!

  1. #1
    Active Member
    Canada Post's sellonline module now requires an API (REST/SOAP) to give shipping quotes!


    Join Date
    Sep 2009
    Location
    Vancouver, BC, Canada
    Posts
    481
    Contribute If you enjoy reading the
    content here, click the below
    image to support our site.
    Click Here To Contribute To Our Site

    Total Contributions For

    JRR     $ 180.00
    Rep Power
    69


    Default Canada Post's sellonline module now requires an API (REST/SOAP) to give shipping quotes!

    Anyone using the Canada Post sellonline feature to estimate packages and provide shipping quotes got a rude awakening Sept 23rd when the TCP way to interface was finally shut down. Little warning was given and apparently you had to be on the developer pages to see it as they did NOT email folks using sellonline to tell them it was going to be obsolete. Grumble.

    Anyway, if you were using the older osC Canada Post system you need to move to the REST/SOAP version which is here: I can't help right now as I am trying to figure it out myself, suffice it to say I wasn't really ready for this change although I did know it was coming. I actually started hunting around for a solution in 2014 but...well you know how it goes, the thing WAS working and I had other jobs to deal with.

    Now my online store can't give a quote for Canada Post and customers are not happy...

    More to come I guess. Need to sort this out today or tomorrow.

    Anyone else using sellonline and wants to talk with me about it please add to this topic and I'll catch it on the next email update...

    John :-#(# - unhappy John -

  2. #2
    Active Member
    Canada Post's sellonline module now requires an API (REST/SOAP) to give shipping quotes!


    Join Date
    Sep 2009
    Location
    Vancouver, BC, Canada
    Posts
    481
    Contribute If you enjoy reading the
    content here, click the below
    image to support our site.
    Click Here To Contribute To Our Site

    Total Contributions For

    JRR     $ 180.00
    Rep Power
    69


    Default Re: Canada Post's sellonline module now requires an API (REST/SOAP) to give shipping quotes!

    Was able to adapt the osCommerce Canada Post (CP) REST quotes, however the CP API does not use dimensions so have to figure out how to integrate the osCmax packaging with the CP system. Otherwise it appears to default to a fairly basic box size.

  3. #3
    Active Member
    Canada Post's sellonline module now requires an API (REST/SOAP) to give shipping quotes!


    Join Date
    Sep 2009
    Location
    Vancouver, BC, Canada
    Posts
    481
    Contribute If you enjoy reading the
    content here, click the below
    image to support our site.
    Click Here To Contribute To Our Site

    Total Contributions For

    JRR     $ 180.00
    Rep Power
    69


    1 out of 1 members found this post helpful.

    Default Re: Canada Post's sellonline module requires a php code modification to keep working...

    Actually, the changes to the original Canada Post PHP code (not the REST version) of the Sellonline code is fairly simple and works just fine.

    This is from cp_al2_sm4_1_2_3_4_5

    Go to catalog/includes/modules/canadapost.php

    Around line 212 you will find:
    PHP Code:
    function _sendToHost($host,$port,$method,$path,$data,$useragent=0) {
        // Supply a default method of GET if the one passed was empty
        if (empty($method))
            $method = 'GET';
        $method = strtoupper($method);
        if ($method == 'GET')
            $path .= '?' . $data;
        $buf = "";
        // try to connect to Canada Post server, for 30 second (was 2 seconds, but IBM told me Canada Post can take up to 30 seconds to respond
        $fp = @fsockopen($host, $port, $errno, $errstr, 30);

        if ( $fp ) {
          fputs($fp, "$method $path HTTP/1.1\n");
          fputs($fp, "Host: $host\n");
          fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
          fputs($fp, "Content-length: " . strlen($data) . "\n");
          if ($useragent)
            fputs($fp, "User-Agent: (your web site)\n");
          fputs($fp, "Connection: close\n\n");
          if ($method == 'POST')
            fputs($fp, $data);

          while (!feof($fp))
            $buf .= fgets($fp,128);
          fclose($fp);
        } else {
          $buf = '<?xml version="1.0" ?><eparcel><error><statusMessage>Cannot reach Canada Post Server. You may refresh this page (Press F5 on your keyboard) to try again.</statusMessage></error></eparcel>';
        }    
            
            if(!tep_not_null($buf)){
                $buf = '<?xml version="1.0" ?><eparcel><error><statusMessage>Cannot reach Canada Post Server. You may refresh this page (Press F5) to try again.</statusMessage></error></eparcel>';
            }
            
            return $buf;
        }
    replace all of that with:

    PHP Code:
        function _sendToHost($host,$port,$method,$path,$XML_data,$useragent=0) {
            $CP_url = 'https://sellonline.canadapost.ca/sellonline/Rating';
            $CP_Comm_context_options = array(
                  'http' => array(
                    'header' => "Content-type: application/x-www-form-urlencoded\r\n",
                    'method' => 'POST',
                    'content' => $XML_data,
                ),
                'ssl' => array(
                    'verify_peer' => false,
                    'verify_peer_name' => false
                )
            ); 
            $CP_context = stream_context_create($CP_Comm_context_options);
            $CP_response = file_get_contents($CP_url, false, $CP_context);
            if (empty($CP_response)) {
                $CP_response = '<?xml version="1.0" ?><eparcel><error><statusMessage>Cannot reach Canada Post Server. You may refresh this page (Press F5 on your keyboard) to try again.</statusMessage></error></eparcel>';
            }    
            if(!tep_not_null($CP_response)){
                $CP_response = '<?xml version="1.0" ?><eparcel><error><statusMessage>Cannot reach Canada Post Server. You may refresh this page (Press F5) to try again.</statusMessage></error></eparcel>';

            }
            
            return $CP_response;
        }
    Then if it doesn't work, check that you have to turned allow_url_fopen = on (the '=' may not be needed) in your php.ini file for the server!

    Doing this enabled me to still use sellonline - however they are not accepting new subcribers so this only works for established clients. The advantage of sellonline is the packing routine which allows you to measure up all your products (LxWxH & weight) and then let sellonline choose the best box from the list of boxes you provide to the system. Allows the shipping quotes to be fair to all.
    Last edited by JRR; 10-07-2019 at 09:09 PM.

Similar Threads

  1. Canada Post quotes and shipping labels by WayToShip
    By michael_s in forum New osCommerce Contributions
    Replies: 0
    Last Post: 01-25-2012, 05:04 PM
  2. Canada Post quotes and shipping labels by WayToShip
    By michael_s in forum New osCommerce Contributions
    Replies: 0
    Last Post: 01-23-2012, 10:03 PM
  3. Canada Post quotes and shipping labels by WayToShip
    By michael_s in forum New osCommerce Contributions
    Replies: 0
    Last Post: 07-25-2009, 05:11 PM
  4. Canada Post Automated Labels 2.0 AND Canada Post Shipping Module 4.0
    By michael_s in forum New osCommerce Contributions
    Replies: 0
    Last Post: 04-18-2008, 04:40 AM
  5. Canada Post Automated Labels 2.0 AND Canada Post Shipping Module 4.0
    By michael_s in forum New osCommerce Contributions
    Replies: 1
    Last Post: 04-10-2008, 01:21 PM

Tags for this Thread

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •