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;
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
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;
?>
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");
Code: Select all
curl_setopt($ch, CURLOPT_URL, "mysite.com/cpcall.php:80");
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>
This original workaround was created here: http://www.oscommerce.com/community/contributions,391
With the attached zip file