ive edited the code hoping to get rid of the error, i think all the errors are gone now, but when i try to calculate shipping i get the error: 004 The account number supplied is invalid or not assigned to this login.
heres a pic
my account details are all correct..
ive attached the TNT API i got a copy of.
also this is the full code that im trying to fix:
Code: Select all
<?php
/**
* TNT Express Post Shipping Module for OpenCart v1.3.4}$/
*
* @package OpenCart
*/
/**
* TNTPost Model
*/
class ModelShippingTntpost extends Model {
/**
* Return quotation details across all TNT shipping methods
*
* @param int $country_id
* @param int $zone_id
* @param int $postcode
* @return array Quotation details
*/
function getQuote($address) {
$this->load->language('shipping/tntpost');
if ($this->config->get('tntpost_status')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('tntpost_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if (!$this->config->get('tntpost_geo_zone_id')) {
$status = TRUE;
} elseif ($query->num_rows) {
$status = TRUE;
} else {
$status = FALSE;
}
} else {
$status = FALSE;
}
$method_data = array();
if ($status) {
$this->load->model('localisation/country');
$quote_data = array();
if (!preg_match('/^[0-9]{4}$/', $address['postcode'])) {
$error = 'Your postcode is not valid in Australia';
} else {
// tomorrow morning, 9am
$tomorrow = mktime('9', 0, 0 ,date('m'), date('d') + 1, date('Y'));
// is it a weekend?
if (date('D', $tomorrow) == 'Sat') {
$add_days = 2;
} elseif (date('D', $tomorrow) == 'Sun') {
$add_days = 1;
} else {
$add_days = 0;
}
$ship_date = date('Y-m-d', $tomorrow + (3600 * 24 * $add_days));
$timestamp = date('Y-m-d\TH:i:s', time());
// start to build XML
$Xml = '
<enquiry xmlns="https://www.tntexpress.com.au/interaction/asps/login.asp">
<ratedTransitTimeEnquiry>
<cutOffTimeEnquiry>
<collectionAddress>
<suburb>'.$this->config->get('tntpost_collect_suburb').'</suburb>
<postCode>'.$this->config->get('tntpost_collect_pcode').'</postCode>
<state>'.$this->config->get('tntpost_collect_state').'</state>
</collectionAddress>
<deliveryAddress>
<suburb>' . $shipping_address['city'] . '</suburb>
<postCode>' . $shipping_address['postcode'] . '</postCode>
<state>' . $shipping_address['zone_code'] . '</state>
</deliveryAddress>
<shippingDate>'.$ship_date.'</shippingDate>
<userCurrentLocalDateTime>' . $timestamp . '</userCurrentLocalDateTime>
<dangerousGoods>
<dangerous>false</dangerous>
</dangerousGoods>
<packageLines packageType="N">';
foreach ($this->cart->getProducts() as $product) {
$option_data = array();
$Xml .= '
<packageLine>
<numberOfPackages>'.$product['quantity'].'</numberOfPackages>
<dimensions unit="cm">
<length>'.round($product['length'] == '0' ? '70' : $product['length']).'</length>
<width>'.round($product['width'] == '0' ? '70' : $product['width']).'</width>
<height>'.round($product['height'] == '0' ? '70' : $product['height']).'</height>
</dimensions>
<weight unit="kg">
<weight>'.round($product['weight']).'</weight>
</weight>
</packageLine>';
}
$Xml .= '
</packageLines>
</cutOffTimeEnquiry>
<termsOfPayment>
<senderAccount>'.$this->config->get('tntpost_tnt_customer_code').'</senderAccount>
<payer>S</payer>
</termsOfPayment>
</ratedTransitTimeEnquiry>
</enquiry>';
$Request = rawurlencode($Xml);
$CurlURL = 'https://www.tntexpress.com.au/Rtt/inputRequest.asp';
$CurlQuery = 'Username='.$this->config->get('tntpost_tnt_user').'&Password='.$this->config->get('tntpost_tnt_password').'&XMLRequest=' . $Request;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $CurlURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $CurlQuery);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Needs to be included if no *.crt is available to verify SSL certificates
curl_setopt($ch,CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
if ($result) {
## catch libxml errors
libxml_use_internal_errors(true);
$quote_xml = @simplexml_load_string($result);
if ($quote_xml) {
## process error from TNT
if (isset($quote_xml->error)) {
$error = $quote_xml->error->code . ' ' . $quote_xml->error->description;
} else {
// did we get any ratings?
if (isset($quote_xml->ratedTransitTimeResponse->ratedProducts)) {
foreach($quote_xml->ratedTransitTimeResponse->ratedProducts->ratedProduct as $option) {
## send quote data for enabled modules
if ($this->config->get('tntpost_' . $option->product->code)) {
$quote_data['tntpost_' . $option->product->code] = array(
'id' => 'tntpost.tntpost_' . $option->product->code,
'title' => (string)($option->product->description),
'cost' => (string)$option->quote->price,
'tax_class_id' => $this->config->get('tntpost_tax_class_id'),
'text' => '$' . sprintf('%.2f', ($this->tax->calculate((string)$option->quote->price, $this->config->get('tntpost_tax_class_id'), $this->config->get('config_tax')))),
'estimated_delivery_date' => ($this->config->get('tntpost_display_estimate') ? date('l, jS F', strtotime($option->estimatedDeliveryDateTime)) : false)
);
}
}
} else {
// no ratings, process broken rules
if (isset($quote_xml->ratedTransitTimeResponse->brokenRules)) {
$error = $quote_xml->ratedTransitTimeResponse->brokenRules->brokenRule->description;
} else {
$error = 'An undetermined error has occurred. Please check TNT module configuration.';
}
}
}
} else {
$error = "Failed loading XML";
foreach(libxml_get_errors() as $xml_error) {
$error .= $xml_error->message;
}
}
} else {
$error = 'Error in response from TNT. Please check module configuration.';
}
} ## postcode error
$method_data = array(
'id' => 'tntpost',
'title' => $this->language->get('text_title'),
'quote' => $quote_data,
'sort_order' => $this->config->get('tntpost_sort_order'),
'error' => $error //$error
);
}
return $method_data;
}
}