Jump to content

Tnt Shipping Intergration


Recommended Posts

Hi everybody,

 

I am trying to build lets say a function to impliment pricing from TNT Express to my carrier. So i have created a Carrier on my Back office and named it TNT, checked all locations and 0 costs.

 

Now i need to impliment the code above its a test file for connecting and gatting price from TNT Servers.

 

Do you have any ideas how a can proceed to this problem?

 

I think i need to edit the cart so the prices will get updated and the TNT carrier by the shipping step on checkout.

 

But wich is the best and fastest way to do that?

 

Thank you for your Time!

 

<?php
 
$postContent= getXML();
 
// Get key
$initialResult = doPost($postContent); // These return null
$header = $initialResult[0];
$key = substr($initialResult[1], 9);
echo "<b>Header:</b> $header\n\n\n<br><br>";
echo "<b>KEY:</b>". htmlspecialchars($key);
 
echo "<hr>";
 
// Get result
$xmlResults = doPost("GET_RESULT:".$key."\n");
$header = $xmlResults[0];
$content = $xmlResults[1];
echo "<b>Header:</b> $header\n\n\n<br><br>";
echo "<b>Content:</b>". htmlspecialchars($content);
 
 
 function doPost($_postContent) {
$postContent = "xml_in=".$_postContent;
 
$host="iconnection.tnt.com";
$contentLen = strlen($postContent);
 
$httpHeader ="POST /shippergate2.asp HTTP/1.1\r\n"
."Host: $host\r\n"
."User-Agent: PHP Script\r\n"
."Content-Type: application/x-www-form-urlencoded\r\n"
."Content-Length: $contentLen\r\n"
."Connection: close\r\n"
."\r\n";
 
$httpHeader.=$postContent;
 
try {
$fp = fsockopen($host, 81);
 
fputs($fp, $httpHeader);
 
$result = "";
   
while(!feof($fp)) {
        // receive the results of the request
       $result .= fgets($fp, 128);
}
 
// close the socket connection:
 
fclose($fp);
 
$result = explode("\r\n\r\n", $result,3);
 
$header1 = isset($result[0]) ? $result[0] : '';
$header2 = isset($result[1]) ? $result[1] : '';
$content = isset($result[2]) ? $result[2] : '';
 
return array($header1, $header2, $content);
 
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
 
return array('Error', 'Error', 'Error');
 }
 
 
 
 
 
function getXML() {
 
$xml = "<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE ESHIPPER SYSTEM 'http://164.39.8.225:81/ShipperDTD2.0/EShipperIN2.dtd'>";
$xml .= "<ESHIPPER>";
$xml .= "<LOGIN>";
$xml .= "<COMPANY>...</COMPANY>"; // Fill in user ID,...
$xml .= "<PASSWORD>...</PASSWORD>"; // ...Password...
$xml .= "<APPID>IN</APPID>";
$xml .= "<APPVERSION>2</APPVERSION>";
$xml .= "</LOGIN>";
$xml .= "<CONSIGNMENTBATCH>";
$xml .= "<SENDER>";
$xml .= "<COMPANYNAME>Sender Co</COMPANYNAME>";
$xml .= "<STREETADDRESS1>TEST DO NOT COLLECT1</STREETADDRESS1>";
$xml .= "<STREETADDRESS2>TEST DO NOT COLLECT2</STREETADDRESS2>";
$xml .= "<STREETADDRESS3>TEST DO NOT COLLECT3</STREETADDRESS3>";
$xml .= "<CITY>Atherstone</CITY>";
$xml .= "<PROVINCE>Warwickshire</PROVINCE>";
$xml .= "<POSTCODE>CV9 2ry</POSTCODE>";
$xml .= "<COUNTRY>GB</COUNTRY>";
$xml .= "<ACCOUNT>...</ACCOUNT>"; // ...and Account number
$xml .= "<VAT></VAT>";
$xml .= "<CONTACTNAME>Mr Contact</CONTACTNAME>";
$xml .= "<CONTACTDIALCODE>01827</CONTACTDIALCODE>";
$xml .= "<CONTACTTELEPHONE>717733</CONTACTTELEPHONE>";
$xml .= "<CONTACTEMAIL>[email protected]</CONTACTEMAIL>";
$xml .= "<COLLECTION>";
$xml .= "<COLLECTIONADDRESS>";
$xml .= "<COMPANYNAME>Collection Name</COMPANYNAME>";
$xml .= "<STREETADDRESS1>TEST DO NOT COLLECT4</STREETADDRESS1>";
$xml .= "<STREETADDRESS2>TEST DO NOT COLLECT5</STREETADDRESS2>";
$xml .= "<STREETADDRESS3>TEST DO NOT COLLECT6</STREETADDRESS3>";
$xml .= "<CITY>Atherstone</CITY>";
$xml .= "<PROVINCE>Warwickshire</PROVINCE>";
$xml .= "<POSTCODE>CV9 1TT</POSTCODE>";
$xml .= "<COUNTRY>GB</COUNTRY>";
$xml .= "<VAT></VAT>";
$xml .= "<CONTACTNAME>Mr Contact</CONTACTNAME>";
$xml .= "<CONTACTDIALCODE>00000</CONTACTDIALCODE>";
$xml .= "<CONTACTTELEPHONE>700005</CONTACTTELEPHONE>";
$xml .= "<CONTACTEMAIL>[email protected]</CONTACTEMAIL>";
$xml .= "</COLLECTIONADDRESS>";
$xml .= "<SHIPDATE>17/12/2010</SHIPDATE>"; // Make sure this is a future date
$xml .= "<PREFCOLLECTTIME>";
$xml .= "<FROM>09:00</FROM>";
$xml .= "<TO>10:00</TO>";
$xml .= "</PREFCOLLECTTIME>";
$xml .= "<ALTCOLLECTTIME>";
$xml .= "<FROM>11:00</FROM>";
$xml .= "<TO>12:00</TO>";
$xml .= "</ALTCOLLECTTIME>";
$xml .= "<COLLINSTRUCTIONS>use rear gate </COLLINSTRUCTIONS>";
$xml .= "</COLLECTION>";
$xml .= "</SENDER> ";
$xml .= "<CONSIGNMENT>";
$xml .= "<CONREF>ref2</CONREF>";
$xml .= "<DETAILS>";
$xml .= "<RECEIVER>";
$xml .= "<COMPANYNAME>Receiver Name</COMPANYNAME>";
$xml .= "<STREETADDRESS1>TEST DO NOT COLLECT7</STREETADDRESS1>";
$xml .= "<STREETADDRESS2>TEST DO NOT COLLECT8</STREETADDRESS2>";
$xml .= "<STREETADDRESS3>TEST DO NOT COLLECT9</STREETADDRESS3>";
$xml .= "<CITY>Amsterdam</CITY>";
$xml .= "<PROVINCE></PROVINCE>";
$xml .= "<POSTCODE>1100 AA</POSTCODE>";
$xml .= "<COUNTRY>NL</COUNTRY>";
$xml .= "<VAT>7668880</VAT>";
$xml .= "<CONTACTNAME>Mr Frank</CONTACTNAME>";
$xml .= "<CONTACTDIALCODE>1672</CONTACTDIALCODE>";
$xml .= "<CONTACTTELEPHONE>987432</CONTACTTELEPHONE>";
$xml .= "<CONTACTEMAIL>[email protected]</CONTACTEMAIL>";
$xml .= "</RECEIVER>";
$xml .= "<DELIVERY>";
$xml .= "<COMPANYNAME>Delivery Name</COMPANYNAME>";
$xml .= "<STREETADDRESS1>TEST DO NOT COLLECT10</STREETADDRESS1>";
$xml .= "<STREETADDRESS2>TEST DO NOT COLLECT11</STREETADDRESS2>";
$xml .= "<STREETADDRESS3>TEST DO NOT COLLECT12</STREETADDRESS3>";
$xml .= "<CITY>Amsterdam</CITY>";
$xml .= "<PROVINCE></PROVINCE>";
$xml .= "<POSTCODE>1100 AA</POSTCODE>";
$xml .= "<COUNTRY>NL</COUNTRY>";
$xml .= "<VAT>7668880</VAT>";
$xml .= "<CONTACTNAME>Mr Frank</CONTACTNAME>";
$xml .= "<CONTACTDIALCODE>1672</CONTACTDIALCODE>";
$xml .= "<CONTACTTELEPHONE>987432</CONTACTTELEPHONE>";
$xml .= "<CONTACTEMAIL>[email protected]</CONTACTEMAIL>";
$xml .= "</DELIVERY>";
$xml .= "<CUSTOMERREF>DISKS</CUSTOMERREF>";
$xml .= "<CONTYPE>N</CONTYPE>";
$xml .= "<PAYMENTIND>S</PAYMENTIND>";
$xml .= "<ITEMS>2</ITEMS>";
$xml .= "<TOTALWEIGHT>1.4</TOTALWEIGHT>";
$xml .= "<TOTALVOLUME>1.0</TOTALVOLUME>";
$xml .= "<CURRENCY>GBP</CURRENCY>";
$xml .= "<GOODSVALUE>180.00</GOODSVALUE>";
$xml .= "<INSURANCEVALUE>150.00</INSURANCEVALUE>";
$xml .= "<INSURANCECURRENCY>GBP</INSURANCECURRENCY>";
$xml .= "<SERVICE>15N</SERVICE>";
$xml .= "<OPTION>PR</OPTION>";
$xml .= "<DESCRIPTION>assorted office accessories</DESCRIPTION>";
$xml .= "<DELIVERYINST>ggg</DELIVERYINST>";
$xml .= "<PACKAGE>";
$xml .= "<ITEMS>3</ITEMS>";
$xml .= "<DESCRIPTION>box 1</DESCRIPTION>";
$xml .= "<LENGTH>0.1</LENGTH>";
$xml .= "<HEIGHT>0.2</HEIGHT>";
$xml .= "<WIDTH>0.3</WIDTH>";
$xml .= "<WEIGHT>0.4</WEIGHT>";
$xml .= "<ARTICLE>";
$xml .= "<ITEMS>1</ITEMS>";
$xml .= "<DESCRIPTION>paperclips</DESCRIPTION>";
$xml .= "<WEIGHT>.03</WEIGHT>";
$xml .= "<INVOICEVALUE>2.30</INVOICEVALUE>";
$xml .= "<INVOICEDESC>metal paperclips</INVOICEDESC>";
$xml .= "<HTS>ABC</HTS>";
$xml .= "<COUNTRY>GB</COUNTRY>";
$xml .= "</ARTICLE>";
$xml .= "</PACKAGE>";
$xml .= "<PACKAGE>";
$xml .= "<ITEMS>3</ITEMS>";
$xml .= "<DESCRIPTION>box 2</DESCRIPTION>";
$xml .= "<LENGTH>0.5</LENGTH>";
$xml .= "<HEIGHT>0.6</HEIGHT>";
$xml .= "<WIDTH>0.7</WIDTH>";
$xml .= "<WEIGHT>0.8</WEIGHT>";
$xml .= "<ARTICLE>";
$xml .= "<ITEMS>1</ITEMS>";
$xml .= "<DESCRIPTION>paperclips</DESCRIPTION>";
$xml .= "<WEIGHT>.03</WEIGHT>";
$xml .= "<INVOICEVALUE>2.30</INVOICEVALUE>";
$xml .= "<INVOICEDESC>metal paperclips</INVOICEDESC>";
$xml .= "<HTS>ABC</HTS>";
$xml .= "<COUNTRY>GB</COUNTRY>";
$xml .= "</ARTICLE>";
$xml .= "</PACKAGE>";
 
$xml .= "</DETAILS>";
$xml .= "</CONSIGNMENT>";
$xml .= "</CONSIGNMENTBATCH>";
$xml .= "<ACTIVITY>";
$xml .= "<CREATE>";
$xml .= "<CONREF>ref2</CONREF>";
$xml .= "</CREATE>";
$xml .= "<RATE>";
$xml .= "<CONREF>ref2</CONREF>";
$xml .= "</RATE>";
//$xml .= "<BOOK>"; // Comment out so a booking is not made
//$xml .= "<CONREF>ref2</CONREF>"; //
//$xml .= "</BOOK>"; //
$xml .= "<PRINT>";
$xml .= "<CONNOTE>";
$xml .= "<CONREF>ref2</CONREF>";
$xml .= "</CONNOTE>";
$xml .= "<LABEL>";
$xml .= "<CONREF>ref2</CONREF>";
$xml .= "</LABEL>";
$xml .= "<MANIFEST>";
$xml .= "<CONREF>ref2</CONREF>";
$xml .= "</MANIFEST>";
$xml .= "<INVOICE>";
$xml .= "<CONREF>ref2</CONREF>";
$xml .= "</INVOICE>";
$xml .= "</PRINT>";
$xml .= "</ACTIVITY>";
$xml .= "</ESHIPPER>";
 
 
 
return $xml;
}
?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...