Post by nightvision04 » Fri Dec 23, 2011 5:06 pm

I am using fatcow hosting services (who does not open port 30000 for any reason).

Since I purchased the Canada Post module from Qphoria and in tend to get it working, i'm proposing/adapting a solution and wanted to bounce the idea off some expertise.

1. Step One - The following script is placed on a server with port 30000 open and is run to test interaction with Canada post.

Code: Select all

<?php
    function sendToHost($data)
	{
		set_time_limit(5);
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_URL, "sellonline.canadapost.ca:30000");  //For testing port 30000 on the server
		//curl_setopt($ch, CURLOPT_URL, "mysite.com/cpcall.php:80");  
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		//curl_setopt($ch, CURLOPT_PROXY, "http://proxy.shr.secureserver.net:3128");  //For GoDaddy.com accounts
		curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 2678400);
		curl_setopt( $ch, CURLOPT_HEADER, 0 );
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
		$buf = "";
		$buf = curl_exec($ch);
		curl_close( $ch );
        if($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;
    }

	$strXML = "<?xml version=\"1.0\" ?>";
	$strXML .= "<eparcel>\n";
	$strXML .= "        <language>en</language>\n";
	$strXML .= "        <ratesAndServicesRequest>\n";
	$strXML .= "                <merchantCPCID>CPC_DEMO_XML</merchantCPCID>\n";
	$strXML .= "                <fromPostalCode>H4E1T2</fromPostalCode>\n";
	$strXML .= "                <turnAroundTime>24</turnAroundTime>\n";
	$strXML .= "                <itemsPrice>25.00</itemsPrice>\n";
	$strXML .= "            <lineItems>\n";
	$strXML .= "	    <item>\n";
	$strXML .= "                <quantity>1</quantity>\n";
	$strXML .= "                <weight>1</weight>\n";
	$strXML .= "                <length>4</length>\n";
	$strXML .= "                <width>4</width>\n";
	$strXML .= "                <height>4</height>\n";
	$strXML .= "                <description>none</description>\n";
	$strXML .= "	    </item>\n";
	$strXML .= "           </lineItems>\n";
	$strXML .= "               <city>Montreal</city>\n";
	$strXML .= "               <provOrState>QC</provOrState>\n";
	$strXML .= "               <country>CA</country>\n";
	$strXML .= "               <postalCode>H4E1T2</postalCode>\n";
	$strXML .= "        </ratesAndServicesRequest>\n";
	$strXML .= "</eparcel>\n";

	$response = sendToHost($strXML);
	echo $response;
I I was able to run this code on a remote server and was returned the following message in my browser:

Code: Select all

]> 1 OK 10510414 0.0 0 Priority Courier 16.26 2011-12-28 2011-12-29 5 true P_0 Expedited 7.64 2011-12-28 2011-12-29 5 false P_0 Regular 7.64 2011-12-28 2011-12-30 6 false P_0 P_0 Small Box 1.2 1.2 25.0 17.0 16.0 1 none No Yes No
Good. Okay its working correctly.

Step 2 - Create a php file with the following CURL code.

Code: Select all

<?php
    function sendToHost($data)
	{
		set_time_limit(5);
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_URL, "sellonline.canadapost.ca:30000");
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		//curl_setopt($ch, CURLOPT_PROXY, "http://proxy.shr.secureserver.net:3128");  'For GoDaddy.com accounts
		curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 2678400);
		curl_setopt( $ch, CURLOPT_HEADER, 0 );
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
		$buf = "";
		$buf = curl_exec($ch);
		curl_close( $ch );
        if($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;
    }

	$data = $_REQUEST['XMLRequest'];
	$response = sendToHost($strXML);
	echo $response;
?>
Since we have tested port 30000 and it is working from this second, accessible server, this second script will be used to interact with Canada post there.

Now technically, shouldn't I be able to call that script cpcall.php on port 80? It will in turn then communicate through port 30000 for me. This modification will be made in my /catalog/model/shipping/canadapost.php file by changing the line

Code: Select all

curl_setopt($ch, CURLOPT_URL, "sellonline.canadapost.ca:30000");
to the following?

Code: Select all

curl_setopt($ch, CURLOPT_URL, "mysite.com/cpcall.php:80");
I believe this logic works, but instead of tunneling the data through, I get stuck at a "302: found" error.

Here it is :

Code: Select all

<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://www.mysite'shosting.com/404.shtml">here</a>.</p>
<hr>
<address>Apache/2.2.20 (Unix) mod_ssl/2.2.20 OpenSSL/0.9.8e-fips-rhel5 Line-Edit/1.0.0 mod_bwlimited/1.4 Server at mysite.com Port 80</address>
</body></html>
How can I get around this 302 error?

This original workaround was created here: http://www.oscommerce.com/community/contributions,391

With the attached zip file

Attachments


New member

Posts

Joined
Sat Oct 15, 2011 1:17 pm

Post by Qphoria » Fri Dec 23, 2011 9:39 pm

Yea I tried the oscommerce work around but never got it to work.
Still if you are getting the initial test to work then you should have no problem with the mod and not need to redirect.

As long as you get this:

Code: Select all

]> 1 OK 10510414 0.0 0 Priority Courier 16.26 2011-12-28 2011-12-29 5 true P_0 Expedited 7.64 2011-12-28 2011-12-29 5 false P_0 Regular 7.64 2011-12-28 2011-12-30 6 false P_0 P_0 Small Box 1.2 1.2 25.0 17.0 16.0 1 none No Yes No
That means it is working on your site.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by nightvision04 » Sat Dec 24, 2011 4:54 am

I secretly figured so Qphoria. I found the artifact, "//For testing port 30000 on the server" in your script and put two and two together. :)

The only problem is that I was running the test script from a remote server with the port 30000 unblocked. Not my current hosting under fatcow. Any suggestions why that 302 found error happens?

New member

Posts

Joined
Sat Oct 15, 2011 1:17 pm

Post by nightvision04 » Mon Dec 26, 2011 4:15 am

Okay, Im a bit closer to getting it I think.

If I change the following line of code in /catalog/model/shipping/canadapost.php...

Code: Select all

curl_setopt($ch, CURLOPT_URL, "http://myhost.com/cpcall.php:80"); 
... By not specifying port 80, to this:

Code: Select all

curl_setopt($ch, CURLOPT_URL, "http://myhost.com/cpcall.php"); 
...Then the result is that I get a "connection timed out" error. In fact its the same error that I recieve when my cpcall.php script runs successfuly by its self on an unblocked (port 30000) host. The reason for the error, in my opinion, is that the canadapost.php has sent insufficient input values to return an output value.

@Qphoria: you may also be familiar with this error since you played with the occommerce workaround.

Now that I have proven that my CURL proxy has been somewhat successful in returning values from canadapost.php, can you see whats causing insufficient values to be sent to the remote CURL script host?

New member

Posts

Joined
Sat Oct 15, 2011 1:17 pm

Post by nightvision04 » Mon Dec 26, 2011 4:22 am

This is what the error message now looks like:

Code: Select all

]> -1002 The connection timed out. 10604101
The 8 digit number at the ened of the error message represents the number of exchanges between the sellonline server and remote clients. If I refresh the page, the number goes higher, proportionally to how long I wait to perform the operation.

New member

Posts

Joined
Sat Oct 15, 2011 1:17 pm

Post by nightvision04 » Sat Dec 31, 2011 1:17 pm

@Qphoria:

I now have a fix. I have successfully used cpcall.php on a remote server to bypass port 30000 on the host using CURL. Let me know if you would like me to share my code with you so you can upgrade your current CP script (paid version).

New member

Posts

Joined
Sat Oct 15, 2011 1:17 pm

Post by harmonymusic » Thu Feb 23, 2012 2:58 am

I have the same issue with port 30000. "freehostia" doesn't unlock the port :( .
Could you please post the code to bypass port 30000 ? thanks.

New member

Posts

Joined
Sat Feb 11, 2012 1:29 am

Post by bobwhite » Thu Mar 29, 2012 3:04 am

Hi guys,
How to find out if port is open or not? I definitely have problems connecting to canadapost server, but not sure if it is setting or closed port.
Thanks,
Bob

P.S. Working on Canada Post Module 1.5.x
I ran script (Step 1) posted by nightvision04 from my hosting server and got back this in the browser:

Code: Select all

]> 1 OK 3590118 1.0 0 Priority Courier 16.77 2012-04-02 2012-04-03 3 true P_0 Expedited 7.87 2012-04-02 2012-04-03 3 false P_0 Regular 7.87 2012-04-02 2012-04-04 4 false P_0 P_0 Small Box 1.2 1.2 25.0 17.0 16.0 1 none No Yes No 
, but when I am trying to estimate shipping cost, I am getting: "Error connecting to Canada Post".
Any help will be appreciated.
Thanks,
Bob

User avatar
New member

Posts

Joined
Thu Jan 26, 2012 8:20 am
Who is online

Users browsing this forum: No registered users and 4 guests