Page 1 of 1

How when a customer order a product to be automatically charged?

Posted: Mon Apr 23, 2018 3:23 pm
by xristos88
Hello,
I want to ask where I can import xml code so that when a customer order a product to be automatically charged, depending on the country and the pounds of the order.
I contacted the TNT courier where they gave me the corresponding code.
1. Where should I enter the code?
2. How do you communicate with the purchase form so that the <delivery>, <product>, <currency>, ... and the rest fields are automatically taken.
The username and password I have received from the TNT courier.
My site http://www.komboloiart.gr
Thank you!!

Xml code from TNT:

Code: Select all

<?php

    $Xml = "<?xml version='1.0' encoding='UTF-8'?>
                <priceRequest xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
                    <appId>PC</appId>
                    <appVersion>3.0</appVersion>
                    <priceCheck>
                        <rateId>rate2</rateId>
                        <sender>
                            <country>GR</country>
                            <town>THESSALONIKI CENTER</town>
                            <postcode>546 29</postcode>
                        </sender>
                        <delivery>
                            <country>IT</country>
                            <town>Milano</town>
                            <postcode>20138</postcode>
                        </delivery>
                        <collectionDateTime>2017-10-31T20:12:00</collectionDateTime>
                        <product>
                            <id>15N</id>
                            <division>G</division>
                            <type>N</type>
                        </product>
                        <currency>EUR</currency>
                        <priceBreakDown>true</priceBreakDown>
                        <consignmentDetails>
                            <totalWeight>1.25</totalWeight>
                            <totalVolume>0.1</totalVolume>
                            <totalNumberOfPieces>1</totalNumberOfPieces>
                        </consignmentDetails>
						<pieceLine>
							<numberOfPieces>1</numberOfPieces>
							<pieceMeasurements>
								<length>1</length>
								<width>2</width>
								<height>3</height>
								<weight>1.25</weight>
							</pieceMeasurements>
							<pallet>1</pallet>
						</pieceLine>
                        
                    </priceCheck>
                </priceRequest>
";

    $username = "YOUR_USERNAME";
    $password = "YOUR_PASSWORD";
    $host = "https://express.tnt.com/expressconnect/pricing/getprice";

    curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);

    $process = curl_init($host);
    curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
    curl_setopt($process, CURLOPT_HEADER, 1);
    curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($process, CURLOPT_TIMEOUT, 30);
    curl_setopt($process, CURLOPT_POST, 1);
    curl_setopt($process, CURLOPT_POSTFIELDS, $Xml);
    curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
    $return = curl_exec($process);
    curl_close($process);


    if ( curl_errno($process) ) {
        $result = 'ERROR -> ' . curl_errno($process) . ': ' . curl_error($ch);
    } else {
        $returnCode = (int)curl_getinfo($process, CURLINFO_HTTP_CODE);
        switch($returnCode){
            case 200:
                break;
            default:
                $result = 'HTTP ERROR -> ' . $returnCode;
                break;
        }
    }

    echo $return;
    

Re: How when a customer order a product to be automatically charged?

Posted: Thu Jun 14, 2018 4:16 pm
by georgeGB
xristos88 wrote:
Mon Apr 23, 2018 3:23 pm
Hello,
I want to ask where I can import xml code so that when a customer order a product to be automatically charged, depending on the country and the pounds of the order.
I contacted the TNT courier where they gave me the corresponding code.
1. Where should I enter the code?
2. How do you communicate with the purchase form so that the <delivery>, <product>, <currency>, ... and the rest fields are automatically taken.
The username and password I have received from the TNT courier.
My site http://www.komboloiart.gr
Thank you!!

Xml code from TNT (more):

Code: Select all

<?php

    $Xml = "<?xml version='1.0' encoding='UTF-8'?>
                <priceRequest xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
                    <appId>PC</appId>
                    <appVersion>3.0</appVersion>
                    <priceCheck>
                        <rateId>rate2</rateId>
                        <sender>
                            <country>GR</country>
                            <town>THESSALONIKI CENTER</town>
                            <postcode>546 29</postcode>
                        </sender>
                        <delivery>
                            <country>IT</country>
                            <town>Milano</town>
                            <postcode>20138</postcode>
                        </delivery>
                        <collectionDateTime>2017-10-31T20:12:00</collectionDateTime>
                        <product>
                            <id>15N</id>
                            <division>G</division>
                            <type>N</type>
                        </product>
                        <currency>EUR</currency>
                        <priceBreakDown>true</priceBreakDown>
                        <consignmentDetails>
                            <totalWeight>1.25</totalWeight>
                            <totalVolume>0.1</totalVolume>
                            <totalNumberOfPieces>1</totalNumberOfPieces>
                        </consignmentDetails>
						<pieceLine>
							<numberOfPieces>1</numberOfPieces>
							<pieceMeasurements>
								<length>1</length>
								<width>2</width>
								<height>3</height>
								<weight>1.25</weight>
							</pieceMeasurements>
							<pallet>1</pallet>
						</pieceLine>
                        
                    </priceCheck>
                </priceRequest>
";

    $username = "YOUR_USERNAME";
    $password = "YOUR_PASSWORD";
    $host = "https://express.tnt.com/expressconnect/pricing/getprice";

    curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);

    $process = curl_init($host);
    curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
    curl_setopt($process, CURLOPT_HEADER, 1);
    curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($process, CURLOPT_TIMEOUT, 30);
    curl_setopt($process, CURLOPT_POST, 1);
    curl_setopt($process, CURLOPT_POSTFIELDS, $Xml);
    curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
    $return = curl_exec($process);
    curl_close($process);


    if ( curl_errno($process) ) {
        $result = 'ERROR -> ' . curl_errno($process) . ': ' . curl_error($ch);
    } else {
        $returnCode = (int)curl_getinfo($process, CURLINFO_HTTP_CODE);
        switch($returnCode){
            case 200:
                break;
            default:
                $result = 'HTTP ERROR -> ' . $returnCode;
                break;
        }
    }

    echo $return;
    
Hello

As for the code, can't tell you. But here's the solution for the <currency> automation suggested here on OpenCart forum by the user (victorj). Perhaps, you should try setting the currencies for each country.

George
GB