private function get_api() { if (self::$api) { return self::$api; } $settings = $this->get_plugin_settings(); $api = null; $require_vars = array('domain', 'clientId', 'clientSecret', 'memberId', 'authId', 'refreshId', 'endOfLife'); foreach ($require_vars as $require_var) { if (empty($settings[$require_var])) { $this->oauth_login(); return false; } } if ($settings['endOfLife'] < time()) { $settings = $this->refresh_token(); } if (!empty($settings['domain']) && !empty($settings['clientId']) && !empty($settings['clientSecret'])) { // init lib $obB24App = new \Bitrix24\Bitrix24(); $obB24App->setApplicationScope(array('crm')); $obB24App->setApplicationId($settings['clientId']); $obB24App->setApplicationSecret($settings['clientSecret']); // set user-specific settings $obB24App->setDomain($settings['domain']); $obB24App->setMemberId($settings['memberId']); $obB24App->setAccessToken($settings['authId']); $obB24App->setRefreshToken($settings['refreshId']); $this->log_debug('Retrieving API Info'); try { $api = new \Bitrix24\CRM\Lead($obB24App); } catch (Exception $e) { $this->log_error('Failed to set up the API'); $this->log_error($e->getCode() . ' - ' . $e->getMessage()); $this->oauth_login(); return null; } } else { $this->log_debug('API credentials not set'); return null; } if (!is_object($api)) { $this->log_error('Failed to set up the API'); return null; } $this->log_debug('Successful API response received'); self::$api = $api; return self::$api; }
function gf_bitrix24() { return GFBitrix24::get_instance(); }