$line2->DetailType = 'JournalEntryLineDetail '; $line2->JournalEntryLineDetail = $linedet2; // Add a journal $journalObj = new IPPJournalEntry(); $journalObj->SyncToken = '1'; $journalObj->DocNumber = '1'; $journalObj->TxnDate = '2014-12-30'; $journalObj->RefNumber = 't123'; $journalObj->PrivateNote = 'Just testing'; $journalObj->Line = array($line, $line2); $journalObj->Adjustment = TRUE; $journalObj->IsAdjustment = TRUE; $resultingjournalObj = $dataService->Add($journalObj); // Echo some formatted output echo '<a href="javascript:void(0)" onclick="goHome()">Home</a>'; echo ' '; echo '<a href="javascript:void(0)" onclick="return intuit.ipp.anywhere.logout(function () { window.location.href = \'http://localhost/PHPSample/index.php\'; });">Sign Out</a>'; echo ' '; echo '<a target="_blank" href="http://localhost/PHPSample/ReadMe.htm">Read Me</a><br />'; //print_r($resultingjournalObj); echo "<br />Created Journal Id={$resultingjournalObj->Id}. <br /> <br /> Reconstructed response body:<br />"; $xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingjournalObj, $urlResource); echo $xmlBody . "\n"; ?> <script type="text/javascript"> function goHome(){ window.location.href = "http://localhost/PHPSample/SampleAppHomePage.php"; } </script> </body> </html>
/** * DeSerializes the specified action entity type. * @param message The type to be serialize to * @param bLimitToOne Limit to parsing just one response element * @return object Returns the de serialized object. */ public function Deserialize($message, $bLimitToOne = FALSE) { if (!$message) { return NULL; } $resultObject = NULL; $resultObjects = NULL; $responseXmlObj = simplexml_load_string($message); foreach ($responseXmlObj as $oneXmlObj) { $oneXmlElementName = (string) $oneXmlObj->getName(); if ('Fault' == $oneXmlElementName) { return NULL; } $phpClassName = XmlObjectSerializer::decorateIntuitEntityToPhpClassName($oneXmlElementName); $onePhpObj = XmlObjectSerializer::PhpObjFromXml($phpClassName, $oneXmlObj->asXML()); $resultObject = $onePhpObj; $resultObjects[] = $onePhpObj; // Caller may be anticipating ONLY one object in result if ($bLimitToOne) { break; } } if ($bLimitToOne) { return $resultObject; } else { return $resultObjects; } /* object deserializedObject = null; // Initialize serialize for object XmlSerializer serializer = new XmlSerializer(typeof(T)); try { using (TextReader reader = new StringReader(message)) { // de serialization of message. deserializedObject = serializer.Deserialize(reader); } } catch (SystemException ex) { SerializationException serializationException = new SerializationException(ex.Message, ex); this.IDSLogger.Log(TraceLevel.Error, serializationException.ToString()); IdsExceptionManager.HandleException(serializationException); } return deserializedObject; */ }
/** * This method executes the batch request. */ public function Execute() { $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Started Executing Method Execute for Batch"); // Create Intuit Batch Request $intuitBatchRequest = new IPPIntuitBatchRequest(); $intuitBatchRequest->BatchItemRequest = $this->batchRequests; $uri = "company/{1}/batch?requestid=" . rand() . rand(); $uri = str_replace('{1}', $this->serviceContext->realmId, $uri); // Creates request parameters $requestParameters = NULL; if (0) { // No JSON support here yet //$requestParameters = new RequestParameters($uri, 'POST', CoreConstants::CONTENTTYPE_APPLICATIONJSON, NULL); } else { $requestParameters = new RequestParameters($uri, 'POST', CoreConstants::CONTENTTYPE_APPLICATIONXML, NULL); } $restRequestHandler = new SyncRestHandler($this->serviceContext); try { // Get literal XML representation of IntuitBatchRequest into a DOMDocument $httpsPostBodyPreProcessed = XmlObjectSerializer::getPostXmlFromArbitraryEntity($intuitBatchRequest, $urlResource); $doc = new DOMDocument(); $domObj = $doc->loadXML($httpsPostBodyPreProcessed); $xpath = new DOMXpath($doc); // Replace generically-named IntuitObject nodes with tags that describe contained objects $objectIndex = 0; while (1) { $matchingElementArray = $xpath->query("//IntuitObject"); if (is_null($matchingElementArray)) { break; } if ($objectIndex >= count($intuitBatchRequest->BatchItemRequest)) { break; } foreach ($matchingElementArray as $oneNode) { // Found a DOMNode currently named "IntuitObject". Need to rename to // entity that describes it's contents, like "ns0:Customer" (determine correct // name by inspecting IntuitObject's class). if ($intuitBatchRequest->BatchItemRequest[$objectIndex]->IntuitObject) { // Determine entity name to use $entityClassName = get_class($intuitBatchRequest->BatchItemRequest[$objectIndex]->IntuitObject); $entityTransferName = XmlObjectSerializer::cleanPhpClassNameToIntuitEntityName($entityClassName); $entityTransferName = 'ns0:' . $entityTransferName; // Replace old-named DOMNode with new-named DOMNode $newNode = $oneNode->ownerDocument->createElement($entityTransferName); if ($oneNode->attributes->length) { foreach ($oneNode->attributes as $attribute) { $newNode->setAttribute($attribute->nodeName, $attribute->nodeValue); } } while ($oneNode->firstChild) { $newNode->appendChild($oneNode->firstChild); } $oneNode->parentNode->replaceChild($newNode, $oneNode); } break; } $objectIndex++; } $httpsPostBody = $doc->saveXML(); list($responseCode, $responseBody, $responseError) = $restRequestHandler->GetResponse($requestParameters, $httpsPostBody, NULL); } catch (Exception $e) { IdsExceptionManager::HandleException($e); } CoreHelper::CheckResponseErrorAndThrowException($this->serviceContext, $responseError); CoreHelper::CheckNullResponseAndThrowException($responseBody); try { $this->batchResponses = array(); $this->intuitBatchItemResponses = array(); // No JSON support here yet // de serialize object $responseXmlObj = simplexml_load_string($responseBody); foreach ($responseXmlObj as $oneXmlObj) { // process batch item $intuitBatchResponse = $this->ProcessBatchItemResponse($oneXmlObj); $this->intuitBatchItemResponses[] = $intuitBatchResponse; if ($intuitBatchResponse && $intuitBatchResponse->entities && count($intuitBatchResponse->entities)) { $this->batchResponses[] = $intuitBatchResponse->entities; } } } catch (Exception $e) { return NULL; } $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Finished Execute method for batch."); }
} // Add a customer $customerObj = new IPPCustomer(); $customerObj->Name = "Name" . rand(); $customerObj->CompanyName = "CompanyName" . rand(); $customerObj->GivenName = "GivenName" . rand(); $customerObj->DisplayName = "DisplayName" . rand(); $resultingCustomerObj = $dataService->Add($customerObj); echo "Created Customer Id={$resultingCustomerObj->Id}. Reconstructed response body:\n\n"; $xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingCustomerObj, $urlResource); echo $xmlBody . "\n"; // Update Customer Obj $resultingCustomerObj->GivenName = "New Name " . rand(); $resultingCustomerUpdatedObj = $dataService->Add($resultingCustomerObj); echo "\n" . "Updated Customer Id={$resultingCustomerObj->Id}. Reconstructed response body:\n\n"; $xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingCustomerUpdatedObj, $urlResource); echo $xmlBody . "\n"; /* Created Customer Id=519. Reconstructed response body: <?xml version="1.0" encoding="UTF-8"?> <ns0:Customer xmlns:ns0="http://schema.intuit.com/finance/v3"> <ns0:Id>519</ns0:Id> <ns0:SyncToken>0</ns0:SyncToken> <ns0:MetaData> <ns0:CreateTime>2013-08-18T10:39:45-07:00</ns0:CreateTime> <ns0:LastUpdatedTime>2013-08-18T10:39:45-07:00</ns0:LastUpdatedTime> </ns0:MetaData> <ns0:GivenName>GivenName588312171</ns0:GivenName> <ns0:FullyQualifiedName>GivenName588312171</ns0:FullyQualifiedName> <ns0:CompanyName>CompanyName305463250</ns0:CompanyName>
/** * Uploads an image * * @param string $imgBits image bytes * @param string $fileName Filename to use for this file * @param string $mimeType MIME type to send in the HTTP Headers * @param IPPAttachable $objAttachable entity describing the attachement * @return array Returns an array of entities fulfilling the query. */ public function Upload($imgBits, $fileName, $mimeType, $objAttachable) { $this->serviceContext->IppConfiguration->Logger->RequestLog->Log(TraceLevel::Info, "Called Method Upload."); // Validate parameter if (!$imgBits || !$mimeType || !$fileName) { $this->serviceContext->IppConfiguration->Logger->RequestLog->Log(TraceLevel::Error, "Argument Null Exception"); throw new IdsException('Argument Null Exception'); } // Builds resource Uri $urlResource = "upload"; $uri = implode(CoreConstants::SLASH_CHAR, array('company', $this->serviceContext->realmId, $urlResource)); $boundaryString = md5(time()); // Creates request parameters $requestParameters = new RequestParameters($uri, 'POST', "multipart/form-data; boundary={$boundaryString}", NULL); $MetaData = XmlObjectSerializer::getPostXmlFromArbitraryEntity($objAttachable, $urlResource); $desiredIdentifier = '0'; $newline = "\r\n"; $dataMultipart = ''; $dataMultipart .= '--' . $boundaryString . $newline; $dataMultipart .= "Content-Disposition: form-data; name=\"file_metadata_{$desiredIdentifier}\"" . $newline; $dataMultipart .= "Content-Type: " . CoreConstants::CONTENTTYPE_APPLICATIONXML . '; charset=UTF-8' . $newline; $dataMultipart .= 'Content-Transfer-Encoding: 8bit' . $newline . $newline; $dataMultipart .= $MetaData; $dataMultipart .= '--' . $boundaryString . $newline; $dataMultipart .= "Content-Disposition: form-data; name=\"file_content_{$desiredIdentifier}\"; filename=\"{$fileName}\"" . $newline; $dataMultipart .= "Content-Type: {$mimeType}" . $newline; $dataMultipart .= 'Content-Transfer-Encoding: base64' . $newline . $newline; $dataMultipart .= chunk_split(base64_encode($imgBits)) . $newline; $dataMultipart .= "--" . $boundaryString . "--" . $newline . $newline; // finish with two eol's!! $restRequestHandler = new SyncRestHandler($this->serviceContext); try { // gets response list($responseCode, $responseBody, $responseError) = $restRequestHandler->GetResponse($requestParameters, $dataMultipart, NULL); } catch (Exception $e) { IdsExceptionManager::HandleException($e); } CoreHelper::CheckResponseErrorAndThrowException($this->serviceContext, $responseError); CoreHelper::CheckNullResponseAndThrowException($responseBody); $restRequestHandler = new SyncRestHandler($this->serviceContext); try { $parsedResponseBody = $this->responseSerializer->Deserialize($responseBody, TRUE); } catch (Exception $e) { return NULL; } $this->serviceContext->IppConfiguration->Logger->RequestLog->Log(TraceLevel::Info, "Finished Executing Method Upload."); return $parsedResponseBody; }