Jump to content

closing out an array? I think..


aebstract

Recommended Posts

Parse error: parse error, unexpected '}', expecting ')' in /home/virtual/site130/fst/var/www/html/Rate.php5 on line 45

 

 

Here is all the code:

<?php

// Copyright 2007, FedEx Corporation. All rights reserved.
// Version 2.0.0

chdir('..'); 

require_once('library/fedex-common.php5');

$newline = "<br />";
ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient('http://www.berryequipment.net/wsdl/RateService_v2.wsdl', array('trace' => 1)); // replace with valid path to WSDL

$request['WebAuthenticationDetail'] = array('UserCredential' =>
                                      array('Key' => 'YXSO2j7gNqcJsOSs', 'Password' => 'zcuAEs7HNaI2j2Wnlaa1Nw3G2')); // Replace 'XXX' and 'YYY' with FedEx provided credentials 
$request['ClientDetail'] = array('AccountNumber' => '510087380', 'MeterNumber' => '1214194');// Replace 'XXX' with your account and meter number
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v2 using PHP ***');
$request['Version'] = array('ServiceId' => 'crs', 'Major' => '2', 'Intermediate' => '0', Minor => '0');
$request['Origin'] = array('StreetLines' => array('6736 Cleveland Hwy'), // Origin details
                                          'City' => 'Clermont',
                                          'StateOrProvinceCode' => 'GA',
                                          'PostalCode' => '30527',
                                          'CountryCode' => 'US');
$request['Destination'] = array('StreetLines' => array('$street'), // Destination details
                                               'City' => '$city',
                                               'StateOrProvinceCode' => '$state',
                                               'PostalCode' => '$zip',
                                               'CountryCode' => 'US');
$request['Payment'] = array('PaymentType' => 'THIRD_PARTY'); // valid codes RECIPIENT, SENDER and THIRD_PARTY
$request['DropoffType'] = 'REGULAR_PICKUP'; // valid codes BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER and STATION
$request['ServiceType'] = 'FEDEX_GROUND'; // valid codes STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['PackagingType'] = 'YOUR_PACKAGING'; // valid codes FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['ShipDate'] = date('Y-m-d');
$request['RateRequestTypes'] = 'ACCOUNT'; // valid codes ACCOUNT, LIST
       
$PassRateRequestPackageSummary = true;

if ($PassRateRequestPackageSummary)
{
   // Passing multi piece shipment rate request (by setting PieceCount > 1)
   $request['RateRequestPackageSummary'] = array('TotalWeight' => array('Value' => 22.0, 'Units' => 'LB'), // valid codes LB and KG
                                                                'TotalInsuredValue' => array('Amount' => $total, 'Currency' => 'USD'),
                                                                'PieceCount' => $quan,
}
else
{
    // Passing single piece shipment rate request 
    $request['PackageCount'] = 1; // currently only one occurrence of RequestedPackage is supported
    $request['Packages'] = array(0 => array('Weight' => array('Value' => 22.0, 'Units' => 'LB'), // valid code LB and KG
                                                           'InsuredValue' => array('Amount' => $total, 'Currency' => 'USD'),
}

try 
{
    $response = $client ->__soapCall("getRate", array('parameters' => $request));
        
    if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
    {
        printRequestResponse($client);
    }
    else
    {
        echo 'Error in processing transaction.'. $newline. $newline; 
        foreach ($response -> Notifications as $notification)
        {           
            if(is_array($response -> Notifications))
            {              
               echo $notification -> Severity;
               echo ': ';           
               echo $notification -> Message . $newline;
            }
            else
            {
                echo $notification . $newline;
            }
        } 
    } 
    
    writeToLog($client);    // Write to log file   

} catch (SoapFault $exception) {
   printFault($exception, $client);        
}

?>

 

This part is where the line is and I'm sure the problem occurs:

if ($PassRateRequestPackageSummary)
{
   // Passing multi piece shipment rate request (by setting PieceCount > 1)
   $request['RateRequestPackageSummary'] = array('TotalWeight' => array('Value' => 22.0, 'Units' => 'LB'), // valid codes LB and KG
                                                                'TotalInsuredValue' => array('Amount' => $total, 'Currency' => 'USD'),
                                                                'PieceCount' => $quan,
}
else
{
    // Passing single piece shipment rate request 
    $request['PackageCount'] = 1; // currently only one occurrence of RequestedPackage is supported
    $request['Packages'] = array(0 => array('Weight' => array('Value' => 22.0, 'Units' => 'LB'), // valid code LB and KG
                                                           'InsuredValue' => array('Amount' => $total, 'Currency' => 'USD'),
}

try 
{

 

This last bit of code starts on line 39

Link to comment
Share on other sites

try this

if ($PassRateRequestPackageSummary)
{
   // Passing multi piece shipment rate request (by setting PieceCount > 1)
   $request['RateRequestPackageSummary'] = array('TotalWeight' => array('Value' => 22.0, 'Units' => 'LB'), // valid codes LB and KG
                                                                'TotalInsuredValue' => array('Amount' => $total, 'Currency' => 'USD'),
                                                                'PieceCount' => $quan)
}
else
{
    // Passing single piece shipment rate request 
    $request['PackageCount'] = 1; // currently only one occurrence of RequestedPackage is supported
    $request['Packages'] = array(0 => array('Weight' => array('Value' => 22.0, 'Units' => 'LB'), // valid code LB and KG
                                                           'InsuredValue' => array('Amount' => $total, 'Currency' => 'USD'),
}

try 
{

Link to comment
Share on other sites

Yup, didn't close your array:

 

  // Passing multi piece shipment rate request (by setting PieceCount > 1)

  $request['RateRequestPackageSummary'] = array('TotalWeight' => array('Value' => 22.0, 'Units' => 'LB'), // valid codes LB and KG

                                                                'TotalInsuredValue' => array('Amount' => $total, 'Currency' => 'USD'),

                                                                'PieceCount' => $quan,

needs a ");" after it, before close brace

Link to comment
Share on other sites

Okay, now when I get those closed (correct me if I did it wrong) I'm getting an error about the next line:

 

}
else
{
    // Passing single piece shipment rate request 
    $request['PackageCount'] = 1; // currently only one occurrence of RequestedPackage is supported
    $request['Packages'] = array(0 => array('Weight' => array('Value' => 22.0, 'Units' => 'LB'), // valid code LB and KG
                                                           'InsuredValue' => array('Amount' => $total, 'Currency' => 'USD');
}

 

Parse error: parse error, unexpected '}', expecting ')' in /home/virtual/site130/fst/var/www/html/Rate.php5 on line 52

 

Line 52 being the one with the }

If I remove the ; on 51, it gives me the error of expecting ; on 51 >.<

Link to comment
Share on other sites

You need to make sure all your parenthesis balance:

<?php
{
    // Passing single piece shipment rate request 
    $request['PackageCount'] = 1; // currently only one occurrence of RequestedPackage is supported
    $request['Packages'] = array(array('Weight' => array('Value' => 22.0, 'Units' => 'LB'), // valid code LB and KG
                                                    'InsuredValue' => array('Amount' => $total, 'Currency' => 'USD')));
}?>

 

A print_r of the $request array shows:

Array
(
    [PackageCount] => 1
    [Packages] => Array
        (
            [0] => Array
                (
                    [Weight] => Array
                        (
                            [Value] => 22
                            [units] => LB
                        )

                    [insuredValue] => Array
                        (
                            [Amount] =>
                            [Currency] => USD
                        )

                )

        )

)

 

 

Ken

Link to comment
Share on other sites

If you format your arrays in a more readable manner, it's much easier to see your errors:

 

if ($PassRateRequestPackageSummary) {
   $request['RateRequestPackageSummary'] = array(
	'TotalWeight' => array(
		'Value' => 22.0, 
		'Units' => 'LB'
	),
        'TotalInsuredValue' => array(
		'Amount' => $total, 
		'Currency' => 'USD'
	),
        'PieceCount' => $quan  // there was an error here
);	
} else {
    $request['PackageCount'] = 1;
    $request['Packages'] = array(
	0 => array(
		'Weight' => array(
			'Value' => 22.0, 
			'Units' => 'LB'
		),
            'InsuredValue' => array(
			'Amount' => $total, 
			'Currency' => 'USD' // error here as well
		)
	)
);
}

Link to comment
Share on other sites

I agree with formatting it better, it was code from fedex developers ;( With that said, I'm kinda new to arrays and trying to work through their code but it's rather difficult for me.

 

Parse error: parse error, unexpected '{' in /home/virtual/site130/fst/var/www/html/Rate.php5 on line 67

 

After changing what you said, hitman. I am left with this error, line 67 beginning below

try {
    $response = $client ->__soapCall("getRate", array('parameters' => $request));
        
    if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
    {
        printRequestResponse($client);
    }
    else
    {
        echo 'Error in processing transaction.'. $newline. $newline; 
        foreach ($response -> Notifications as $notification)
        {           
            if(is_array($response -> Notifications))
            {              
               echo $notification -> Severity;
               echo ': ';           
               echo $notification -> Message . $newline;
            }
            else
            {
                echo $notification . $newline;
            }
        } 
    } 
    
    writeToLog($client);    // Write to log file   

} catch (SoapFault $exception) {
   printFault($exception, $client);        
}

?>

Link to comment
Share on other sites

I've been trying.. many many times. Constantly throughout the day. I've gotten more help in an hour here than I have in several days of trying to contact them. I got a response back from a developer that said: "Are you rating dry ice?" I would much rather just get help here and get the code fixed. I understand there is a "3rd party" section to the forums, which hardly gets used. I looked and if I was to post this there, I would probably get a response once a day, meaning the problems would get solved in a week or two. Much better responses and response times here. If im not welcome here, okay but I hope that isn't the truth as I want really need to get this code working.

Link to comment
Share on other sites

The entire script is posted at the top, here it is with the most recent updates:

 

<?php

// Copyright 2007, FedEx Corporation. All rights reserved.
// Version 2.0.0

chdir('..'); 

require_once('library/fedex-common.php5');

$newline = "<br />";
ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient('http://www.berryequipment.net/wsdl/RateService_v2.wsdl', array('trace' => 1)); // replace with valid path to WSDL

$request['WebAuthenticationDetail'] = array('UserCredential' =>
                                      array('Key' => 'YXSO2j7gNqcJsOSs', 'Password' => 'zcuAEs7HNaI2j2Wnlaa1Nw3G2')); // Replace 'XXX' and 'YYY' with FedEx provided credentials 
$request['ClientDetail'] = array('AccountNumber' => '510087380', 'MeterNumber' => '1214194');// Replace 'XXX' with your account and meter number
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v2 using PHP ***');
$request['Version'] = array('ServiceId' => 'crs', 'Major' => '2', 'Intermediate' => '0', Minor => '0');
$request['Origin'] = array('StreetLines' => array('6736 Cleveland Hwy'), // Origin details
                                          'City' => 'Clermont',
                                          'StateOrProvinceCode' => 'GA',
                                          'PostalCode' => '30527',
                                          'CountryCode' => 'US');
$request['Destination'] = array('StreetLines' => array('$street'), // Destination details
                                               'City' => '$city',
                                               'StateOrProvinceCode' => '$state',
                                               'PostalCode' => '$zip',
                                               'CountryCode' => 'US');
$request['Payment'] = array('PaymentType' => 'THIRD_PARTY'); // valid codes RECIPIENT, SENDER and THIRD_PARTY
$request['DropoffType'] = 'REGULAR_PICKUP'; // valid codes BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER and STATION
$request['ServiceType'] = 'FEDEX_GROUND'; // valid codes STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['PackagingType'] = 'YOUR_PACKAGING'; // valid codes FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['ShipDate'] = date('Y-m-d');
$request['RateRequestTypes'] = 'ACCOUNT'; // valid codes ACCOUNT, LIST
       
$PassRateRequestPackageSummary = true;

if ($PassRateRequestPackageSummary) {
   $request['RateRequestPackageSummary'] = array(
	'TotalWeight' => array(
		'Value' => 22.0, 
		'Units' => 'LB'
	),
        'TotalInsuredValue' => array(
		'Amount' => $total, 
		'Currency' => 'USD'
	),
        'PieceCount' => $quan  // there was an error here
);	
} else {
    $request['PackageCount'] = 1;
    $request['Packages'] = array(
	0 => array(
		'Weight' => array(
			'Value' => 22.0, 
			'Units' => 'LB'
		),
            'InsuredValue' => array(
			'Amount' => $total, 
			'Currency' => 'USD' // error here as well
		)
	)
);
}

try {
    $response = $client ->__soapCall("getRate", array('parameters' => $request));
        
    if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
    {
        printRequestResponse($client);
    }
    else
    {
        echo 'Error in processing transaction.'. $newline. $newline; 
        foreach ($response -> Notifications as $notification)
        {           
            if(is_array($response -> Notifications))
            {              
               echo $notification -> Severity;
               echo ': ';           
               echo $notification -> Message . $newline;
            }
            else
            {
                echo $notification . $newline;
            }
        } 
    } 
    
    writeToLog($client);    // Write to log file   

} catch (SoapFault $exception) {
   printFault($exception, $client);        
}

?>

Link to comment
Share on other sites

Alright, I think this should do the trick. And please, from now on, when writing code, keep it clean so it is easier to debug.

<?php 
// Copyright 2007, FedEx Corporation. All rights reserved.
// Version 2.0.0
chdir('..');

require_once('library/fedex-common.php5');

$newline = "<br />";
ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient('http://www.berryequipment.net/wsdl/RateService_v2.wsdl', array('trace' => 1)); // replace with valid path to WSDL

$request['WebAuthenticationDetail'] = array('UserCredential' =>
    array('Key' => 'YXSO2j7gNqcJsOSs', 'Password' => 'zcuAEs7HNaI2j2Wnlaa1Nw3G2')); // Replace 'XXX' and 'YYY' with FedEx provided credentials 
$request['ClientDetail'] = array('AccountNumber' => '510087380', 'MeterNumber' => '1214194'); // Replace 'XXX' with your account and meter number
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v2 using PHP ***');
$request['Version'] = array('ServiceId' => 'crs', 'Major' => '2', 'Intermediate' => '0', Minor => '0');
$request['Origin'] = array('StreetLines' => array('6736 Cleveland Hwy'), // Origin details
    'City' => 'Clermont',
    'StateOrProvinceCode' => 'GA',
    'PostalCode' => '30527',
    'CountryCode' => 'US');
$request['Destination'] = array('StreetLines' => array('$street'), // Destination details
    'City' => '$city',
    'StateOrProvinceCode' => '$state',
    'PostalCode' => '$zip',
    'CountryCode' => 'US');
$request['Payment'] = array('PaymentType' => 'THIRD_PARTY'); // valid codes RECIPIENT, SENDER and THIRD_PARTY
$request['DropoffType'] = 'REGULAR_PICKUP'; // valid codes BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER and STATION
$request['ServiceType'] = 'FEDEX_GROUND'; // valid codes STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['PackagingType'] = 'YOUR_PACKAGING'; // valid codes FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['ShipDate'] = date('Y-m-d');
$request['RateRequestTypes'] = 'ACCOUNT'; // valid codes ACCOUNT, LIST
$PassRateRequestPackageSummary = true;

if ($PassRateRequestPackageSummary) {
    // Passing multi piece shipment rate request (by setting PieceCount > 1)
    $request['RateRequestPackageSummary'] = array('TotalWeight' => array('Value' => 22.0, 'Units' => 'LB'), // valid codes LB and KG
        'TotalInsuredValue' => array('Amount' => $total, 'Currency' => 'USD'),
        'PieceCount' => $quan);
} else {
    // Passing single piece shipment rate request
    $request['PackageCount'] = 1; // currently only one occurrence of RequestedPackage is supported
    $request['Packages'] = array(0 => array('Weight' => array('Value' => 22.0, 'Units' => 'LB'), // valid code LB and KG
            'InsuredValue' => array('Amount' => $total, 'Currency' => 'USD')));
} 

try {
    $response = $client->__soapCall("getRate", array('parameters' => $request));
    if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
        printRequestResponse($client);
    } else {
        echo 'Error in processing transaction.' . $newline . $newline;
        foreach ($response->Notifications as $notification) {
            if (is_array($response->Notifications)) {
                echo $notification->Severity;
                echo ': ';
                echo $notification->Message . $newline;
            } else {
                echo $notification . $newline;
            } 
        } 
    } 

    writeToLog($client); // Write to log file   
} 
catch (SoapFault $exception) {
    printFault($exception, $client);
} 

?>

Link to comment
Share on other sites

Duclet, in response to your code:

Parse error: parse error, unexpected '{' in /home/virtual/site130/fst/var/www/html/Rate.php5 on line 48

 

Also, I had mentioned before that it was the fedex rate script to get a price on shipping for items that we are selling. This is why I'm stuck as well, I'm not too good with arrays and it's hard to go through this code.

 

 

*edit* Just talked to my host and I have php 4.2 enabled. Is there a way around the file being php5? Can I remove the 5 from the extension? Am I going to HAVE to find a way to get an upgrade for this to work?

Link to comment
Share on other sites

To determine whether your server is using PHP4 or PHP5 create, upload and run the script:

<?php phpinfo() ?>

 

If the host is running PHP4, you will not be able to use this script. Go back to FedEX and get get one that runs with PHP4.

 

PHP 4.2 is very old. Either switch hosts or ask your current host to upgrade to PHP5, since PHP4 is not being supported anymore.

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.