I'm calling a web service using SOAP in PHP which is returning the data which I am then converting to an array using:
$array = json_decode(json_encode($response), True);
This gives me the following when calling print_r($array):
{"Transactions":[{"MerchantAccount":"Test Account","Owner":"Test Owner","CustomerName":"Lisa Jobs"},
{"MerchantAccount":"Test Account","Owner":"Test Owner","CustomerName":"Lisa Jobs2"},
{"MerchantAccount":"Test Account","Owner":"Test Owner","CustomerName":"Lisa Jobs3"},
{"MerchantAccount":"Test Account","Owner":"Test Owner","CustomerName":"Lisa Jobs4"}]}
Could someone point me in the right direction so that I have an array full of Transactions please? (as in get rid of the first part of the string "Transactions"
I've tried print_r($array['Transactions']); but that is giving me an error:
Warning: Illegal string offset
Any help would be greatly appreciated.
Here's the bare data from the WSDL:
Array
(
[0] => stdClass Object
(
[TransactionsSinceTicksResult] =>
{"Transactions":[
{"MerchantAccount":"Test","Owner":"Test Owner","CustomerName":"Lisa Bloggs"},
{"MerchantAccount":"Test","Owner":"Test Owner","CustomerName":"Lisa Bloggs2"},
{"MerchantAccount":"Test","Owner":"Test Owner","CustomerName":"Lisa Bloggs3"}
]}
)
)
UPDATE:
Function:
function getTransactions($sinceTicks) {
global $userEmailAddress;
global $userPassword;
global $accountGatewayUser;
global $accountGatewayPassword;
$format = 'JSON';
$wsdl = 'https://apps.blahblahblah.co.uk/recurring-payments/Services/Merchant.asmx?WSDL';
try {
$soapclient = new SoapClient($wsdl);
$params = array (
'userEmailAddress' => $userEmailAddress,
'userPassword' => $userPassword,
'accountGatewayUser' => $accountGatewayUser,
'accountGatewayPassword' => $accountGatewayPassword,
'format' => $format,
'sinceTicks' => $sinceTicks
);
$response = $soapclient->TransactionsSinceTicks($params);
$array = json_decode($response[0]->TransactionsSinceTicksResult, True);
return ($array['Transactions']);
}
catch(SoapFault $error) {
return json_encode($error);
}
}
This is returning: Fatal error: Cannot use object of type stdClass as array in...