views:

1140

answers:

3

Hi Everyone, I downloaded the sample code to request a rate from fedex's website... i placed the WSDL file in the proper location, I have my acct number, password, meter number, and key. When I run the script I get this error:

Error in processing transaction.
ERROR
prof
1000
Authentication Failed

The script they give is as follows, and yes i do actually replace the XXX and YYY everywhere it says.:

<?php

// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 7.0.0

require_once('fedex-common.php5');

$newline = "<br />";
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "RateService_v7.wsdl";

ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information

$request['WebAuthenticationDetail'] = array('UserCredential' =>
                                      array('Key' => 'XXX', 'Password' => 'YYY')); // Replace 'XXX' and 'YYY' with FedEx provided credentials 
$request['ClientDetail'] = array('AccountNumber' => 'XXX', 'MeterNumber' => 'YYY');// Replace 'XXX' with your account and meter number
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v7 using PHP ***');
$request['Version'] = array('ServiceId' => 'crs', 'Major' => '7', 'Intermediate' => '0', 'Minor' => '0');
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
$request['RequestedShipment']['ServiceType'] = 'FEDEX_GROUND'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING'; // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['RequestedShipment']['Shipper'] = array('Address' => array(
                                          'StreetLines' => array('10 Fed Ex Pkwy'), // Origin details
                                          'City' => 'Memphis',
                                          'StateOrProvinceCode' => 'TN',
                                          'PostalCode' => '38115',
                                          'CountryCode' => 'US'));
$request['RequestedShipment']['Recipient'] = array('Address' => array (
                                               'StreetLines' => array('13450 Farmcrest Ct'), // Destination details
                                               'City' => 'Herndon',
                                               'StateOrProvinceCode' => 'VA',
                                               'PostalCode' => '20171',
                                               'CountryCode' => 'US'));
$request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER',
                                                        'Payor' => array('AccountNumber' => 'XXX', // Replace 'XXX' with payor's account number
                                                                     'CountryCode' => 'US'));
$request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT'; 
$request['RequestedShipment']['RateRequestTypes'] = 'LIST'; 
$request['RequestedShipment']['PackageCount'] = '2';
$request['RequestedShipment']['PackageDetailSpecified'] = true;
$request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';  //  Or PACKAGE_SUMMARY
$request['RequestedShipment']['RequestedPackageLineItems'] = array('0' => array('Weight' => array('Value' => 2.0,
                                                                                    'Units' => 'LB'),
                                                                                    'Dimensions' => array('Length' => 10,
                                                                                        'Width' => 10,
                                                                                        'Height' => 3,
                                                                                        'Units' => 'IN')),
                                                                   '1' => array('Weight' => array('Value' => 5.0,
                                                                                    'Units' => 'LB'),
                                                                                    'Dimensions' => array('Length' => 20,
                                                                                        'Width' => 20,
                                                                                        'Height' => 10,
                                                                                        'Units' => 'IN')));
try 
{
    $response = $client ->getRates($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);        
}

?>

I am not quite sure why it isn't working, i've read about using a proxy, but I am not quite sure how i would use it in this case? Isn't the point of using SOAP and WSDL to avoid using CURL, Direct Connect type stuff?

+1  A: 

If you use SoapUI ( http://www.soapui.org/ ) to contact the WSDL, what is the response you get?

(SoapUI enables you to test SOAP/Wsdl's without programming, so you can check if the calls are correct, if they are, then the problem is in your code.)

Jimmy Shelter
yes i did... i think its properly communicating with their server since if i comment out those lines completely it says I am missing those lines? perhaps that is a soap wsdl thing though
Parris
I edited my answer with a new idea.
Jimmy Shelter
Actually, I get the same issue... So I suppose its not the code it has something to do with my account info maybe since it says auth failed. I would assume if communication failed it would say that instead... (i guess you never know with these things)
Parris
Apparently there is some propagation period with FedEx passwords and test accounts. I obtained a production key (had to registered for my own fedex account as well), and then after some searching I found I had to change the gateway to: https://gateway.fedex.com/web-services A little confusing, as none of that is documented. In any case it works now. Now I just need to parse this nasty XML response!
Parris
also if anyone is getting 803 meter number incorrect use this alternative gateway mentioned above... that fixed my issue... stackoverflow dropped the https:// when converting it to a link
Parris
A: 

Parris,

I have changed the getway path, and now, top 2 lines of ShipService_v7.wsdl is

[code]

lt(<) ques(?) xml version="1.0" encoding="UTF-8"?>

lt(<) definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://gateway.fedex.com/web-services/ship/v7" xmlns:s1="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://gateway.fedex.com/web-services/ship/v7" name="ShipServiceDefinitions">

[/code]

Still getting the same error, 1000 Auth Failed. Also, i have replaced all the fields in request with proper/valid data.

do i need to change any thing else?

please reply.

paresh
A: 

@Paresh, you dont have to replace xml namespace. I changed nothing in the body of wsdl file, just give the full path [ dirname(FILE)."/someotherpath/RateService_v8.wsdl"] and apply correctly your key, meter and account numbers. please tell me if it helps

P.M