I am trying to create a test pickup request using Estes web services. This particular service requires Basic Authentication using my login credentials. However, I can't seem to figure out how to perform the authentication using PHP and SoapClient. I keep getting the following error:
PHP Fatal error: Uncaught SoapFault exception: [soapenv:Client] [ISS.0088.9164] Access to WSDescriptor estesrtpickup.base.ws.provider.soapws:pickupRequestSSL denied.
My last attempt I tried to pass the credentials into WSDL address, but to no avail. Like so:
$client_pickup = new SoapClient('https://USERNAME:PASSWORD#apitest.estes-express.com/tools/pickup/request/v1.0?wsdl');
Here is my current block of PHP code for the Pickup Webservice:
public static function estesFreightPickupRequest($option) {
self::$ShipToCity = preg_replace("/[^a-zA-Z0-9\s]/", "", $option->ShipToCity);
self::$ShipToStateProvinceCode = preg_replace("/[^a-zA-Z0-9\s]/", "", $option->ShipToStateProvinceCode);
self::$ShipToPostalCode = (string)$option->ShipToPostalCode;
self::$ShipToPostalCode = substr(trim(self::$ShipToPostalCode), 0, 5);
self::$ShipToPostalCode = str_pad(self::$ShipToPostalCode, 5, "0", STR_PAD_LEFT);
self::$ShipToAddressLine = preg_replace("/[^a-zA-Z0-9\s]/", "", $option->ShipToAddressLine);
$Weight = $option->weight;
$d = strtotime("tomorrow");
$request_date = date("Y-m-d", $d);
$path_to_wsdl_pickup = "https://apitest.estes-express.com/tools/pickup/request/v1.0?wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client_pickup = new SoapClient('https://USERNAME:PASSWORD#apitest.estes-express.com/tools/pickup/request/v1.0?wsdl');
ini_set("soap.wsdl_cache_enabled", "0");
$header_pickup = new SoapHeader('http://www.estes-express.com/tools/pickup');
$client_pickup->__setSoapHeaders($header_pickup);
//Enter the body data for WSDL
$request_pickup = array(
'requestNumber' => date("Y-m-d"),
'shipper' => array(
'shipperName' => 'COMPANY NAME',
'accountCode' => 'ACCOUNT CODE',
'shipperAddress' => array(
'addressInfo' => array(
'addressLine1' => '1620 TEST CT',
'city' => 'SOMETOWN',
'stateProvince' => 'MO',
'postalCode' => '65222',
'countryAbbrev' => 'US'
)
)
),
'requestAction' => 'LL',
'pickupDate'=> date("Y-m-d"),
'pickupStartTime' => '1200',
'pickupEndTime' => '1500',
'totalPieces' => '1',
'totalWeight' => '100',
'totalHandlingUnits' => '1',
'whoRequested' => 'S'
);
try {
$response_pickup = $client_pickup->createPickupRequestWS($request_pickup);
//Error log the request and response
error_log($client->__getLastRequest());
error_log($client->__getLastResponse());
//$rateReply = $response->quoteInfo->quote->pricing->totalPrice;
//Get the response data
$result_array = array();
$result_array['totalPrice'] = $estes_total_rate_amount;
return $result_array;
} catch (SoapFault $exception) {
error_log('ERROR LOG::' . $exception, $client);
}
}
Related
Hi Stackoverflow community,
I am attempting to implement the "convertPaymentMethodToToken" method from USAePay soap api documentations. For the function to work, it is required to fetch the customer number from the UsaEpay acct, and it generates a Method ID through a "getCustomer" request, that will be used for the conversion. However, the implementation works only for a single customer and fails when I try to process multiple customers at once. The error message I receive is: "An error occurred while fetching details of customer 'customer1': 40030: Customer Not Found......".
I have a large customer database of over 20,000 customers, and my goal is to convert each of their payment methods to tokens efficiently, without having to perform individual conversions for each customer. The USAePay documentation only provides information on how to implement the feature for a single customer.
here is my code by getting Method ID for a single customer
<?php
$wsdl = "https://secure.usaepay.com/soap/gate/INBGTWZC/usaepay.wsdl";
$sourceKey = "your soruce key";
$pin = "1234";
function getClient($wsdl) {
return new SoapClient($wsdl, array(
'trace' => 1,
'exceptions' => 1,
'stream_context' => stream_context_create(
array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)
)
));
}
function getToken($sourceKey, $pin) {
$seed = time() . rand();
return array(
'SourceKey' => $sourceKey,
'PinHash' => array(
'Type' => 'sha1',
'Seed' => $seed,
'HashValue' => sha1($sourceKey . $seed . $pin)
),
'ClientIP' => $_SERVER['REMOTE_ADDR']
);
}
$client = getClient($wsdl);
$token = getToken($sourceKey, $pin);
try {
$custnum='customer number';
print_r($client->getCustomer($token,$custnum));
} catch (Exception $e) {
// Code to handle the exception
echo "An error occurred: " . $e->getMessage();
}
?>
and here the successful response I get back (with the Method ID included)
Successful response.
here Is the code I'm trying it to do with multiple customers
<?php
$wsdl = "https://sandbox.usaepay.com/soap/gate/43R1QPKU/usaepay.wsdl";
$sourceKey = "your api key";
$pin = "1234";
function getClient($wsdl) {
return new SoapClient($wsdl, array(
'trace' => 1,
'exceptions' => 1,
'stream_context' => stream_context_create(
array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)
)
));
}
function getToken($sourceKey, $pin) {
$seed = time() . rand();
return array(
'SourceKey' => $sourceKey,
'PinHash' => array(
'Type' => 'sha1',
'Seed' => $seed,
'HashValue' => sha1($sourceKey . $seed . $pin)
),
'ClientIP' => $_SERVER['REMOTE_ADDR']
);
}
$client = getClient($wsdl);
$token = getToken($sourceKey, $pin);
$custnums = array();
for ($i = 1; $i <= 3; $i++) {
$custnums[] = 'customer' . $i;
}
$methodIDs = array();
foreach ($custnums as $custnum) {
try {
$result = $client->getCustomer($token, $custnum);
$methodID = $result[0]->MethodID;
$methodIDs[] = $methodID;
error_log("Method ID for customer $custnum: $methodID");
} catch (Exception $e) {
echo " An error occurred: " . $e->getMessage();
}
}
?>
I've already been working on it all day,
Can anyone help me with this?
Thanks in advance
I have been attempting to get this to work for a while. I am hoping someone familiar with it happens to run across the question and can explain WHY this isnt working and what is wrong with the code. Estes has been useless in helping thus far. They have provided me a bunch of information but none of it works.
The code below is returning this error
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR:
Encoding: object has no 'requestID' property in
/home/xxxxxxxxxx/public_html/inc/estes/estesapi.php:41 Stack trace: #0
/home/xxxxxxxxxx/public_html/inc/estes/estesapi.php(41):
SoapClient->__call('getQuote', Array) #1 {main} thrown in
/home/xxxxxxxxxx/public_html/inc/estes/estesapi.php on line 41
$client = new SoapClient("https://www.estes-express.com/tools/rating/ratequote/v3.0/services/RateQuoteService?wsdl");
$request_object = array(
"header"=>array(
"auth"=>array(
"user"=>"xxxxxxxxx",
"password"=>"xxxx",
)
),
"rateRequest"=>array(
"requestID"=>"abc",
"account"=>"############",
"originPoint"=>array(
"countryCode"=>"US",
"postalCode"=>"28366",
"city"=>"Newton Grove",
"stateProvince"=>"NC",
),
"destinationPoint"=>array(
"countryCode"=>"US",
"postalCode"=>"28334",
),
"payor"=> "S",
"terms"=> "P",
"stackable"=> "N",
"baseCommodities"=>array(
"commodity"=>array(
"class"=>"50",
"weight"=>"1200",
)
)
)
);
$result = $client->getQuote($request_object);
var_dump($result);
print_r($result);
I cant figure out why RequestID isnt being passed into the soap request.
This is our Estes Soap call. See if you see anything in it that helps:
// define transaction arrays
$url = "http://www.estes-express.com/rating/ratequote/services/RateQuoteService?wsdl";
$username = 'xxxxxxxx';
$password = 'xxxxxxxx';
// setting a connection timeout of five seconds
$client = new SoapClient($url, array("trace" => true,
"exceptions" => true,
"connection_timeout" => 5,
"features" => SOAP_WAIT_ONE_WAY_CALLS,
"cache_wsdl" => WSDL_CACHE_NONE));
$old = ini_get('default_socket_timeout');
ini_set('default_socket_timeout', 5);
//Prepare SoapHeader parameters
$cred = array(
'user' => $username,
'password' => $password
);
$header = new SoapHeader('http://ws.estesexpress.com/ratequote', 'auth', $cred);
$client->__setSoapHeaders($header);
$params = array(
"requestID" => "xxxxxxxx",
"account" => "xxxxxxxx",
"originPoint" => array('countryCode' => 'US', 'postalCode' => $fromzip),
"destinationPoint" => array('countryCode' => 'US', 'postalCode' => $shipzip),
"payor" => 'T',
"terms" => 'PPD',
"stackable" => 'N',
"baseCommodities" => array('commodity' => $comArray ),
"accessorials" => array('accessorialCode' => $accArray)
);
// remove accessorials entry if no accessorial codes
if(count($accArray) == 0){
$params = array_slice($params, 0, 8); // remove accesorials entry
}
// call Estes API and catch any errors
try {
$reply = $client->getQuote($params);
}
catch(SoapFault $e){
// handle issues returned by the web service
//echo "Estes soap fault<br>" . $e . "<br>";
$edit_error_msg = "Estes quote API timed out or failed to return a quote";
return "0.00";
}
catch(Exception $e){
// handle PHP issues with the request
//echo "PHP soap exception<br>" . $e . "<br>";
$edit_error_msg = "Estes quote API timed out or failed to return a quote";
return "0.00";
}
unset($client);
ini_set('default_socket_timeout', $old);
// print_r($reply);
I have written a script that should connect to a secure web service (ws-security). However, when running the script, I'm getting this error:
Error: SOAP-ERROR: Encoding: object has no 'createLead' property
I'm using this code:
<?php
$wsdl = "http://localhost/test/wsdl-src/CRMLeadService.wsdl";
$momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0/";
echo "Post to URL: {$momurl}\n";
$username = '817221';
$password = '1234';
//Perform Request
$client = new SoapClient ($wsdl, array('loacation' => $momurl));
$security = array('UsernameToken' => array(
'Username'=>"$username",
'Password'=>"$password"
));
$header = new SoapHeader('wsse','Security',$security, false);
$client->__setSoapHeaders($header);
print_r($client);
echo "<br />";
print_r( $client->__getFunctions() ); //Available Function
$params = array(
'LeadSourceId' => '23627e70-a29e-e211-b8a8-005056b81ebe',
'AffiliateLeadReference' => '5465546hdfh5sggd52',
'Title' => '852800018',
'Initials' => 'MD',
'PreferredName' => 'Marius',
'FirstName' => 'Marius',
'LastName' => 'Drew',
'PreferredCorrespondenceLanguage' => '852800001',
'PreferredCommunicationMethod' => '852800000',
'Campaign' => '',
'HomePhoneNumber' => '0723621762',
'BusinessPhoneNumber' => '0723621762',
'MobilePhoneNumber' => '0723621762',
'EmailAddress' => 'mdrew#gmail.com',
'Notes' => 'IMU',
'ProductCategories' => array('Code' => 'd000083d-229c-e211-b8a8-005056b81ebe')
);
print_r($params);
try {
echo $result = $client->__soapCall('createLead',array('parameters'=>$params));
} catch (Exception $e) {
$msgs = $e->getMessage();
echo "Error: $msgs";
}
?>
The WSDL and XSD files can be downloaded here:
http://sdrv.ms/16KC8o4
Any help would be appreciated. Thanks!
Why i am getting the following
error
Warning: SoapClient::__doRequest(): Unable to find the wrapper "https"
- did you forget to enable it when you configured PHP
What is my mistake?
My code is following
$config = parse_ini_file('ebay.ini', true);
$site = $config['settings']['site'];
$compatibilityLevel = $config['settings']['compatibilityLevel'];
$dev = $config[$site]['devId'];
$app = $config[$site]['appId'];
$cert = $config[$site]['cert'];
$token = $config[$site]['authToken'];
$location = $config[$site]['gatewaySOAP'];
// Create and configure session
$session = new eBaySession($dev, $app, $cert);
$session->token = $token;
$session->site = 203; // 0 = US;
$session->location = $location;
// Make an AddItem API call and print Listing Fee and ItemID
try {
$client = new eBaySOAP($session);
$PrimaryCategory = array('CategoryID' => 357);
$Item = array('ListingType' => 'Chinese',
'Currency' => 'INR',
'Country' => 'US',
'PaymentMethods' => 'PaymentSeeDescription',
'RegionID' => 0,
'ListingDuration' => 'Days_3',
'Title' => 'The new item',
'Description' => "It's a great new item",
'Location' => "San Jose, CA",
'Quantity' => 1,
'StartPrice' => 24.99,
'PrimaryCategory' => $PrimaryCategory,
);
$params = array('Version' => $compatibilityLevel, 'Item' => $Item);
$results = $client->AddItem($params);
// The $results->Fees['ListingFee'] syntax is a result of SOAP classmapping
print "Listing fee is: " . $results->Fees['ListingFee'] . " <br> \n";
print "Listed Item ID: " . $results->ItemID . " <br> \n";
print "Item was listed for the user associated with the auth token code herer>\n";`enter code here`
} catch (SOAPFault $f) {
print $f; // error handling
}
Thanks in advance
Murali
You have to add (or uncomment it) extension=php_openssl.dll; to your php.ini file.
I need to send a SOAP request to Estes to retrieve rate quotes. I'm having trouble doing this as the other APIs I have worked with either post the XML or use a URL string. This is a bit different for me.
I believe my problem is that I cannot figure out the array that needs to be sent for the request.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rat="http://ws.estesexpress.com/ratequote" xmlns:rat1="http://ws.estesexpress.com/schema/2012/12/ratequote">
<soapenv:Header>
<rat:auth>
<rat:user>XXXXX</rat:user>
<rat:password>XXXX</rat:password>
</rat:auth>
</soapenv:Header>
<soapenv:Body>
<rat1:rateRequest>
<rat1:requestID>XXXXXX</rat1:requestID>
<rat1:account>XXXXXXX</rat1:account>
<rat1:originPoint>
<rat1:countryCode>XX</rat1:countryCode>
<rat1:postalCode>XXXXX</rat1:postalCode>
<rat1:city>XXXXXX</rat1:city>
<rat1:stateProvince>XX</rat1:stateProvince>
</rat1:originPoint>
<rat1:destinationPoint>
<rat1:countryCode>XX</rat1:countryCode>
<rat1:postalCode>XXXXX</rat1:postalCode>
</rat1:destinationPoint>
<rat1:payor>X</rat1:payor>
<rat1:terms>XX</rat1:terms>
<rat1:stackable>X</rat1:stackable>
<rat1:baseCommodities>
<rat1:commodity>
<rat1:class>X</rat1:class>
<rat1:weight>XXX</rat1:weight>
</rat1:commodity>
</rat1:baseCommodities>
</rat1:rateRequest>
</soapenv:Body>
</soapenv:Envelope>
This was the code I was using before and it is not working.
<?php
$client = new SoapClient("https://www.estes-express.com/rating/ratequote/services/RateQuoteService?wsdl");
$request_object = array(
"header"=>array(
"auth"=>array(
"user"=>"XXXXX",
"password"=>"XXXXX",
)
),
"rateRequest"=>array(
"requestID"=>"XXXXXXXXXXXXXXX",
"account"=>"XXXXXX",
),
"originPoint"=>array(
"countryCode"=>"XX",
"postalCode"=>"XXXXX",
"city"=>"XXXXX",
"stateProvince"=>"XX",
),
"destinationPoint"=>array(
"countryCode"=>"XX",
"postalCode"=>"XXXXX",
),
"payor"=> "X",
"terms"=> "XXXX",
"stackable"=> "X",
"baseCommodities"=>array(
"commodity"=>array(
"class"=>"XX",
"weight"=>"XXXX",
)
),
);
$result = $client->rateRequest(array("request"=>$request_object));
var_dump($result);
?>
Here is the error
Fatal error: Uncaught SoapFault exception: [Client] Function ("rateRequest") is not a valid method for this service in /home/content/54/11307354/html/test/new/estes.php:36
Stack trace: #0 /home/content/54/11307354/html/test/new/estes.php(36): SoapClient->__call('rateRequest', Array) #1 /home/content/54/11307354/html/test/new/estes.php(36):
SoapClient->rateRequest(Array) #2 {main} thrown in /home/content/54/11307354/html/test/new/estes.php on line 36
This is my $params array that is passed to the Estes API
$params = array(
"requestID" => "xxxxxxxx",
"account" => "xxxxxxxx",
"originPoint" => array('countryCode' => 'US', 'postalCode' => $fromzip),
"destinationPoint" => array('countryCode' => 'US', 'postalCode' => $shipzip),
"payor" => 'T',
"terms" => 'PPD',
"stackable" => 'N',
"baseCommodities" => array('commodity' => $comArray ),
"accessorials" => array('accessorialCode' => $accArray)
If there are no accessorials, that array needs to be deleted from the $params array
);
// remove accessorials entry if no accessorial codes
if(sizeof($accArray) == 0){
$params = array_slice($params, 0, 8); // remove accesorials entry
}
THis is how I build the commodities array from a class array & a weight
array:
// load the $params commodities array
$comArray = array();
for ($i=0; $i<count($class_tbl); $i++) {
$comArray[] = array('class'=>$class_tbl[$i], 'weight'=>$weight_tbl[$i]);
}
The following code formats the accessorials array
if($inside == "Yes") {
$accArray[$i] = "INS";
++$i;
}
if($liftgate == "Yes") {
$accArray[$i] = "LGATE";
++$i;
}
if($call == "Yes") {
$accArray[$i] = "NCM";
++$i;
}
The Estes destination accessorial code also should be added to the $accArray array if delivery is to other than a business (for instance school. church, etc.)
See if anything in our soap call helps. We are doing the soap call like this:
// define transaction arrays
$url = "http://www.estes-express.com/rating/ratequote/services/RateQuoteService?wsdl";
$username = 'xxxxxxxx';
$password = 'xxxxxxxx';
// setting a connection timeout of five seconds
$client = new SoapClient($url, array("trace" => true,
"exceptions" => true,
"connection_timeout" => 5,
"features" => SOAP_WAIT_ONE_WAY_CALLS,
"cache_wsdl" => WSDL_CACHE_NONE));
$old = ini_get('default_socket_timeout');
ini_set('default_socket_timeout', 5);
//Prepare SoapHeader parameters
$cred = array(
'user' => $username,
'password' => $password
);
$header = new SoapHeader('http://ws.estesexpress.com/ratequote', 'auth', $cred);
$client->__setSoapHeaders($header);
$params = array(
"requestID" => "xxxxxxxx",
"account" => "xxxxxxxx",
"originPoint" => array('countryCode' => 'US', 'postalCode' => $fromzip),
"destinationPoint" => array('countryCode' => 'US', 'postalCode' => $shipzip),
"payor" => 'T',
"terms" => 'PPD',
"stackable" => 'N',
"baseCommodities" => array('commodity' => $comArray ),
"accessorials" => array('accessorialCode' => $accArray)
);
// remove accessorials entry if no accessorial codes
if(count($accArray) == 0){
$params = array_slice($params, 0, 8); // remove accesorials entry
}
// call Estes API and catch any errors
try {
$reply = $client->getQuote($params);
}
catch(SoapFault $e){
// handle issues returned by the web service
//echo "Estes soap fault<br>" . $e . "<br>";
$edit_error_msg = "Estes quote API timed out or failed to return a quote";
return "0.00";
}
catch(Exception $e){
// handle PHP issues with the request
//echo "PHP soap exception<br>" . $e . "<br>";
$edit_error_msg = "Estes quote API timed out or failed to return a quote";
return "0.00";
}
unset($client);
ini_set('default_socket_timeout', $old);
// print_r($reply);
Looking up the WSDL with a validator it looks like the two methods available are echo and getQuote.
Looking at the WSDL itself you can see that too:
<wsdl:operation name="getQuote">
<wsdl:input name="rateRequest" message="tns:rateRequestMsg"></wsdl:input>
<wsdl:output name="quoteInfo" message="tns:rateQuoteMsg"></wsdl:output>
<wsdl:fault name="schemaErrorMessage" message="tns:schemaErrorMsg"></wsdl:fault>
<wsdl:fault name="generalErrorMessage" message="tns:generalErrorMsg"></wsdl:fault>
</wsdl:operation>
Try calling getQuote instead of rateRequest.
$result = $client->__soapCall('getQuote', array("request"=>$request_object));