/** * * * * @param string $message * @param integer $level * @return boolean */ protected function _log($message, $level = QUICKBOOKS_LOG_NORMAL) { if ($this->_masking) { // Mask credit card numbers, session tickets, and connection tickets $message = QuickBooks_Utilities::mask($message); } if ($this->_debug) { print $message . QUICKBOOKS_CRLF; } if ($this->_driver) { $this->_driver->log($message, $this->_ticket_session, $level); } return true; }
/** * * * @param string $method * @param string $action * @param string $type * @param string $qbxml * @param array $callbacks * @param mixed $uniqueid * @param integer $priority * @param string $err * @param integer $recur * @return boolean */ public function handleQBXML($method, $action, $type, $qbxml, $callbacks, $uniqueid, $priority, &$err, $recur = null) { if (strlen($uniqueid) == 0) { $uniqueid = md5(time() . $this->_user . mt_rand()); } // The qbXML requests that get passed to this function are without the // typical qbXML wrapper info, so we need to modify them to make them // into complete, valid requests. $qbxml = $this->_makeValidQBXML($qbxml, $this->_config['qbxml_version'], $this->_config['qbxml_onerror']); $extra = array('method' => $method, 'action' => $action, 'type' => $type, 'api' => true, 'uniqueid' => $uniqueid, 'callbacks' => $callbacks, 'options' => $this->_config, 'recur' => $recur); //print_r($qbxml); if ($recur) { return $this->_driver->recurEnqueue($this->_user, $recur, $action, $uniqueid, true, $priority, $extra, $qbxml); } else { return $this->_driver->queueEnqueue($this->_user, $action, $uniqueid, true, $priority, $extra, $qbxml); } }
/** * Call a hook function / object method / static method * * @param QuickBooks_Driver $Driver QuickBooks_Driver instance for logging * @param array $hooks An array of arrays of hooks * @param string $hook The hook to call * @param string $requestID The requestID of the request which caused this hook to be called * @param string $user The username of the QuickBooks user * @param string $ticket The ticket for the session * @param string $err Any errors that occur will be passed back here * @param array $hook_data An array of additional data to be passed to the hook * @param array $callback_config An array of additional callback data * @return boolean */ public static function callHook($Driver, &$hooks, $hook, $requestID, $user, $ticket, &$err, $hook_data, $callback_config = array()) { // There's a bug somewhere that passes a null value to this function... ? if (!is_array($hooks)) { $hooks = array(); } // First, clean up the hooks array foreach ($hooks as $key => $value) { if (!is_array($value)) { $hooks[$key] = array($value); } } // Clean up the hook data foreach (array('requestID' => $requestID, 'user' => $user, 'ticket' => $ticket) as $key => $value) { if (empty($hook_data[$key])) { $hook_data[$key] = $value; } } // Check if the hook is set, if so, call it! if (isset($hooks[$hook])) { // Drop a message in the log if ($Driver) { $Driver->log('Calling hooks for: ' . $hook, $ticket, QUICKBOOKS_LOG_VERBOSE); } // Loop through the hooks foreach ($hooks[$hook] as $callback) { // Determine the type of hook $type = QuickBooks_Callbacks::_type($callback, $Driver, $ticket); if ($Driver) { // Log the callback for debugging // $Driver->log('Calling callback [' . $type . ']: ' . print_r($callback, true), $ticket, QUICKBOOKS_LOG_DEVELOP); } $vars = array($requestID, $user, $hook, &$err, $hook_data, $callback_config); if ($type == QUICKBOOKS_CALLBACKS_TYPE_OBJECT_METHOD) { $object = $callback[0]; $method = $callback[1]; if ($Driver) { $Driver->log('Calling hook instance method: ' . get_class($callback[0]) . '->' . $callback[1], $ticket, QUICKBOOKS_LOG_VERBOSE); } $ret = QuickBooks_Callbacks::_callObjectMethod(array($object, $method), $vars, $err); //$ret = call_user_func_array( array( $object, $method ), array( $requestID, $user, $hook, &$err, $hook_data, $callback_config) ); } else { if ($type == QUICKBOOKS_CALLBACKS_TYPE_FUNCTION) { if ($Driver) { $Driver->log('Calling hook function: ' . $callback, $ticket, QUICKBOOKS_LOG_VERBOSE); } $ret = QuickBooks_Callbacks::_callFunction($callback, $vars, $err); //$ret = $callback($requestID, $user, $hook, $err, $hook_data, $callback_config); // $requestID, $user, $action, $ident, $extra, $err, $xml, $qb_identifier } else { if ($type == QUICKBOOKS_CALLBACKS_TYPE_STATIC_METHOD) { if ($Driver) { $Driver->log('Calling hook static method: ' . $callback, $ticket, QUICKBOOKS_LOG_VERBOSE); } //$tmp = explode('::', $callback); //$class = trim(current($tmp)); //$method = trim(end($tmp)); $ret = QuickBooks_Callbacks::_callStaticMethod($callback, $vars, $err); //$ret = call_user_func_array( array( $class, $method ), array( $requestID, $user, $hook, &$err, $hook_data, $callback_config) ); } else { if ($type == QUICKBOOKS_CALLBACKS_TYPE_HOOK_INSTANCE) { // Just call the ->hook() method if ($Driver) { $Driver->log('Calling hook instance: ' . get_class($callback), $ticket, QUICKBOOKS_LOG_VERBOSE); } $ret = QuickBooks_Callbacks::_callObjectMethod(array($callback, 'hook'), $vars, $err); } else { return false; } } } } // If the hook returns FALSE, then *do not* run all of the other hooks, just return FALSE here if ($ret == false) { return false; } } } return true; }
/** * * * The stdClass object passed as a parameter will have the following members: * - ticket * * @param stdClass $obj * @return QuickBooks_Result_InteractiveDone */ public function interactiveDone($obj) { $this->_driver->log('interactiveDone()', $obj->ticket, QUICKBOOKS_LOG_VERBOSE); if ($this->_driver->authCheck($obj->ticket)) { $user = $this->_driver->authResolve($obj->ticket); $hookdata = array('username' => $user, 'ticket' => $obj->ticket); $hookerr = ''; $this->_callHook($obj->ticket, QUICKBOOKS_HANDLERS_HOOK_INTERACTIVEDONE, null, null, null, null, $hookerr, null, array(), $hookdata); return new QuickBooks_Result_InteractiveDone('Done'); } return new QuickBooks_Result_InteractiveDone(''); }
/** * Map a type and application primary key to a QuickBooks EditSequence string * * @param string $type The type of object * @param mixed $ID The application primary key * @return string The QuickBooks EditSequence string */ protected function _mapToEditSequence($type, $ID) { $editsequence = ''; $extra = null; if (strlen($this->_config['map_to_editsequence_handler'])) { $func = $this->_config['map_to_editsequence_handler']; if (false === strpos($func, '::')) { return $func($type, $ID); } else { $tmp = explode('::', $func); return call_user_func(array($tmp[0], $tmp[1]), $type, $ID); } } else { if ($ListID_or_TxnID = $this->_driver->identToQuickBooks($this->_user, $type, $ID, $editsequence, $extra)) { return $editsequence; } } return null; }
/** * QuickBooks Web Connector ->closeConnection() SOAP method * * The stdClass object passed in as a parameter has these members: * - ->ticket The ticket string * * The sole member of the returned object should be a string describing the reason for closing the connection * * @todo The "Complete!" message should probably be based on a configuration variable, user configurable * * The following user-defined hooks are invoked: * - QUICKBOOKS_HANDLERS_HOOK_CLOSECONNECTION * * @return QuickBooks_Result_CloseConnection */ public function closeConnection($obj) { //$this->_driver->log('closeConnection()', $obj->ticket, QUICKBOOKS_LOG_VERBOSE); $this->_log('closeConnection()', $obj->ticket, QUICKBOOKS_LOG_VERBOSE); if ($this->_driver->authCheck($obj->ticket)) { $user = $this->_driver->authResolve($obj->ticket); $hookdata = array('username' => $user, 'ticket' => $obj->ticket); $hookerr = ''; $this->_callHook($obj->ticket, QUICKBOOKS_HANDLERS_HOOK_CLOSECONNECTION, null, null, null, null, $hookerr, null, array(), $hookdata); // return new QuickBooks_WebConnector_Result_CloseConnection('Complete!'); } // Bad ticket return new QuickBooks_WebConnector_Result_CloseConnection('Bad ticket.'); }
/** * Accept input from the data source and queue things up * * @param QuickBooks_Driver $Driver * @return boolean */ public function input($Driver) { if ($this->_mode != QUICKBOOKS_TRANSPORT_MODE_INPUT) { return false; } // Clean up magic quotes junk $this->_compat(); $defaults = array('method' => QUICKBOOKS_TRANSPORT_METHOD_ENQUEUE, 'action' => $this->_action, 'ident' => null, 'replace' => true, 'priority' => 0, 'extra' => null, 'qbxml' => null, 'id' => null); $data = array_merge($defaults, $_POST); if (empty($data['id'])) { $data['id'] = QuickBooks_Utilities::generateGUID(); } $data['extra'] = array('__extra' => $data['extra'], '__id' => $data['id'], '__method' => $data['method'], '__replace' => $data['replace'], '__priority' => $data['priority']); // They must pass *at least* a valid method *and* either an action, or a qbXML request $errno = QUICKBOOKS_TRANSPORT_ERROR_OK; $errmsg = null; if (!$data['action'] and !$data['qbxml']) { $errno = QUICKBOOKS_TRANSPORT_ERROR_MISSING; $errmsg = 'You must HTTP POST at least either an "action" parameter or a "qbxml" parameter.'; } else { if (!is_numeric($data['priority'])) { $errno = QUICKBOOKS_TRANSPORT_ERROR_VALIDATE; $errmsg = 'The value "' . $data['priority'] . '" is invalid for the priority field.'; } } if (!$errno) { $ok = false; switch ($data['method']) { case QUICKBOOKS_TRANSPORT_METHOD_ENQUEUE: $ok = $Driver->queueEnqueue($this->_user, $data['action'], $data['ident'], (bool) $data['replace'], (int) $data['priority'], $data['extra'], $data['qbxml']); break; case QUICKBOOKS_TRANSPORT_METHOD_EXISTS: case QUICKBOOKS_TRANSPORT_METHOD_RECUR: default: $errmsg = 'Unimplemented method: ' . $data['method']; break; } } $this->_ack($data, $ok, $data['id'], $errno, $errmsg); $this->_done = true; return $ok == true; }