0

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';

closed as off-topic by Mark Kaplun, cjbj, kaiser Sep 11 '16 at 20:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?" – Mark Kaplun, cjbj, kaiser
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Return should be return. Also the warning is saying that your array is being turned into a string, which isn't possible, not the other way around – Tom J Nowell Sep 3 '16 at 0:58
  • 1
    Can we see the full warning, as well as the code immediately before and after the line mentioned? Where does the $request array come from? It looks like a warning then a notice, with the new line and a chunk of information deleted so they're merged into 1 message – Tom J Nowell Sep 3 '16 at 0:59
  • Thanks for your help Tom! I've added more code above. The "return" works fine either way, but i'll make the changes to lowercase (that part of the code came directly from fedex) – rudtek Sep 3 '16 at 2:42
  • Ah so you never created $request, can you add $request = array(); before that and verify that's not the problem? – Tom J Nowell Sep 3 '16 at 3:41
  • this is just a php question that has nothing to do with wordpress. The error actually points you exactly where to look and it is easy to see that getProperty returns void for parentkey which I assume generates some sort of error, oor just prevent the creation of an array. Things like getProperty should always fire an exception/log an error when they can not handle the value being passed – Mark Kaplun Sep 3 '16 at 6:06
0

It looks like it was my original assumption. I placed all my codes into functions and then made a plugin and everything is working almost perfectly. The major hurdle was that because it was being handled on 2 pages and outside functions wordpress just didn't seem to know what it/I was doing.

Thanks again @tomjnowell for attempting. I truly appreciate it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.