The following Soap Request works when the ORDER element is submitted as single element as an array or as an object, however I need to have multiple ORDER elements. I am now trying SoapParam/SoapVar with no luck at all. days of attempts to get this working at this point. Thank you all for your time!
function SendOrder($wan, $param) {
$url = "someurl";
$options = array(
"trace" => 1,
"exceptions" => 1,
"cache_wsdl" => WSDL_CACHE_NONE
);
try {
$client = new SoapClient($url, $options);
$xmlR = $client->ORDER($param);
//create a usable array
$json = json_encode($xmlR);
$array = json_decode($json,true);
dump($client->__getLastRequestHeaders());
dump($client->__getLastRequest());
dump($client->__getLastResponseHeaders());
dump($client->__getLastResponse());
return $array;
} catch (\Exception $e) {
return $e;
}
};
$param = new stdClass;
$param->REQUESTUNIQUEID = uniqid();
$person = 0;
$a = 0;
$orders = new stdClass;
foreach ($_SESSION['cartR'] as $c) {
$person++;
$menu_item = new stdClass;
$menu_item->PERSON = array('_' => "{$c->for_who}", 'NUMBER' => $person);
$menu_item->SERVICETIME = $service_time;
$menu_item->MENUITEM = array('_' => '', 'ID' => $c->product_id);
$menu_item->QUANTITY = 1;
$menu_item->PRICE = $c->price;
$menu_item->TOPPINGPART = "Whole";
$menu_item->ITEMLEVEL = 0;
$menu_item->POSWINDOW = array('_' => 'test', 'ID' => "");
$orders->MENUTIEM = $menu_item;
$param->ORDERS[] = $orders;
unset($menu_item);
}
$result = SendOrder($wan, $param);
Produces an object:
object(stdClass)#26 (13) {
["REQUESTUNIQUEID"]=>
string(13) "5c829ff8197fb"
["ORDERS"]=>
array(5) {
[0]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
[1]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
[2]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
[3]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
[4]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
}
}
I attempted suggestions in Stack OVerflow 3617398 and a few others. I am attempting SoapVar and SoapParam with no success at all, not even getting a trimmed down request of the minimal required elements through.
How do I get the Object created/formated properly with multiple elements with the same name in this scenario?
RESULT WITH THE ARRAY:
"
string(229) "HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/10.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 08 Mar 2019 18:57:11 GMT
Content-Length: 671
"
string(671) "5c82bb00d12a1 Web Service 27.4.3.320 Error false 0"
SOAPVAR AND SOAPPARAM (I am trying different combinations of SoapParam and SoapVar with the minimium required elements same url and same options as above)
$unique_id = uniqid();
$client_software = new stdClass;
$client_software->SOFTWARENAME = 'company name';
$client_software->SOFTWAREAPIVERSION = 1;
$client_software->SOFTWARECODEVERSION = "1.0.0.0"
$client = new SoapClient($url, $options);
$xmlR = $client->CHECKIMPORT(
new SoapParam(new SoapVar($unique_id, XSD_STRING), 'REQUESTUNIQUEID'),
new SoapParam(new SoapVar($client_software, SOAP_ENC_OBJECT), 'CLIENTSOFTWARE'),
);
RESPONSE:
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/10.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 08 Mar 2019 19:06:03 GMT
Content-Length: 868
"
string(868) "Web Service 27.4.3.320 REQUESTUNIQUEID is missing. CLIENTSOFTWARE is missing. false 0
WSDL Tree
<s:element minOccurs="0" maxOccurs="1" name="ORDERS" type="tns:IMPORTORDERLIST"/>
<s:complexType name="IMPORTORDERLIST">
<s:choice minOccurs="0" maxOccurs="unbounded">
<s:element minOccurs="1" maxOccurs="1" name="DISCOUNT" nillable="true" type="tns:IMPORTDISCOUNT"/>
<s:element minOccurs="1" maxOccurs="1" name="CHARGE" nillable="true" type="tns:IMPORTCHARGE"/>
<s:element minOccurs="1" maxOccurs="1" name="INSTRUCTION" nillable="true" type="tns:IMPORTINSTRUCTIONS"/>
<s:element minOccurs="1" maxOccurs="1" name="MENUITEM" nillable="true" type="tns:IMPORTMENUITEM"/>