示例#1
0
 protected function _IDS_v2($Context, $realmID, $resource, $optype, $xml, $ID)
 {
     if (substr($resource, 0, 6) == 'Report') {
         $resource = substr($resource, 6);
     }
     // This is because IDS v2 with QuickBooks Online is retarded
     if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_PAYMENTMETHOD) {
         $resource = 'payment-method';
     } else {
         if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_SALESRECEIPT) {
             $resource = 'sales-receipt';
         } else {
             if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_TIMEACTIVITY) {
                 $resource = 'time-activity';
             } else {
                 if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_JOURNALENTRY) {
                     $resource = 'journal-entries';
                 } else {
                     if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_BILLPAYMENT) {
                         $resource = 'bill-payment';
                     }
                 }
             }
         }
     }
     if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $optype == QuickBooks_IPP_IDS::OPTYPE_QUERY) {
         // Make the resource plural... (unless it's the changedatadeleted) *sigh*
         if ($resource == QuickBooks_IPP_IDS::RESOURCE_TIMEACTIVITY) {
             $resource = 'time-activities';
         } else {
             if ($resource == QuickBooks_IPP_IDS::RESOURCE_CLASS) {
                 $resource .= 'es';
             } else {
                 if ($resource != QuickBooks_IPP_IDS::RESOURCE_CHANGEDATADELETED) {
                     $resource .= 's';
                 }
             }
         }
     }
     $post = true;
     if ($resource == QuickBooks_IPP_IDS::RESOURCE_COMPANY or $resource == QuickBooks_IPP_IDS::RESOURCE_COMPANYMETADATA) {
         $post = false;
         $xml = '';
     }
     //$url = 'https://services.intuit.com/sb/' . strtolower($resource) . '/' . $this->_ids_version . '/' . $realmID;
     if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE) {
         if ($optype == QuickBooks_IPP_IDS::OPTYPE_FINDBYID) {
             $parse = QuickBooks_IPP_IDS::parseIDType($xml);
             $url = $this->_baseurl . '/' . strtolower($resource) . '/' . $this->_ids_version . '/' . $realmID . '/' . $parse[1];
             $post = false;
             $xml = null;
         } else {
             if ($optype == QuickBooks_IPP_IDS::OPTYPE_MOD) {
                 $parse = QuickBooks_IPP_IDS::parseIDType($ID);
                 $url = $this->_baseurl . '/' . strtolower($resource) . '/' . $this->_ids_version . '/' . $realmID . '/' . $parse[1];
             } else {
                 $url = $this->_baseurl . '/' . strtolower($resource) . '/' . $this->_ids_version . '/' . $realmID;
             }
         }
     }
     if ($optype == QuickBooks_IPP_IDS::OPTYPE_SYNCSTATUS) {
         $url = $this->_baseurl . '/status/v2/' . $realmID;
     } else {
         // Case matters on "syncActivity" #fun (everything else is lower cased)
         if (strtolower($resource) == 'syncactivity') {
             $resource = 'syncActivity';
         } else {
             $resource = strtolower($resource);
             // everything else should be lowercase
         }
         $url = $this->_baseurl . '/' . $resource . '/' . $this->_ids_version . '/' . $realmID;
     }
     //print('hitting URL [' . $url . ']');
     //print($xml);
     $response = $this->_request($Context, QuickBooks_IPP::REQUEST_IDS, $url, $optype, $xml, $post);
     //print($response);
     // Check for generic IPP errors and HTTP errors
     if ($this->_hasErrors($response)) {
         return false;
     }
     $data = $this->_stripHTTPHeaders($response);
     if (!$this->_ids_parser) {
         // If they don't want the responses parsed into objects, then just return the raw XML data
         return $data;
     }
     $start = microtime(true);
     //$Parser = new QuickBooks_IPP_Parser();
     $Parser = $this->_parserInstance();
     $xml_errnum = null;
     $xml_errmsg = null;
     $err_code = null;
     $err_desc = null;
     $err_db = null;
     // Try to parse the responses into QuickBooks_IPP_Object_* classes
     $parsed = $Parser->parseIDS($data, $optype, $this->flavor(), QuickBooks_IPP_IDS::VERSION_2, $xml_errnum, $xml_errmsg, $err_code, $err_desc, $err_db);
     $this->_setLastDebug(__CLASS__, array('ids_parser_duration' => microtime(true) - $start));
     if ($xml_errnum != QuickBooks_XML::ERROR_OK) {
         // Error parsing the returned XML?
         $this->_setError(QuickBooks_IPP::ERROR_XML, 'XML parser said: ' . $xml_errnum . ': ' . $xml_errmsg);
         return false;
     } else {
         if ($err_code != QuickBooks_IPP::ERROR_OK) {
             // Some other IPP error
             $this->_setError($err_code, $err_desc, 'Database error code: ' . $err_db);
             return false;
         }
     }
     // Return the parsed response
     return $parsed;
 }
示例#2
0
 /**
  * Find a record by ID number 
  * 
  * 
  */
 protected function _findById($Context, $realmID, $resource, $IDType, $xml_or_IDType = '', $query = null)
 {
     $IPP = $Context->IPP();
     $flavor = $IPP->flavor();
     if (!$xml_or_IDType) {
         if ($flavor == QuickBooks_IPP_IDS::FLAVOR_DESKTOP) {
             $parse = QuickBooks_IPP_IDS::parseIDType($IDType);
             $xml_or_IDType = '';
             $xml_or_IDType .= '<?xml version="1.0" encoding="UTF-8"?>' . QUICKBOOKS_CRLF;
             $xml_or_IDType .= '<' . $resource . 'Query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.intuit.com/sb/cdm/' . $IPP->version() . '">' . QUICKBOOKS_CRLF;
             if ($resource == QuickBooks_IPP_IDS::RESOURCE_CUSTOMER) {
                 $xml_or_IDType .= '<CustomFieldEnable>true</CustomFieldEnable>';
             }
             if ($query) {
                 $xml_or_IDType .= $query;
             }
             $xml_or_IDType .= '	<' . QuickBooks_IPP_IDS::resourceToKeyType($resource) . 'Set>' . QUICKBOOKS_CRLF;
             $xml_or_IDType .= '		<Id idDomain="' . $parse['domain'] . '">' . $parse['ID'] . '</Id>' . QUICKBOOKS_CRLF;
             $xml_or_IDType .= '	</' . QuickBooks_IPP_IDS::resourceToKeyType($resource) . 'Set>' . QUICKBOOKS_CRLF;
             $xml_or_IDType .= '</' . $resource . 'Query>';
         } else {
             if ($flavor == QuickBooks_IPP_IDS::FLAVOR_ONLINE) {
                 $xml_or_IDType = $IDType;
             }
         }
     }
     $return = $IPP->IDS($Context, $realmID, $resource, QuickBooks_IPP_IDS::OPTYPE_FINDBYID, $xml_or_IDType);
     $this->_setLastRequestResponse($Context->lastRequest(), $Context->lastResponse());
     $this->_setLastDebug($Context->lastDebug());
     if (count($return)) {
         return $return[0];
     }
     return null;
 }