/** * Makes request to API server. * * @param array $request Data to send. * @param array $response [optional]<br />Please provide if you need actual response. * * @return bool Is request successful. */ public function request($request, &$response = null) { if (!($this->_apiUrl && $this->_token)) { return false; } try { $this->_processOutgoingData($request); TriggMine_Helper::encodeArray($request, $this->_integrator->getCharset()); if ($this->_integrator->supportsJavaScript() && !$this->_integrator->isAjaxRequest() && !$this->_integrator->isAsyncRequest() && in_array($request['_action'], array('getVisitor'))) { // Can't handle any other actions. // In case of redirect other method calls can be lost in case of redirect, // which oft //en happens in CMS after the cart purchase, for example. $this->_registerAsyncRequest($request); } elseif (in_array($request['_action'], array('onPingCart'))) { $this->_integrator->pingCart(); } elseif (in_array($request['_action'], array('onUpdateBuyerEmail'))) { $this->_integrator->updateBuyerEmail($request['Data']); } else { $url = strstr($this->_apiUrl, 'http://') ? $this->_apiUrl : 'http://' . $this->_apiUrl; $url .= substr($url, -1) === '/' ? '' : '/'; $url .= self::KEY_MAIN_API_SUFFIX; $result = false; if (TriggMine_Helper::isCurlEnabled()) { $result = $this->_curlRequest($url, $request); } else { if (TriggMine_Helper::isUrlFopenEnabled()) { $result = $this->_fopenRequest($url, $request); } } $response = json_decode($result, true); if ($this->_integrator->getLogInFile()) { $this->_integrator->localResponseLog($request, $response); } $this->_processIncomingData($request, $response); TriggMine_Helper::encodeArray($response, $this->_integrator->getCharset(), true); } } catch (Exception $e) { if ($request['_action'] != 'Log') { // It's not 'Log' method failed, so no recursion will occure $this->reportError($e, $response ? $response['LogId'] : null); } } return !TriggMine_Error::isError($response['ErrorCode']); }