I have a dovoid function I've taken from various tutorials for the classic api (the rest of our site uses the classic api, so I'm stuck using it until i can gut the thing and use the better apis). The function appears to execute and I am not getting error messages, but I am not seeing the transactions voided in the sandbox.
Here is the dovoid function:
public function DoVoid($auth_id,$note)
{
$xml = '<?xml version="1.0" encoding="UTF-8"?>'.
ENV:Envelope
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
'.
'<SOAP-ENV:Header>
'.
'<RequesterCredentials
xmlns="urn:ebay:api:PayPalAPI"
SOAP-ENV:mustUnderstand="1">
'.
'<Credentials xmlns="urn:ebay:apis:eBLBaseComponents">
'.
'<Username>'.utf8_encode($PayPalApiUsername).'</Username> '.
'<Password>'.utf8_encode($PayPalApiPassword).'</Password> '.
'<Subject>'.utf8_encode("Voiding Transaction").'</Subject>'.
'
</Credentials>'.
'
</RequesterCredentials>'.
'
</SOAP-ENV:Header>'.
'<SOAP-ENV:Body>
'.
'<DoVoidReq xmlns="urn:ebay:api:PayPalAPI">
'.
'<DoVoidRequest xmlns="urn:ebay:api:PayPalAPI">
'.
'<Version xmlns="urn:ebay:apis:eBLBaseComponents"
xsi:type="xsd:string">60.0</Version>'.
'<AuthorizationID>'.utf8_encode($auth_id).'</AuthorizationID>'.
'<Note>'.utf8_encode($note).'</Note>'.
'
</DoVoidRequest>'.
'
</DoVoidReq>'.
'
</SOAP-ENV:Body>'.
'
</SOAP-ENV:Envelope>';
//send query
$response = $this->sendQuery($xml);
if ($response)
{
//check XML response data
if (isset($response["SOAP-ENV:Envelope"][0]["SOAP-ENV:Body"][0]["DoVoidResponse"][0]))
{
$a = $response["SOAP-ENV:Envelope"][0]["SOAP-ENV:Body"][0]["DoVoidResponse"][0];
//check is there transaction error
if (isset($a["Errors"]))
{
$this->is_error = true;
foreach ($a["Errors"] as $key=>$value)
{
$this->error_messages[] = $value["ShortMessage"][0].(trim($value["ShortMessage"][0])!=trim($value["LongMessage"][0])?(" - ".$value["LongMessage"][0]):"");
}
return $this->error_messages;
}
//potentially all is good
else
{
$this->PaymentAction = $a;
//check tocken is the same as sent
if ($a["Ack"][0] == "Success")
{
if (isset($a["AuthorizationID"][0]))
{
//return payment data
return $a["AuthorizationID"][0];
}
}
else
{
$this->is_error = true;
$this->error_messages[] = "Incorrect transaction status";
return false;
}
}
}
}
}
Now one thing I am not sure of (since I just started using this API) is what the authorization ID should look like. Currently, the ones I am pulling from elsewhere in our system start with "ec_" which I don't think is correct. What should these authorization ids look like for voiding?
What I am trying to do is void an authorization when the order's values change, as we have had a lot of trouble with people getting multiple pending transactions because they change their order, reauthorize, and our system gets confused. While I am trying to fix the larger structural problems, I need this as a short term fix so we only have one active authorization per order.
In order to void an authorization you will need to reference it's transaction ID. The string that begins with "EC" is the secure token. A PayPal transaction ID contains 16 alphanumeric characters, for example 5DE44868BF3911546.
Related
I might be asking the wrong question here, but I cant seem to figure out where this is coming form. I am using both the HTTP Request2 and NET URL2 libraries in order to send some GET request to the Vuforia web services. This all works fine, but everytime I send a request, it also shows said request on screen.
GET d41d8cd98f00b204e9800998ecf8427e Mon, 09 Dec 2019 22:49:52 GMT /summary/ba2246f8cd29466899c69b8d05af09a1
The code that I use to get the above text appear on screen is as follows.
Main code:
<?php if(sizeof($items) > 0){
foreach($items as $item){
echo '<tr>';
echo'<td>'.$item['itemid'].'</td>';
echo'<td>'.$item['name'].'</td>';
echo'<td>'.$item['surname'].'</td>';
echo'<td>'.$item['phone'].'</td>';
$recos = $targetdata = json_decode(CheckVuforiaTarget("ba2246f8cd29466899c69b8d05af09a1"), true);
echo'<td>'.$recos['current_month_recos'].'</td>';
}
} else echo '<tr><td>Geen kandidaten</td></tr>';?>
Script holding the CheckVuforiaTarget function:
function CheckVuforiaTarget($vuforiaid){
$vuforiaTargetTracker = new TargetTracker($vuforiaid);
$response = $vuforiaTargetTracker->TargetTracker();
return ($response);
//print_r($vuforiaResult);
}
TargetTracker class:
<?php
require_once 'HTTP/Request2.php';
require_once 'SignatureBuilder.php';
// See the Vuforia Web Services Developer API Specification - https://developer.vuforia.com/resources/dev-guide/retrieving-target-cloud-database
// The DeleteTarget sample demonstrates how to delete a target from its Cloud Database using the target's target id.
// * note that targets cannot be 'Processing' and must be inactive to be deleted.
class TargetTracker{
//Server Keys
private $access_key = "...";
private $secret_key = "...";
private $url = "https://vws.vuforia.com";
private $requestPath = "/summary/";
private $request;
private $targetId = "";
public function __construct($targetId) {
$this->targetId = $targetId;
}
function TargetTracker(){
$this->requestPath = $this->requestPath . $this->targetId;
return $this->execTargetTracker();
}
public function execTargetTracker(){
$this->request = new HTTP_Request2();
$this->request->setMethod( HTTP_Request2::METHOD_GET );
$this->request->setConfig(array('ssl_verify_peer' => false));
$this->request->setURL( $this->url . $this->requestPath );
$this->setHeaders();
try {
$response = $this->request->send();
if (200 == $response->getStatus()) {
return $response->getBody();
} else {
//echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
// $response->getReasonPhrase(). ' ' . $response->getBody();
return $response->getBody();
}
} catch (HTTP_Request2_Exception $e) {
return $e->getMessage();
}
}
private function setHeaders(){
$sb = new SignatureBuilder();
$date = new DateTime("now", new DateTimeZone("GMT"));
// Define the Date field using the proper GMT format
$this->request->setHeader('Date', $date->format("D, d M Y H:i:s") . " GMT" );
// Generate the Auth field value by concatenating the public server access key w/ the private query signature for this request
$this->request->setHeader("Authorization" , "VWS " . $this->access_key . ":" . $sb->tmsSignature( $this->request , $this->secret_key ));
}
}
?>
Both HTTP/Request2.php(and everything it came with) and SignatureBuilder.php are both default scripts/classes I've downloaded from the internet without altering them.
Now with my basic understanding of PHP, i've tried to find anything related to an echo or whatever command would show this on screen, but I can't seem to find it.
Does someone have some pointers for me, so I can figure out the source?
Thanks in advance!
The code you provided has no echo/print output that would explain the message you see. The echo/print statement must be somewhere else.
I would like to get the item URL based on the item ID. After searching, I found that I can use GetSingleItem to achieve my goal. However, I got an error:
eBay returned the following error(s):
2 : Unsupported API call.
The API call "GetSingleItem" is invalid or not supported in this release.
Here is my code (all configuration are correct because I can use GetOrders by using these configs):
$subverb = "GetSingleItem";
$requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
$requestXmlBody .= '<GetSingleItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= "<ItemID>111986554711</ItemID>";
$requestXmlBody .= '</GetSingleItemRequest>';
//Create a new eBay session with all details pulled in from included keys.php
$session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $subverb);
//send the request and get response
$responseXml = $session->sendHttpRequest($requestXmlBody);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
die('<P>Error sending request');
//Xml string is parsed and creates a DOM Document object
$responseDoc = new DomDocument();
$responseDoc->loadXML($responseXml);
//get any error nodes
$errors = $responseDoc->getElementsByTagName('Errors');
$response = simplexml_import_dom($responseDoc);
$entries = $response->PaginationResult->TotalNumberOfEntries;
//if there are error nodes
if ($errors->length > 0) {
echo '<P><B>eBay returned the following error(s):</B>';
//display each error
//Get error code, ShortMesaage and LongMessage
$code = $errors->item(0)->getElementsByTagName('ErrorCode');
$shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
$longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
//Display code and shortmessage
echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", ">", str_replace("<", "<", $shortMsg->item(0)->nodeValue));
//if there is a long message (ie ErrorLevel=1), display it
if (count($longMsg) > 0)
echo '<BR>', str_replace(">", ">", str_replace("<", "<", $longMsg->item(0)->nodeValue));
} else { //If there are no errors, continue
if (isset($_GET['debug'])) {
header("Content-type: text/xml");
print_r($responseXml);
} else {
print("\n; 111986554711: " . $response->Item->ViewItemURLForNaturalSearch);
}
}
Any suggestion? Thank you .
As you discovered, you don't need the API to construct a simple eBay view item landing page URL.
The URL format you discovered works, but it's very old and might not be supported in full or for much longer.
Here's a simple URL format that is pretty current that you can use:
http://www.ebay.com/itm/122225724269
I got an answer without using api. Here is the answer: after I got item ID, I can use "http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=".$item_id to show my product on ebay.
I found this uri by using GetOrders API.
OrderArray.Order .TransactionArray.Transaction .Variation .VariationViewItemURL
Tip: "not optimized for natural search"
If anyone has any idea about "GetSingleItem", I am willing to know why my code doesn't work.
Can any one please advice how to parse nuSOAP headers and checking the username/password/Signature from the below SOAP Request
<SOAP-ENV:Header>
<SOAP-ENV:Header xmlns:wsa="http://admin.example.com">
<Username>testuser</Username>
<Password>test123456</Password>
<Signature>5595610031002</Signature>
</SOAP-ENV:Header>
</SOAP-ENV:Header>
i.e: i need to parse this header on server side and validate the credentials for every request.
Am not sure but i found an alternative to track the credentials by using the following code.
let me explain.
The code $sSoapRequest = file_get_contents('php://input'); which returns the entire SOAP request to the server side...
The following 2 functions helps me to bring out the values..
function doAuthenticate()
{
$sSoapRequest = file_get_contents('php://input');
if(isset($sSoapRequest))
{
$sUsername = hookTextBetweenTags($sSoapRequest, 'Username');
$sPassword = hookTextBetweenTags($sSoapRequest, 'Password');
$sSignature = hookTextBetweenTags($sSoapRequest, 'Signature');
if($sUsername=='testuser' && $sPassword=='test123456' && $sSignature=='5595610031002')
return true;
else
return false;
}
}
function hookTextBetweenTags($string, $tagname) {
$pattern = "/<$tagname ?.*>(.*)<\/$tagname>/";
preg_match($pattern, $string, $matches);
return $matches[1];
}
and, use doAuthenticate() method for every process in server side.
Just to be clear before continuing: using PHP's built-in SOAP class is unfortunately not an option here (production server's PHP is not built with it, and won't be).
I'm trying to use EWS to allow me to authenticate users for a completely external server application. LDAP authentication has been disallowed. I have verified my EWS wsdl is correct via http://www.testexchangeconnectivity.com/, a Microsoft autodiscover tool. The contents of the WSDL can be found here: http://pastebin.org/214070
The server is using SSL, and is using the default authentication method for EWS of "NTLM".
I've tried various code examples around the web, unfortunately I'm not well-versed in XML, SOAP, or cURL (which is pretty much all of the technology being used here). The current iteration of my code is found below:
<?php
include_once('./lib/nusoap.php');
$username = 'username#example.com';
$password = 'password';
$ews_url = 'https://owa.example.com/EWS/Exchange.asmx';
$soapclient = new nusoap_client($service, true);
$soapclient->setCredentials($username, $password, 'ntlm');
$soapclient->setUseCurl(true);
$soapclient->useHTTPPersistentConnection();
$soapclient->setCurlOption(CURLOPT_USERPWD, $username.':'.$password);
$soapclient->soap_defencoding = 'UTF-8';
$params = '<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"';
$params += ' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" Traversal="Shallow">';
$params += ' <ItemShape>';
$params += ' <t:BaseShape>IdOnly</t:BaseShape>';
$params += ' <t:AdditionalProperties>';
$params += ' <t:FieldURI FieldURI="message:From"/>';
$params += ' <t:FieldURI FieldURI="item:Subject"/>';
$params += ' <t:FieldURI FieldURI="message:IsRead"/>';
$params += ' <t:FieldURI FieldURI="item:DateTimeReceived"/>';
$params += ' <t:FieldURI FieldURI="calendar:Start"/>';
$params += ' <t:FieldURI FieldURI="calendar:End"/>';
$params += ' <t:FieldURI FieldURI="calendar:Location"/>';
$params += ' <t:FieldURI FieldURI="task:Status"/>';
$params += ' <t:FieldURI FieldURI="task:DueDate"/>';
$params += ' </t:AdditionalProperties>';
$params += ' </ItemShape>';
$params += ' <IndexedPageItemView Offset="0" MaxEntriesReturned="5" BasePoint="Beginning"/>';
$params += ' <ParentFolderIds>';
$params += ' <t:DistinguishedFolderId Id="inbox"/>';
$params += ' </ParentFolderIds>';
$params += '</FindItem>';
$operation = 'FindItem';
$namespace = '';
$soapAction = '';
$headers = false;
$result = $soapclient->call($operation, $params, $namespace, $soapAction, $headers);
echo '<pre>'; print_r($result); echo '</pre>';
if($soapclient->fault){
echo 'FAULT: ';
echo '<pre>'; print_r($result); echo '</pre>';
}else{
$err = $soapclient->getError();
if ($err) {
echo '<p><b><u>Error</u>:</b><br />' . $err . '</p>';
}else{
echo 'Connection succeeded.';
}
}
?>
The actual issue I am having is that NuSOAP is returning a generic error message of: "no operations defined in the WSDL document!". From the looks of the WSDL, this seems incorrect and makes me believe I'm missing something in code. If I remove the actual client call in the code ($soapclient->call(...)), the code prints out "Connection succeeded.", but it does this with or without the attempted NTLM authentication code.
I've also tried using the "php-ews" project on my development machine (even though the same code would not work on the production server) and was also unable to access anything without receiving an error.
If anyone has any experience with any of these technologies and might be able to point out some clarification (or possible errors) I would greatly appreciate it. If any further clarification is needed on my part, please let me know.
UPDATE 1:
It seems one error in loading the WSDL is the NTLM Authentication. Using cURL alone (no NuSOAP) I was able to access the WSDL file and find out the server is redirecting to a different endpoint location (.../EWS/Services.wsdl).
Unfortunately, I've tried using the NuSOAP library's cURL ability and setting the same options through NuSOAP, and I am still getting the same generic error message as if NuSOAP is just unable to see/view/access the WSDL file. I believe it may still be NTLM Authentication as the cURL version takes a few moments to return (NTLM it a multi-step handshake process), whereas the NuSOAP client code is immediately returning the error message.
There's a few things you'll want to look at here.
There's an error in your call to the actual soap_client. You defined the endpoint in a variable called $ews_url, but then called the constructor with $service.
Why are you adding a string to a string in your $xml variable - perhaps in your haste you meant to concatenate instead? (operators: + vs .)
Using the following Wiki information directed to working with EWS in Java, it seems that Microsoft has yet again blundered in their implementation of a common protocol. The modification of types.xsd in this Wiki actually causes a problem, so ignore that change, but downloading a local copy of Services.wsdl and modifying it to point to your own server seems to work properly. http://www.bedework.org/trac/bedework/wiki/ExchangeWSlink text
The following code should work, so long as you have downloaded a local copy of your types.xsd, messages.xsd, and Services.wsdl - and modified the Services.wsdl file to add the required information relevant to your server. Make sure the local copies of those files are in the same folder on your server.
<?php
include_once('./lib/nusoap.php');
$username = 'username#example.com';
$password = 'password';
$endpoint = 'http://your.local.version/of/Services.wsdl';
$wsdl = true;
$soapclient = new nusoap_client($endpoint, $wsdl);
$soapclient->setCredentials($username, $password, 'ntlm');
$xml = '<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"';
$xml .= ' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" Traversal="Shallow">';
$xml .= ' <ItemShape>';
$xml .= ' <t:BaseShape>IdOnly</t:BaseShape>';
$xml .= ' <t:AdditionalProperties>';
$xml .= ' <t:FieldURI FieldURI="message:From"/>';
$xml .= ' <t:FieldURI FieldURI="item:Subject"/>';
$xml .= ' <t:FieldURI FieldURI="message:IsRead"/>';
$xml .= ' <t:FieldURI FieldURI="item:DateTimeReceived"/>';
$xml .= ' <t:FieldURI FieldURI="calendar:Start"/>';
$xml .= ' <t:FieldURI FieldURI="calendar:End"/>';
$xml .= ' <t:FieldURI FieldURI="calendar:Location"/>';
$xml .= ' <t:FieldURI FieldURI="task:Status"/>';
$xml .= ' <t:FieldURI FieldURI="task:DueDate"/>';
$xml .= ' </t:AdditionalProperties>';
$xml .= ' </ItemShape>';
$xml .= ' <IndexedPageItemView Offset="0" MaxEntriesReturned="5" BasePoint="Beginning"/>';
$xml .= ' <ParentFolderIds>';
$xml .= ' <t:DistinguishedFolderId Id="inbox"/>';
$xml .= ' </ParentFolderIds>';
$xml .= '</FindItem>';
$operation = 'FindItem';
$result = $soapclient->call($operation, $xml);
echo '<pre>'; print_r($result); echo '</pre>';
?>
The solution all seems to stem from having a local copy of the main SOAP reference files, and fixing the Services.wsdl file. If you had access to the Exchange server, you might be able to modify the Services.wsdl file and everything could have worked as expected without all of this hassle. I cannot verify this, unfortunately.
UPDATE:
OK I figured it out, looks like fread has a filesize limitation, changed this to
file_get_contents('php://input')
, but now having SF give a java.net.SocketTimeoutException: Read timed out error and nothing on the PHP side. I have also added set_time_limit(0); to the PHP script which if I understand correctly execute the script for as long as it takes. Any thoughts?
BTW: I can process up to 25 (that I've tested) but not 100
I'm using Salesforce to send outbound messages (via SOAP) to another server. The server can process about 8 messages at a time, but will not send back the ACK file if the SOAP request contains more than 8 messages. SF can send up to 100 outbound messages in 1 SOAP request and I think this is causing a memory issue with PHP. If I process the outbound messages 1 by 1 they all go through fine, I can even do 8 at a time with no issues. But larger sets are not working.
ERROR in SF:
org.xml.sax.SAXParseException: Premature end of file
Looking in the HTTP error logs I see that the incoming SOAP message looks to be getting cut of which throws a PHP warning stating:
DOMDocument::loadXML() ... Premature end of data in tag ...
PHP Fatal error:
Call to a member function getAttribute() on a non-object
This leads me to believe that PHP is having a memory issue and can not parse the incoming message due to it's size.
I was thinking I could just set:
ini_set('memory_limit', '64M'); // This has done nothing to fix the problem
But would this be the correct approach? Is there a way I could set this to increase with the incoming SOAP request dynamically?
UPDATE: Adding some code
/**
* To parse out incoming SOAP requests and insert the values into a database table
*
* {#link http://www.mikesimonds.com/salesforce-php-tutorials/95-using-salesforce-outbound-soap-messages-php-2.html}
*/
// Might need more memory?
ini_set('memory_limit', '64M'); // So far this does nothing to help the bulk requests
/**
* Set the document root path
* #var $doc_root
*/
$doc_root = $_SERVER['DOCUMENT_ROOT'];
/**
* This is needed for the $sObject object variable creation
* found in phptoolkit-11_0 package available from SalesForce
*/
require_once(DOC_ROOT . SALESFORCE_DIRECTORY . SALESFORCE_PHP_TOOLKIT .'/soapclient/SforcePartnerClient.php');
/**
* Reads SOAP incoming message from Salesforce/MAPS
* #var incoming SOAP request
*/
$data = fopen('php://input','rb');
$headers = getallheaders();
$content_length = $headers['Content-Length'];
$buffer_length = 1000; // Do I need this buffer?
$fread_length = $content_length + $buffer_length;
$content = fread($data,$fread_length);
/**
* Parse values from soap string into DOM XML
*/
$dom = new DOMDocument();
$dom->loadXML($content);
$resultArray = parseNotification($dom);
$sObject = $resultArray["sObject"];
// Can remove this once I figure out the bug
$testing = false;
// Set $testing to true if you would like to see the incoming SOAP request from SF
if($testing) {
// Make it look nice
$dom->formatOutput = true;
// Write message and values to a file
$fh = fopen(LOG_FILE_PATH.'/'.LOG_FILE_NAME,'a');
fwrite($fh,$dom->saveXML());
$ret_val = fclose($fh);
}
/**
* Checks if the SOAP request was parsed out,
* the $sObject->ACK is set to a string value of true in
* the parseNotification()
* #var $sObject->ACK
*/
if($sObject->ACK == 'true') {
respond('true');
} else {
// This means something might be wrong
mail(BAD_ACK_TO_EMAIL,BAD_ACK_EMAIL_SUBJECT,$content,BAD_ACK_EMAIL_HEADER_WITH_CC);
respond('false');
}
if(WRITE_OUTPUT_TO_LOG_FILE) {
// Clear variable
$fields_string = "";
/**
* List common values of the SOAP request
* #var $sObject
*/
$fields_string .= "Organization Id: " . $sObject->OrganizationId . "\n";
$fields_string .= "Action Id: " . $sObject->ActionId . "\n";
//$fields_string .= "Session Id: " . $sObject->SessionId . "\n"; // Session Id is not being passed right now, don't need it
$fields_string .= "Enterprise URL: " . $sObject->EnterpriseUrl . "\n";
$fields_string .= "Partner URL: " . $sObject->PartnerUrl . "\n";
/**
* #todo: Still need to add the notification Id to an array or some sort
*/
//$fields_string .= "Notification Id: " . $sObject->NotificationId . "\n";
//$fields_string .= '<pre>' . print_r($sObject->NotificationId,true) . '</pre>';
/**
* now you have an array as $record and you can use the
* data as you need to for updates or calls back to salesforce
* whatever you need to do is here
* #var $resultArray['MapsRecords']
*/
foreach ($resultArray['MapsRecords'] as $record) {
// Just prints the fields in the array
$fields_string .= '<pre>' . print_r($record,true) . '</pre>';
}
// Flag used to send ACK response
$fields_string .= "\nACK Flag: " . $sObject->ACK;
// $content_length
$fields_string .= "\nContent Length (Outbound Message Size): " . $content_length;
// Close Border to separate each request
$fields_string .= "\n /*********************************************/ \n";
// Write message and values to a file
$fh = fopen(LOG_FILE_PATH.'/'.LOG_FILE_NAME,'a');
fwrite($fh,$fields_string);
$ret_val = fclose($fh);
}
/**
* Parse a Salesforce.com Outbound Message notification SOAP packet
* into an array of notification parms and an sObject.
* #param XML [$domDoc] SOAP request as XML
* #return object/array[ $result] typecast XML to object of arrays
**/
function parseNotification($domDoc) {
// Parse Notification parameters into result array
$result = array("OrganizationId" => "",
"ActionId" => "",
"SessionId" => "",
"EnterpriseUrl" => "",
"PartnerUrl" => "",
"sObject" => null,
"MapsRecords" => array());
// Create sObject and fill fields provided in notification
$sObjectNode = $domDoc->getElementsByTagName("sObject")->item(0);
$sObjType = $sObjectNode->getAttribute("type");
if(substr_count($sObjType,"sf:")) {
$sObjType = substr($sObjType,3);
}
$result["sObject"] = new SObject($sObjType);
$result["sObject"]->type = $sObjType;
$result["sObject"]->OrganizationId = $domDoc->getElementsByTagName("OrganizationId")->item(0)->textContent;
$result["sObject"]->ActionId = $domDoc->getElementsByTagName("ActionId")->item(0)->textContent;
$result["sObject"]->SessionId = $domDoc->getElementsByTagName("SessionId")->item(0)->textContent;
$result["sObject"]->EnterpriseUrl = $domDoc->getElementsByTagName("EnterpriseUrl")->item(0)->textContent;
$result["sObject"]->PartnerUrl = $domDoc->getElementsByTagName("PartnerUrl")->item(0)->textContent;
/**
* #todo: for multiple requests, need to add an array of Notification Id's
* might move this inside the loop or something
* might not need to do this as well
*/
//$notificationId[] = $domDoc->getElementsByTagName("Id")->item(0)->textContent;
//$result["sObject"]->NotificationId = $notificationId;
$sObjectNodes = $domDoc->getElementsByTagNameNS('urn:sobject.BLAH.com','*');
$result["sObject"]->fieldnames = array();
$count = 0;
$tempMapRecord = array();
// Loop through each notification sObject
foreach ($sObjectNodes as $node) {
if ($node->localName == "Id") {
if ($count > 0) {
$result["MapsRecords"][] = $tempMapRecord;
$tempMapRecord = array();
}
// #note: added the strip_tags() to strip out all HTML tags
$tempMapRecord[$node->localName] = strip_tags($node->textContent);
} else {
// #note: added the strip_tags() to strip out all HTML tags
$tempMapRecord[$node->localName] = strip_tags($node->textContent);
}
$count++;
// set flag for ACK
$result["sObject"]->ACK = 'true';
}
// Finish last item
$result["MapsRecords"][] = $tempMapRecord;
return $result;
}
/**
* ACK to SalesForce, True/False (Prints header)
* #param object $tf
* #return $ACK
*/
function respond($tf) {
$ACK = <<<ACK
<?xml version = "1.0" encoding = "utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<notifications xmlns="http://BLAH.com/outbound">
<Ack>$tf</Ack>
</notifications>
</soapenv:Body>
</soapenv:Envelope>
ACK;
print trim($ACK);
}
Example SOAP Request from Salesforce, there would be multiple notification nodes added to a larger request.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<notifications xmlns="http://BLAH.com/outbound">
<OrganizationId>BLAH</OrganizationId>
<ActionId>BLAH</ActionId>
<SessionId xsi:nil="true"/>
<EnterpriseUrl>https://BLAH.com/</EnterpriseUrl>
<PartnerUrl>https://BLAH.com/</PartnerUrl>
<Notification>
<Id>BLAH</Id>
<sObject xmlns:sf="urn:sobject.BLAH.com" xsi:type="sf:Case">
<sf:Id>BLAH</sf:Id>
<sf:CaseNumber>BLAH</sf:CaseNumber>
<sf:Case_Owner_ID_hidden__c>BLAH</sf:Case_Owner_ID_hidden__c>
<sf:CreatedDate>2010-03-17T12:11:33.000Z</sf:CreatedDate>
<sf:LastModifiedDate>2010-03-17T15:21:29.000Z</sf:LastModifiedDate>
<sf:OwnerId>BLAH</sf:OwnerId>
<sf:Status>BLAH</sf:Status>
</sObject>
</Notification>
</notifications>
</soapenv:Body>
</soapenv:Envelope>
A PHP memory issue will say
PHP Fatal error: Out of memory (allocated 250871808)...
This is more likely to be incorrectly terminated or truncated data originating from the Salesforce platform - try debugging the first error from SF.
EDIT:
OK, it looks like you're grabbing data in an antiquated manner. Try replacing fread() with stream_get_contents(), and also echo $content straight after you get it to check the output.