soap request in wordpress for a fedex pickup request
I'm trying to create a pickup request for fedex for a wordpress site. I have the api and tool working fine when I create have the code outside wordpress, but when i put the same code into wordpress i'm getting and error that says
A Warning: Illegal string offset 'Warning: Illegal string offset 'WebAuthenticationDetail' in /home/xd/public_html/test/wp-content/themes/dev/template-pickup-confirm.php on line 33 Notice: Array to string conversion in /home/xd/public_html/test/wp-content/themes/dev/template-pickup-confirm.php on line 33
There are 4 files that are needed: pickupform.php (form that posts to pickup-request.php) pickup-request.php (handling soap) fedex-common.php (handling common fedex functions in case i was using other fedex tools such as rating, shipping, refunds, or cancellations) PickupService_v13.wsdl. (fedex webservices library)
I embedded the 2 main php forms into templates in wordpress.
I fill out the form on (pickupform.php) one and it posts to pickup-request.php
so it's stopping at this line in my pickuprequest form:
$request['WebAuthenticationDetail'] = array(
'ParentCredential' = array(
'Key' = getProperty('parentkey'),
'Password' = getProperty('parentpassword')
),
'UserCredential' = array(
'Key' = getProperty('key'),
'Password' = getProperty('password')
)
);
which the getProperty()is referencing this function in the fedexcommon.php:
function getProperty($var){
if($var == 'key') Return 'vB12a89Q25xwv';
if($var == 'password') Return 'FFAz8EEYEEfEZufZxu4pJc';
if($var == 'shipaccount') Return '510087';
if($var == 'billaccount') Return '510087';
if($var == 'dutyaccount') Return 'XXX';
if($var == 'freightaccount') Return 'XXX';
if($var == 'trackaccount') Return 'XXX';
if($var == 'dutiesaccount') Return 'XXX';
if($var == 'importeraccount') Return 'XXX';
if($var == 'brokeraccount') Return 'XXX';
if($var == 'distributionaccount') Return 'XXX';
if($var == 'locationid') Return 'PLBA';
if($var == 'printlabels') Return true;
if($var == 'printdocuments') Return true;
if($var == 'packagecount') Return '4';
if($var == 'validateaccount') Return 'XXX';
if($var == 'meter') Return '118593060';
);
}
So it looks like for some reason wordpress doesn't know or isn't changing the WebAuthenticationDetail to an array?
Should the code be written differently for a wordpress array?
Or is this needing to be written in a plugin instead?
adding additional code at request of below:
require_once('library/fedex-common.php5');
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "wsdl/PickupService_v13.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
date_default_timezone_set('America/Los_Angeles');
$cdate = $_POST["txtPickupDate"]. " ". $_POST["txtPickupTime"];
$datetime = new DateTime($cdate);
$tdate = $datetime-format('c');
$request['WebAuthenticationDetail'] = array( //LINE 33
'ParentCredential' = array(
'Key' = getProperty('parentkey'),
'Password' = getProperty('parentpassword')
),
'UserCredential' = array(
'Key' = getProperty('key'),
'Password' = getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' = getProperty('shipaccount'),
'MeterNumber' = getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' = '*** Create Pickup Request using PHP ***');
$request['Version'] = array(
'ServiceId' = 'disp',
'Major' = 13,
'Intermediate' = 0,
'Minor' = 0
);
$request['OriginDetail'] = array(
'PickupLocation' = array(
'Contact' = array(
'PersonName' = $_POST["txtFromName"],
'CompanyName' = '',
'PhoneNumber' = $_POST["txtFromPhone"]
),
'Address' = array(
'StreetLines' = array($_POST["txtFromAddress1"]),
'City' = $_POST["txtFromCity"],
'StateOrProvinceCode' = $_POST["txtFromState"],
'PostalCode' = $_POST["txtFromZip"],
'CountryCode' = 'US')
),
'PackageLocation' = $_POST["selPickupPoint"], // valid values NONE, FRONT, REAR and SIDE
'BuildingPartCode' = '', // valid values APARTMENT, BUILDING, DEPARTMENT, SUITE, FLOOR and ROOM
'BuildingPartDescription' = $_POST["txtFromAddress1"],
'ReadyTimestamp' = $tdate, // Replace with your ready date time
'CompanyCloseTime' = $_POST["txtCloseTime"]
);
$request['PackageCount'] = $_POST["txtPackageCount"];
$request['TotalWeight'] = array(
'Value' = $_POST["txtTPackWeight"],
'Units' = 'LB' // valid values LB and KG
);
$request['CarrierCode'] = 'FDXE'; // valid values FDXE-Express, FDXG-Ground, FDXC-Cargo, FXCC-Custom Critical and FXFR-Freight
//$request['OversizePackageCount'] = '0';
$request['CourierRemarks'] = 'This is a test. Do not pickup';